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, ...@@ -625,11 +625,23 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context,
ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_HIGH, ANGLE_PERF_WARNING(contextVk->getDebug(), GL_DEBUG_SEVERITY_HIGH,
"Texture copied on CPU due to format restrictions"); "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. // Do a CPU readback that does the conversion, and then stage the change to the pixel buffer.
ANGLE_TRY(mImage->stageSubresourceUpdateFromFramebuffer( ANGLE_TRY(mImage->stageSubresourceUpdateFromFramebuffer(
context, offsetImageIndex, clippedSourceArea, modifiedDestOffset, context, offsetImageIndex, clippedSourceArea, modifiedDestOffset,
gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat, gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat,
framebufferVk)); framebufferVk, contextStagingBuffer));
if (contextStagingBuffer)
{
ANGLE_TRY(flushImageStagedUpdates(contextVk));
}
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -4028,12 +4028,8 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk ...@@ -4028,12 +4028,8 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
VkBuffer bufferHandle; VkBuffer bufferHandle;
VkDeviceSize stagingOffset = 0; VkDeviceSize stagingOffset = 0;
DynamicBuffer *stagingBuffer = &mStagingBuffer; DynamicBuffer *stagingBuffer = stagingBufferOverride ? stagingBufferOverride : &mStagingBuffer;
if (stagingBufferOverride) size_t alignment = mStagingBuffer.getAlignment();
{
stagingBuffer = stagingBufferOverride;
}
size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment, destData, ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment, destData,
&bufferHandle, &stagingOffset, nullptr)); &bufferHandle, &stagingOffset, nullptr));
...@@ -4112,7 +4108,8 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer( ...@@ -4112,7 +4108,8 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
const gl::Offset &dstOffset, const gl::Offset &dstOffset,
const gl::Extents &dstExtent, const gl::Extents &dstExtent,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
FramebufferVk *framebufferVk) FramebufferVk *framebufferVk,
DynamicBuffer *stagingBufferOverride)
{ {
ContextVk *contextVk = GetImpl(context); ContextVk *contextVk = GetImpl(context);
...@@ -4148,9 +4145,13 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer( ...@@ -4148,9 +4145,13 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
VkDeviceSize stagingOffset = 0; VkDeviceSize stagingOffset = 0;
// The destination is only one layer deep. // The destination is only one layer deep.
size_t allocationSize = outputDepthPitch; size_t allocationSize = outputDepthPitch;
ANGLE_TRY(mStagingBuffer.allocate(contextVk, allocationSize, &stagingPointer, &bufferHandle, DynamicBuffer *stagingBuffer = stagingBufferOverride ? stagingBufferOverride : &mStagingBuffer;
&stagingOffset, nullptr)); size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment,
&stagingPointer, &bufferHandle, &stagingOffset,
nullptr));
BufferHelper *currentBuffer = stagingBuffer->getCurrentBuffer();
const angle::Format &copyFormat = const angle::Format &copyFormat =
GetFormatFromFormatType(formatInfo.internalFormat, formatInfo.type); GetFormatFromFormatType(formatInfo.internalFormat, formatInfo.type);
...@@ -4200,7 +4201,7 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer( ...@@ -4200,7 +4201,7 @@ angle::Result ImageHelper::stageSubresourceUpdateFromFramebuffer(
gl_vk::GetExtent(dstExtent, &copyToImage.imageExtent); gl_vk::GetExtent(dstExtent, &copyToImage.imageExtent);
// 3- enqueue the destination image subresource update // 3- enqueue the destination image subresource update
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), copyToImage)); appendSubresourceUpdate(SubresourceUpdate(currentBuffer, copyToImage));
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -1384,7 +1384,8 @@ class ImageHelper final : public Resource, public angle::Subject ...@@ -1384,7 +1384,8 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &dstOffset, const gl::Offset &dstOffset,
const gl::Extents &dstExtent, const gl::Extents &dstExtent,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
FramebufferVk *framebufferVk); FramebufferVk *framebufferVk,
DynamicBuffer *stagingBufferOverride);
void stageSubresourceUpdateFromImage(ImageHelper *image, void stageSubresourceUpdateFromImage(ImageHelper *image,
const gl::ImageIndex &index, 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