Commit 1d331c91 by Charlie Lao Committed by Commit Bot

Vulkan: Use context staging buffer for copyImageDataToBuffer

ImageHelper::copyImageDataToBuffer() is called from glCopyTexture*. It allocate staging buffer and write the copy command into command buffer right away. This uses context staging buffer instead of ImageHelper's staging buffer. This has the benefit of able to share staging buffer with other objects (including buffers etc). Bug: b/164511310 Change-Id: I3f680b1cd95df172a442aac573a8cc8d48972b1b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2364717 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent a2c2a910
...@@ -946,7 +946,8 @@ angle::Result ContextVk::initialize() ...@@ -946,7 +946,8 @@ angle::Result ContextVk::initialize()
constexpr VkMemoryPropertyFlags kMemoryType = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; constexpr VkMemoryPropertyFlags kMemoryType = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
ANGLE_TRY(mEmptyBuffer.init(this, emptyBufferInfo, kMemoryType)); ANGLE_TRY(mEmptyBuffer.init(this, emptyBufferInfo, kMemoryType));
constexpr VkImageUsageFlags kStagingBufferUsageFlags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; constexpr VkImageUsageFlags kStagingBufferUsageFlags =
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
size_t stagingBufferAlignment = size_t stagingBufferAlignment =
static_cast<size_t>(mRenderer->getPhysicalDeviceProperties().limits.minMemoryMapAlignment); static_cast<size_t>(mRenderer->getPhysicalDeviceProperties().limits.minMemoryMapAlignment);
constexpr size_t kStagingBufferSize = 1024u * 1024u; // 1M constexpr size_t kStagingBufferSize = 1024u * 1024u; // 1M
......
...@@ -4400,20 +4400,6 @@ void ImageHelper::stageSelfForBaseLevel() ...@@ -4400,20 +4400,6 @@ void ImageHelper::stageSelfForBaseLevel()
getLevelExtents(0), mImageType); getLevelExtents(0), mImageType);
} }
angle::Result ImageHelper::allocateStagingMemory(ContextVk *contextVk,
size_t sizeInBytes,
uint8_t **ptrOut,
BufferHelper **bufferOut,
StagingBufferOffsetArray *offsetOut,
bool *newBufferAllocatedOut)
{
VkBuffer handle;
ANGLE_TRY(mStagingBuffer.allocate(contextVk, sizeInBytes, ptrOut, &handle, &(*offsetOut)[0],
newBufferAllocatedOut));
*bufferOut = mStagingBuffer.getCurrentBuffer();
return angle::Result::Continue;
}
angle::Result ImageHelper::flushSingleSubresourceStagedUpdates(ContextVk *contextVk, angle::Result ImageHelper::flushSingleSubresourceStagedUpdates(ContextVk *contextVk,
uint32_t levelGL, uint32_t levelGL,
uint32_t layer, uint32_t layer,
...@@ -4806,9 +4792,11 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk, ...@@ -4806,9 +4792,11 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
const VkImageAspectFlags aspectFlags = getAspectFlags(); const VkImageAspectFlags aspectFlags = getAspectFlags();
// Allocate staging buffer data // Allocate staging buffer data from context
ANGLE_TRY(allocateStagingMemory(contextVk, *bufferSize, outDataPtr, bufferOut, bufferOffsetsOut, VkBuffer bufferHandle;
nullptr)); ANGLE_TRY(contextVk->getStagingBuffer()->allocate(
contextVk, *bufferSize, outDataPtr, &bufferHandle, &(*bufferOffsetsOut)[0], nullptr));
*bufferOut = contextVk->getStagingBuffer()->getCurrentBuffer();
uint32_t sourceLevelVk = static_cast<uint32_t>(sourceLevelGL) - mBaseLevel; uint32_t sourceLevelVk = static_cast<uint32_t>(sourceLevelGL) - mBaseLevel;
...@@ -4865,8 +4853,7 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk, ...@@ -4865,8 +4853,7 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
CommandBuffer &commandBuffer = contextVk->getOutsideRenderPassCommandBuffer(); CommandBuffer &commandBuffer = contextVk->getOutsideRenderPassCommandBuffer();
commandBuffer.copyImageToBuffer(mImage, getCurrentLayout(), commandBuffer.copyImageToBuffer(mImage, getCurrentLayout(), bufferHandle, 1, regions);
(*bufferOut)->getBuffer().getHandle(), 1, regions);
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -1397,15 +1397,6 @@ class ImageHelper final : public Resource, public angle::Subject ...@@ -1397,15 +1397,6 @@ class ImageHelper final : public Resource, public angle::Subject
// is used for mipmap generation. // is used for mipmap generation.
void stageSelfForBaseLevel(); void stageSelfForBaseLevel();
// This will use the underlying dynamic buffer to allocate some memory to be used as a src or
// dst.
angle::Result allocateStagingMemory(ContextVk *contextVk,
size_t sizeInBytes,
uint8_t **ptrOut,
BufferHelper **bufferOut,
StagingBufferOffsetArray *offsetOut,
bool *newBufferAllocatedOut);
// Flush staged updates for a single subresource. Can optionally take a parameter to defer // Flush staged updates for a single subresource. Can optionally take a parameter to defer
// clears to a subsequent RenderPass load op. // clears to a subsequent RenderPass load op.
angle::Result flushSingleSubresourceStagedUpdates(ContextVk *contextVk, angle::Result flushSingleSubresourceStagedUpdates(ContextVk *contextVk,
......
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