Commit fbafb46c by Charlie Lao Committed by Commit Bot

Vulkan: Use context staging buffer for CopyTexSubImage

This will avoid allocate staging buffer if there isn't one already. Bug: b/164511310 Change-Id: Ieb5ef12fa58c52c0a62276cab6de135fdd62780c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2377121 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com>
parent 1acaf4ec
......@@ -625,11 +625,23 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context,
ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_HIGH,
"Texture copied on CPU due to format restrictions");
// Use context's staging buffer if possible
vk::DynamicBuffer *contextStagingBuffer = nullptr;
if (mImage->valid() && !shouldUpdateBeStaged(index.getLevelIndex()))
{
contextStagingBuffer = contextVk->getStagingBuffer();
}
// Do a CPU readback that does the conversion, and then stage the change to the pixel buffer.
ANGLE_TRY(mImage->stageSubresourceUpdateFromFramebuffer(
context, offsetImageIndex, clippedSourceArea, modifiedDestOffset,
gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat,
framebufferVk));
framebufferVk, contextStagingBuffer));
if (contextStagingBuffer)
{
ANGLE_TRY(flushImageStagedUpdates(contextVk));
}
return angle::Result::Continue;
}
......
......@@ -4028,12 +4028,8 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
VkBuffer bufferHandle;
VkDeviceSize stagingOffset = 0;
DynamicBuffer *stagingBuffer = &mStagingBuffer;
if (stagingBufferOverride)
{
stagingBuffer = stagingBufferOverride;
}
size_t alignment = mStagingBuffer.getAlignment();
DynamicBuffer *stagingBuffer = stagingBufferOverride ? stagingBufferOverride : &mStagingBuffer;
size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment, destData,
&bufferHandle, &stagingOffset, nullptr));
......@@ -4112,7 +4108,8 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
const gl::Offset &dstOffset,
const gl::Extents &dstExtent,
const gl::InternalFormat &formatInfo,
FramebufferVk *framebufferVk)
FramebufferVk *framebufferVk,
DynamicBuffer *stagingBufferOverride)
{
ContextVk *contextVk = GetImpl(context);
......@@ -4148,9 +4145,13 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
VkDeviceSize stagingOffset = 0;
// The destination is only one layer deep.
size_t allocationSize = outputDepthPitch;
ANGLE_TRY(mStagingBuffer.allocate(contextVk, allocationSize, &stagingPointer, &bufferHandle,
&stagingOffset, nullptr));
size_t allocationSize = outputDepthPitch;
DynamicBuffer *stagingBuffer = stagingBufferOverride ? stagingBufferOverride : &mStagingBuffer;
size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment,
&stagingPointer, &bufferHandle, &stagingOffset,
nullptr));
BufferHelper *currentBuffer = stagingBuffer->getCurrentBuffer();
const angle::Format &copyFormat =
GetFormatFromFormatType(formatInfo.internalFormat, formatInfo.type);
......@@ -4200,7 +4201,7 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
gl_vk::GetExtent(dstExtent, &copyToImage.imageExtent);
// 3- enqueue the destination image subresource update
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), copyToImage));
appendSubresourceUpdate(SubresourceUpdate(currentBuffer, copyToImage));
return angle::Result::Continue;
}
......
......@@ -1384,7 +1384,8 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &dstOffset,
const gl::Extents &dstExtent,
const gl::InternalFormat &formatInfo,
FramebufferVk *framebufferVk);
FramebufferVk *framebufferVk,
DynamicBuffer *stagingBufferOverride);
void stageSubresourceUpdateFromImage(ImageHelper *image,
const gl::ImageIndex &index,
......
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