Commit 57fbfd80 by Jamie Madill Committed by Commit Bot

Vulkan: Pass RendererVk to Allocate helpers.

Passing the Renderer pointer instead of the Context pointer makes these methods a bit easier to work with from the "EGL" sections of the code. This is a refactoring-only change to aid the Depth/Stencil implementation. Bug: angleproject:2357 Change-Id: Icbcc72a1daff4edd947a21672744498781cfc064 Reviewed-on: https://chromium-review.googlesource.com/919523Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 12eb3d74
...@@ -54,6 +54,10 @@ gl::Error BufferVk::setData(const gl::Context *context, ...@@ -54,6 +54,10 @@ gl::Error BufferVk::setData(const gl::Context *context,
// Release and re-create the memory and buffer. // Release and re-create the memory and buffer.
release(contextVk->getRenderer()); release(contextVk->getRenderer());
const VkImageUsageFlags usageFlags =
(VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
// TODO(jmadill): Proper usage bit implementation. Likely will involve multiple backing // TODO(jmadill): Proper usage bit implementation. Likely will involve multiple backing
// buffers like in D3D11. // buffers like in D3D11.
VkBufferCreateInfo createInfo; VkBufferCreateInfo createInfo;
...@@ -61,8 +65,7 @@ gl::Error BufferVk::setData(const gl::Context *context, ...@@ -61,8 +65,7 @@ gl::Error BufferVk::setData(const gl::Context *context,
createInfo.pNext = nullptr; createInfo.pNext = nullptr;
createInfo.flags = 0; createInfo.flags = 0;
createInfo.size = size; createInfo.size = size;
createInfo.usage = (VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | createInfo.usage = usageFlags;
VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; createInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
createInfo.queueFamilyIndexCount = 0; createInfo.queueFamilyIndexCount = 0;
createInfo.pQueueFamilyIndices = nullptr; createInfo.pQueueFamilyIndices = nullptr;
...@@ -70,10 +73,10 @@ gl::Error BufferVk::setData(const gl::Context *context, ...@@ -70,10 +73,10 @@ gl::Error BufferVk::setData(const gl::Context *context,
ANGLE_TRY(mBuffer.init(device, createInfo)); ANGLE_TRY(mBuffer.init(device, createInfo));
// Assume host vislble/coherent memory available. // Assume host vislble/coherent memory available.
VkMemoryPropertyFlags flags = const VkMemoryPropertyFlags memoryPropertyFlags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(vk::AllocateBufferMemory(contextVk, flags, &mBuffer, &mBufferMemory, ANGLE_TRY(vk::AllocateBufferMemory(contextVk->getRenderer(), memoryPropertyFlags, &mBuffer,
&mCurrentRequiredSize)); &mBufferMemory, &mCurrentRequiredSize));
} }
if (data) if (data)
......
...@@ -65,7 +65,10 @@ gl::Error InitDefaultUniformBlock(const gl::Context *context, ...@@ -65,7 +65,10 @@ gl::Error InitDefaultUniformBlock(const gl::Context *context,
// Assume host vislble/coherent memory available. // Assume host vislble/coherent memory available.
VkMemoryPropertyFlags flags = VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(AllocateBufferMemory(vk::GetImpl(context), flags, &storageOut->buffer,
ContextVk *contextVk = vk::GetImpl(context);
ANGLE_TRY(AllocateBufferMemory(contextVk->getRenderer(), flags, &storageOut->buffer,
&storageOut->memory, requiredSizeOut)); &storageOut->memory, requiredSizeOut));
return gl::NoError(); return gl::NoError();
...@@ -264,6 +267,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext, ...@@ -264,6 +267,7 @@ gl::LinkResult ProgramVk::link(const gl::Context *glContext,
gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
{ {
ContextVk *contextVk = vk::GetImpl(glContext); ContextVk *contextVk = vk::GetImpl(glContext);
RendererVk *renderer = contextVk->getRenderer();
VkDevice device = contextVk->getDevice(); VkDevice device = contextVk->getDevice();
// Process vertex and fragment uniforms into std140 packing. // Process vertex and fragment uniforms into std140 packing.
...@@ -364,7 +368,7 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) ...@@ -364,7 +368,7 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
VkMemoryPropertyFlags flags = VkMemoryPropertyFlags flags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
size_t requiredSize = 0; size_t requiredSize = 0;
ANGLE_TRY(AllocateBufferMemory(contextVk, flags, &mEmptyUniformBlockStorage.buffer, ANGLE_TRY(AllocateBufferMemory(renderer, flags, &mEmptyUniformBlockStorage.buffer,
&mEmptyUniformBlockStorage.memory, &requiredSize)); &mEmptyUniformBlockStorage.memory, &requiredSize));
} }
......
...@@ -40,7 +40,8 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context, ...@@ -40,7 +40,8 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
size_t height) size_t height)
{ {
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
const vk::Format &vkFormat = contextVk->getRenderer()->getFormat(internalformat); RendererVk *renderer = contextVk->getRenderer();
const vk::Format &vkFormat = renderer->getFormat(internalformat);
VkImageUsageFlags usage = VkImageUsageFlags usage =
(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
...@@ -68,7 +69,7 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context, ...@@ -68,7 +69,7 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
ANGLE_TRY(mImage.init(contextVk->getDevice(), imageInfo)); ANGLE_TRY(mImage.init(contextVk->getDevice(), imageInfo));
VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
ANGLE_TRY(vk::AllocateImageMemory(contextVk, flags, &mImage, &mDeviceMemory, &mRequiredSize)); ANGLE_TRY(vk::AllocateImageMemory(renderer, flags, &mImage, &mDeviceMemory, &mRequiredSize));
return gl::NoError(); return gl::NoError();
} }
......
...@@ -115,8 +115,7 @@ gl::Error TextureVk::setImage(const gl::Context *context, ...@@ -115,8 +115,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
VkMemoryPropertyFlags flags = (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); VkMemoryPropertyFlags flags = (VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
size_t requiredSize = 0; size_t requiredSize = 0;
ANGLE_TRY( ANGLE_TRY(vk::AllocateImageMemory(renderer, flags, &mImage, &mDeviceMemory, &requiredSize));
vk::AllocateImageMemory(contextVk, flags, &mImage, &mDeviceMemory, &requiredSize));
VkImageViewCreateInfo viewInfo; VkImageViewCreateInfo viewInfo;
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
......
...@@ -168,14 +168,14 @@ vk::Error FindAndAllocateCompatibleMemory(VkDevice device, ...@@ -168,14 +168,14 @@ vk::Error FindAndAllocateCompatibleMemory(VkDevice device,
} }
template <typename T> template <typename T>
vk::Error AllocateBufferOrImageMemory(ContextVk *contextVk, vk::Error AllocateBufferOrImageMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags, VkMemoryPropertyFlags memoryPropertyFlags,
T *bufferOrImage, T *bufferOrImage,
vk::DeviceMemory *deviceMemoryOut, vk::DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut) size_t *requiredSizeOut)
{ {
VkDevice device = contextVk->getDevice(); VkDevice device = renderer->getDevice();
const vk::MemoryProperties &memoryProperties = contextVk->getRenderer()->getMemoryProperties(); const vk::MemoryProperties &memoryProperties = renderer->getMemoryProperties();
// Call driver to determine memory requirements. // Call driver to determine memory requirements.
VkMemoryRequirements memoryRequirements; VkMemoryRequirements memoryRequirements;
...@@ -859,7 +859,8 @@ Error StagingImage::init(ContextVk *contextVk, ...@@ -859,7 +859,8 @@ Error StagingImage::init(ContextVk *contextVk,
StagingUsage usage) StagingUsage usage)
{ {
VkDevice device = contextVk->getDevice(); VkDevice device = contextVk->getDevice();
uint32_t queueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex(); RendererVk *renderer = contextVk->getRenderer();
uint32_t queueFamilyIndex = renderer->getQueueFamilyIndex();
VkImageCreateInfo createInfo; VkImageCreateInfo createInfo;
...@@ -894,7 +895,7 @@ Error StagingImage::init(ContextVk *contextVk, ...@@ -894,7 +895,7 @@ Error StagingImage::init(ContextVk *contextVk,
// 1) not having (enough) coherent memory and 2) coherent memory being slower // 1) not having (enough) coherent memory and 2) coherent memory being slower
VkMemoryPropertyFlags memoryPropertyFlags = VkMemoryPropertyFlags memoryPropertyFlags =
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(AllocateImageMemory(contextVk, memoryPropertyFlags, &mImage, &mDeviceMemory, &mSize)); ANGLE_TRY(AllocateImageMemory(renderer, memoryPropertyFlags, &mImage, &mDeviceMemory, &mSize));
return NoError(); return NoError();
} }
...@@ -1167,7 +1168,8 @@ vk::Error StagingBuffer::init(ContextVk *contextVk, VkDeviceSize size, StagingUs ...@@ -1167,7 +1168,8 @@ vk::Error StagingBuffer::init(ContextVk *contextVk, VkDeviceSize size, StagingUs
(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
ANGLE_TRY(mBuffer.init(contextVk->getDevice(), createInfo)); ANGLE_TRY(mBuffer.init(contextVk->getDevice(), createInfo));
ANGLE_TRY(AllocateBufferMemory(contextVk, flags, &mBuffer, &mDeviceMemory, &mSize)); ANGLE_TRY(
AllocateBufferMemory(contextVk->getRenderer(), flags, &mBuffer, &mDeviceMemory, &mSize));
return vk::NoError(); return vk::NoError();
} }
...@@ -1178,23 +1180,23 @@ void StagingBuffer::dumpResources(Serial serial, std::vector<vk::GarbageObject> ...@@ -1178,23 +1180,23 @@ void StagingBuffer::dumpResources(Serial serial, std::vector<vk::GarbageObject>
mDeviceMemory.dumpResources(serial, garbageQueue); mDeviceMemory.dumpResources(serial, garbageQueue);
} }
Error AllocateBufferMemory(ContextVk *contextVk, Error AllocateBufferMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags, VkMemoryPropertyFlags memoryPropertyFlags,
Buffer *buffer, Buffer *buffer,
DeviceMemory *deviceMemoryOut, DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut) size_t *requiredSizeOut)
{ {
return AllocateBufferOrImageMemory(contextVk, memoryPropertyFlags, buffer, deviceMemoryOut, return AllocateBufferOrImageMemory(renderer, memoryPropertyFlags, buffer, deviceMemoryOut,
requiredSizeOut); requiredSizeOut);
} }
Error AllocateImageMemory(ContextVk *contextVk, Error AllocateImageMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags, VkMemoryPropertyFlags memoryPropertyFlags,
Image *image, Image *image,
DeviceMemory *deviceMemoryOut, DeviceMemory *deviceMemoryOut,
size_t *requiredSizeOut) size_t *requiredSizeOut)
{ {
return AllocateBufferOrImageMemory(contextVk, memoryPropertyFlags, image, deviceMemoryOut, return AllocateBufferOrImageMemory(renderer, memoryPropertyFlags, image, deviceMemoryOut,
requiredSizeOut); requiredSizeOut);
} }
......
...@@ -642,7 +642,7 @@ class ObjectAndSerial final : angle::NonCopyable ...@@ -642,7 +642,7 @@ class ObjectAndSerial final : angle::NonCopyable
Serial mQueueSerial; Serial mQueueSerial;
}; };
Error AllocateBufferMemory(ContextVk *contextVk, Error AllocateBufferMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags, VkMemoryPropertyFlags memoryPropertyFlags,
Buffer *buffer, Buffer *buffer,
DeviceMemory *deviceMemoryOut, DeviceMemory *deviceMemoryOut,
...@@ -654,7 +654,7 @@ struct BufferAndMemory final : private angle::NonCopyable ...@@ -654,7 +654,7 @@ struct BufferAndMemory final : private angle::NonCopyable
vk::DeviceMemory memory; vk::DeviceMemory memory;
}; };
Error AllocateImageMemory(ContextVk *contextVk, Error AllocateImageMemory(RendererVk *renderer,
VkMemoryPropertyFlags memoryPropertyFlags, VkMemoryPropertyFlags memoryPropertyFlags,
Image *image, Image *image,
DeviceMemory *deviceMemoryOut, DeviceMemory *deviceMemoryOut,
......
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