Commit 5ac807b2 by Charlie Lao Committed by Commit Bot

Vulkan: Let stageSubresourceUpdateAndGetData use ctx staging buffer

stageSubresourceUpdateAndGetData call are made and then flush the commands out, so they could just switch to use context's staging buffer instead of use per object's staging buffer. Bug: b/164511310 Change-Id: Iff7944a37073bb3641498e334847f599903858b1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2376895 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 1ab8b75a
......@@ -718,10 +718,17 @@ angle::Result TextureVk::copySubTextureImpl(ContextVk *contextVk,
const gl::ImageIndex stagingIndex = gl::ImageIndex::Make2DArrayRange(
offsetImageIndex.getLevelIndex(), stagingBaseLayer, stagingLayerCount);
// Use context's staging buffer if possible
vk::DynamicBuffer *contextStagingBuffer = nullptr;
if (mImage->valid() && !shouldUpdateBeStaged(index.getLevelIndex()))
{
contextStagingBuffer = contextVk->getStagingBuffer();
}
uint8_t *destData = nullptr;
ANGLE_TRY(mImage->stageSubresourceUpdateAndGetData(contextVk, destinationAllocationSize,
stagingIndex, stagingExtents, stagingOffset,
&destData));
&destData, contextStagingBuffer));
// Source and dest data is tightly packed
GLuint sourceDataRowPitch = sourceBox.width * sourceTextureFormat.pixelBytes;
......@@ -752,6 +759,11 @@ angle::Result TextureVk::copySubTextureImpl(ContextVk *contextVk,
sourceBox.height, sourceBox.depth, unpackFlipY, unpackPremultiplyAlpha,
unpackUnmultiplyAlpha);
if (contextStagingBuffer)
{
ANGLE_TRY(flushImageStagedUpdates(contextVk));
}
return angle::Result::Continue;
}
......@@ -2471,7 +2483,7 @@ angle::Result TextureVk::generateMipmapLevelsWithCPU(ContextVk *contextVk,
ANGLE_TRY(mImage->stageSubresourceUpdateAndGetData(
contextVk, mipAllocationSize,
gl::ImageIndex::MakeFromType(mState.getType(), currentMipLevel, layer), mipLevelExtents,
gl::Offset(), &destData));
gl::Offset(), &destData, contextVk->getStagingBuffer()));
// Generate the mipmap into that new buffer
sourceFormat.mipGenerationFunction(
......
......@@ -4022,12 +4022,20 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
const gl::ImageIndex &imageIndex,
const gl::Extents &glExtents,
const gl::Offset &offset,
uint8_t **destData)
uint8_t **destData,
DynamicBuffer *stagingBufferOverride)
{
VkBuffer bufferHandle;
VkDeviceSize stagingOffset = 0;
ANGLE_TRY(mStagingBuffer.allocate(contextVk, allocationSize, destData, &bufferHandle,
&stagingOffset, nullptr));
DynamicBuffer *stagingBuffer = &mStagingBuffer;
if (stagingBufferOverride)
{
stagingBuffer = stagingBufferOverride;
}
size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(stagingBuffer->allocateWithAlignment(contextVk, allocationSize, alignment, destData,
&bufferHandle, &stagingOffset, nullptr));
VkBufferImageCopy copy = {};
copy.bufferOffset = stagingOffset;
......@@ -4044,7 +4052,7 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
gl_vk::GetOffset(offset, &copy.imageOffset);
gl_vk::GetExtent(glExtents, &copy.imageExtent);
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), copy));
appendSubresourceUpdate(SubresourceUpdate(stagingBuffer->getCurrentBuffer(), copy));
return angle::Result::Continue;
}
......
......@@ -1363,7 +1363,8 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::ImageIndex &imageIndex,
const gl::Extents &glExtents,
const gl::Offset &offset,
uint8_t **destData);
uint8_t **destData,
DynamicBuffer *stagingBufferOverride);
angle::Result stageSubresourceUpdateFromBuffer(ContextVk *contextVk,
size_t allocationSize,
......
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