Commit 57dd97aa by Jamie Madill Committed by Commit Bot

Vulkan: Add helper for allocating image memory.

Also refactors some memory index searching code that was duplicated. This will lead the way to having more code reuse for our Renderbuffers implementation in Vulkan, and for other types of Texture. Bug: angleproject:2347 Change-Id: I49cbd77328c01f945d66f92e6ec4ba7c552abeff Reviewed-on: https://chromium-review.googlesource.com/904684 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent fbb1c792
......@@ -68,7 +68,11 @@ gl::Error BufferVk::setData(const gl::Context *context,
createInfo.pQueueFamilyIndices = nullptr;
ANGLE_TRY(mBuffer.init(device, createInfo));
ANGLE_TRY(vk::AllocateBufferMemory(contextVk, size, &mBuffer, &mBufferMemory,
// Assume host vislble/coherent memory available.
VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(vk::AllocateBufferMemory(contextVk, flags, &mBuffer, &mBufferMemory,
&mCurrentRequiredSize));
}
......
......@@ -263,9 +263,8 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
vk::Image *readImage = renderTarget->image;
vk::StagingImage stagingImage;
ANGLE_TRY(renderer->createStagingImage(TextureDimension::TEX_2D, *renderTarget->format,
renderTarget->extents, vk::StagingUsage::Read,
&stagingImage));
ANGLE_TRY(stagingImage.init(contextVk, TextureDimension::TEX_2D, *renderTarget->format,
renderTarget->extents, vk::StagingUsage::Read));
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(recordWriteCommands(renderer, &commandBuffer));
......
......@@ -62,7 +62,10 @@ gl::Error InitDefaultUniformBlock(const gl::Context *context,
ANGLE_TRY(storageOut->buffer.init(device, uniformBufferInfo));
ANGLE_TRY(AllocateBufferMemory(vk::GetImpl(context), blockSize, &storageOut->buffer,
// Assume host vislble/coherent memory available.
VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(AllocateBufferMemory(vk::GetImpl(context), flags, &storageOut->buffer,
&storageOut->memory, requiredSizeOut));
return gl::NoError();
......@@ -357,8 +360,11 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
ANGLE_TRY(mEmptyUniformBlockStorage.buffer.init(device, uniformBufferInfo));
// Assume host vislble/coherent memory available.
VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
size_t requiredSize = 0;
ANGLE_TRY(AllocateBufferMemory(contextVk, 1, &mEmptyUniformBlockStorage.buffer,
ANGLE_TRY(AllocateBufferMemory(contextVk, flags, &mEmptyUniformBlockStorage.buffer,
&mEmptyUniformBlockStorage.memory, &requiredSize));
}
......
......@@ -720,17 +720,6 @@ vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo, vk::CommandBuf
return vk::NoError();
}
vk::Error RendererVk::createStagingImage(TextureDimension dimension,
const vk::Format &format,
const gl::Extents &extent,
vk::StagingUsage usage,
vk::StagingImage *imageOut)
{
ANGLE_TRY(imageOut->init(mDevice, mCurrentQueueFamilyIndex, mMemoryProperties, dimension,
format.vkTextureFormat, extent, usage));
return vk::NoError();
}
GlslangWrapper *RendererVk::getGlslangWrapper()
{
return mGlslangWrapper;
......
......@@ -63,12 +63,6 @@ class RendererVk : angle::NonCopyable
const gl::Extensions &getNativeExtensions() const;
const gl::Limitations &getNativeLimitations() const;
vk::Error createStagingImage(TextureDimension dimension,
const vk::Format &format,
const gl::Extents &extent,
vk::StagingUsage usage,
vk::StagingImage *imageOut);
GlslangWrapper *getGlslangWrapper();
Serial getCurrentQueueSerial() const;
......
......@@ -113,22 +113,10 @@ gl::Error TextureVk::setImage(const gl::Context *context,
ANGLE_TRY(mImage.init(device, imageInfo));
// Allocate the device memory for the image.
// TODO(jmadill): Use more intelligent device memory allocation.
VkMemoryRequirements memoryRequirements;
mImage.getMemoryRequirements(device, &memoryRequirements);
uint32_t memoryIndex = renderer->getMemoryProperties().findCompatibleMemoryIndex(
memoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VkMemoryAllocateInfo allocateInfo;
allocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
allocateInfo.pNext = nullptr;
allocateInfo.allocationSize = memoryRequirements.size;
allocateInfo.memoryTypeIndex = memoryIndex;
ANGLE_TRY(mDeviceMemory.allocate(device, allocateInfo));
ANGLE_TRY(mImage.bindMemory(device, mDeviceMemory));
VkMemoryPropertyFlags flags = (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
size_t requiredSize = 0;
ANGLE_TRY(
vk::AllocateImageMemory(contextVk, flags, &mImage, &mDeviceMemory, &requiredSize));
VkImageViewCreateInfo viewInfo;
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
......@@ -220,8 +208,8 @@ gl::Error TextureVk::setSubImageImpl(ContextVk *contextVk,
const vk::Format &vkFormat = *mRenderTarget.format;
vk::StagingImage stagingImage;
ANGLE_TRY(renderer->createStagingImage(TextureDimension::TEX_2D, vkFormat, size,
vk::StagingUsage::Write, &stagingImage));
ANGLE_TRY(stagingImage.init(contextVk, TextureDimension::TEX_2D, vkFormat, size,
vk::StagingUsage::Write));
GLuint inputRowPitch = 0;
ANGLE_TRY_RESULT(
......
......@@ -115,18 +115,6 @@ GetImplType<T> *GetImpl(const T *glObject)
return GetImplAs<GetImplType<T>>(glObject);
}
class MemoryProperties final : angle::NonCopyable
{
public:
MemoryProperties();
void init(VkPhysicalDevice physicalDevice);
uint32_t findCompatibleMemoryIndex(uint32_t bitMask, uint32_t propertyFlags) const;
private:
VkPhysicalDeviceMemoryProperties mMemoryProperties;
};
class Error final
{
public:
......@@ -292,6 +280,20 @@ class WrappedObject : angle::NonCopyable
HandleT mHandle;
};
class MemoryProperties final : angle::NonCopyable
{
public:
MemoryProperties();
void init(VkPhysicalDevice physicalDevice);
Error findCompatibleMemoryIndex(const VkMemoryRequirements &memoryRequirements,
VkMemoryPropertyFlags memoryPropertyFlags,
uint32_t *indexOut) const;
private:
VkPhysicalDeviceMemoryProperties mMemoryProperties;
};
class CommandPool final : public WrappedObject<CommandPool, VkCommandPool>
{
public:
......@@ -481,6 +483,7 @@ class Buffer final : public WrappedObject<Buffer, VkBuffer>
Error init(VkDevice device, const VkBufferCreateInfo &createInfo);
Error bindMemory(VkDevice device, const DeviceMemory &deviceMemory);
void getMemoryRequirements(VkDevice device, VkMemoryRequirements *memoryRequirementsOut);
};
class ShaderModule final : public WrappedObject<ShaderModule, VkShaderModule>
......@@ -559,11 +562,9 @@ class StagingImage final : angle::NonCopyable
StagingImage(StagingImage &&other);
void destroy(VkDevice device);
vk::Error init(VkDevice device,
uint32_t queueFamilyIndex,
const MemoryProperties &memoryProperties,
vk::Error init(ContextVk *contextVk,
TextureDimension dimension,
VkFormat format,
const Format &format,
const gl::Extents &extent,
StagingUsage usage);
......@@ -578,7 +579,7 @@ class StagingImage final : angle::NonCopyable
private:
Image mImage;
DeviceMemory mDeviceMemory;
VkDeviceSize mSize;
size_t mSize;
};
// Similar to StagingImage, for Buffers.
......@@ -641,12 +642,8 @@ class ObjectAndSerial final : angle::NonCopyable
Serial mQueueSerial;
};
Optional<uint32_t> FindMemoryType(const VkPhysicalDeviceMemoryProperties &memoryProps,
const VkMemoryRequirements &requirements,
uint32_t propertyFlagMask);
Error AllocateBufferMemory(ContextVk *contextVk,
size_t size,
VkMemoryPropertyFlags memoryPropertyFlags,
Buffer *buffer,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut);
......@@ -657,6 +654,12 @@ struct BufferAndMemory final : private angle::NonCopyable
vk::DeviceMemory memory;
};
Error AllocateImageMemory(ContextVk *contextVk,
VkMemoryPropertyFlags memoryPropertyFlags,
Image *image,
DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut);
} // namespace vk
namespace gl_vk
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment