Commit 552f0f76 by Charlie Lao Committed by Commit Bot

Vulkan: Use context staging buffer for immutable texture update

This uses context's staging buffer for immutable texture TextureVk::setSubImageImpl call and flushes update right away. Bug: b/164511310 Change-Id: I04fee0a9afe0e84617a461fb6cd7137e853adf8b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2357971 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent e689d316
...@@ -369,6 +369,14 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context, ...@@ -369,6 +369,14 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context,
{ {
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
// Use context's staging buffer for immutable textures and flush out updates
// immediately.
vk::DynamicBuffer *stagingBuffer = nullptr;
if (!mOwnsImage || mState.getImmutableFormat())
{
stagingBuffer = contextVk->getStagingBufferStorage();
}
if (unpackBuffer) if (unpackBuffer)
{ {
BufferVk *unpackBufferVk = vk::GetImpl(unpackBuffer); BufferVk *unpackBufferVk = vk::GetImpl(unpackBuffer);
...@@ -416,22 +424,24 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context, ...@@ -416,22 +424,24 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context,
ANGLE_TRY(mImage->stageSubresourceUpdateImpl( ANGLE_TRY(mImage->stageSubresourceUpdateImpl(
contextVk, getNativeImageIndex(index), contextVk, getNativeImageIndex(index),
gl::Extents(area.width, area.height, area.depth), gl::Extents(area.width, area.height, area.depth),
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, source, vkFormat, gl::Offset(area.x, area.y, area.z), formatInfo, unpack, stagingBuffer, type, source,
inputRowPitch, inputDepthPitch, inputSkipBytes)); vkFormat, inputRowPitch, inputDepthPitch, inputSkipBytes));
ANGLE_TRY(unpackBufferVk->unmapImpl(contextVk)); ANGLE_TRY(unpackBufferVk->unmapImpl(contextVk));
} }
} }
else if (pixels) else if (pixels)
{ {
ANGLE_TRY(mImage->stageSubresourceUpdate( ANGLE_TRY(mImage->stageSubresourceUpdate(contextVk, getNativeImageIndex(index),
contextVk, getNativeImageIndex(index), gl::Extents(area.width, area.height, area.depth), gl::Extents(area.width, area.height, area.depth),
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, pixels, vkFormat)); gl::Offset(area.x, area.y, area.z), formatInfo,
unpack, stagingBuffer, type, pixels, vkFormat));
} }
if (!mOwnsImage) // If we used context's staging buffer, flush out the updates
if (stagingBuffer)
{ {
ANGLE_TRY(mImage->flushAllStagedUpdates(contextVk)); ANGLE_TRY(ensureImageInitialized(contextVk, ImageMipLevels::EnabledLevels));
} }
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -3668,6 +3668,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, ...@@ -3668,6 +3668,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
const gl::Offset &offset, const gl::Offset &offset,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type, GLenum type,
const uint8_t *pixels, const uint8_t *pixels,
const Format &vkFormat, const Format &vkFormat,
...@@ -3779,8 +3780,11 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, ...@@ -3779,8 +3780,11 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
uint8_t *stagingPointer = nullptr; uint8_t *stagingPointer = nullptr;
VkDeviceSize stagingOffset = 0; VkDeviceSize stagingOffset = 0;
ANGLE_TRY(mStagingBuffer.allocate(contextVk, allocationSize, &stagingPointer, &bufferHandle, // If caller has provided a staging buffer, use it.
DynamicBuffer *stagingBuffer = stagingBufferOverride ? stagingBufferOverride : &mStagingBuffer;
ANGLE_TRY(stagingBuffer->allocate(contextVk, allocationSize, &stagingPointer, &bufferHandle,
&stagingOffset, nullptr)); &stagingOffset, nullptr));
BufferHelper *currentBuffer = stagingBuffer->getCurrentBuffer();
const uint8_t *source = pixels + static_cast<ptrdiff_t>(inputSkipBytes); const uint8_t *source = pixels + static_cast<ptrdiff_t>(inputSkipBytes);
...@@ -3841,7 +3845,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, ...@@ -3841,7 +3845,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
stencilCopy.imageOffset = copy.imageOffset; stencilCopy.imageOffset = copy.imageOffset;
stencilCopy.imageExtent = copy.imageExtent; stencilCopy.imageExtent = copy.imageExtent;
stencilCopy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; stencilCopy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), stencilCopy)); appendSubresourceUpdate(SubresourceUpdate(currentBuffer, stencilCopy));
aspectFlags &= ~VK_IMAGE_ASPECT_STENCIL_BIT; aspectFlags &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
} }
...@@ -3865,7 +3869,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk, ...@@ -3865,7 +3869,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
if (aspectFlags) if (aspectFlags)
{ {
copy.imageSubresource.aspectMask = aspectFlags; copy.imageSubresource.aspectMask = aspectFlags;
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), copy)); appendSubresourceUpdate(SubresourceUpdate(currentBuffer, copy));
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -3902,6 +3906,7 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -3902,6 +3906,7 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
const gl::Offset &offset, const gl::Offset &offset,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type, GLenum type,
const uint8_t *pixels, const uint8_t *pixels,
const Format &vkFormat) const Format &vkFormat)
...@@ -3913,8 +3918,8 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -3913,8 +3918,8 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
&inputRowPitch, &inputDepthPitch, &inputSkipBytes)); &inputRowPitch, &inputDepthPitch, &inputSkipBytes));
ANGLE_TRY(stageSubresourceUpdateImpl(contextVk, index, glExtents, offset, formatInfo, unpack, ANGLE_TRY(stageSubresourceUpdateImpl(contextVk, index, glExtents, offset, formatInfo, unpack,
type, pixels, vkFormat, inputRowPitch, inputDepthPitch, stagingBufferOverride, type, pixels, vkFormat,
inputSkipBytes)); inputRowPitch, inputDepthPitch, inputSkipBytes));
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -1262,6 +1262,7 @@ class ImageHelper final : public Resource, public angle::Subject ...@@ -1262,6 +1262,7 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &offset, const gl::Offset &offset,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type, GLenum type,
const uint8_t *pixels, const uint8_t *pixels,
const Format &vkFormat, const Format &vkFormat,
...@@ -1275,6 +1276,7 @@ class ImageHelper final : public Resource, public angle::Subject ...@@ -1275,6 +1276,7 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &offset, const gl::Offset &offset,
const gl::InternalFormat &formatInfo, const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type, GLenum type,
const uint8_t *pixels, const uint8_t *pixels,
const Format &vkFormat); const Format &vkFormat);
......
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