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: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Tim Van Patten <timvp@google.com>
This commit is contained in:
Charlie Lao 2020-08-14 16:37:03 -07:00 коммит произвёл Commit Bot
Родитель e689d3164f
Коммит 552f0f7623
3 изменённых файлов: 29 добавлений и 12 удалений

Просмотреть файл

@ -369,6 +369,14 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *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)
{
BufferVk *unpackBufferVk = vk::GetImpl(unpackBuffer);
@ -416,22 +424,24 @@ angle::Result TextureVk::setSubImageImpl(const gl::Context *context,
ANGLE_TRY(mImage->stageSubresourceUpdateImpl(
contextVk, getNativeImageIndex(index),
gl::Extents(area.width, area.height, area.depth),
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, source, vkFormat,
inputRowPitch, inputDepthPitch, inputSkipBytes));
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, stagingBuffer, type, source,
vkFormat, inputRowPitch, inputDepthPitch, inputSkipBytes));
ANGLE_TRY(unpackBufferVk->unmapImpl(contextVk));
}
}
else if (pixels)
{
ANGLE_TRY(mImage->stageSubresourceUpdate(
contextVk, getNativeImageIndex(index), gl::Extents(area.width, area.height, area.depth),
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, pixels, vkFormat));
ANGLE_TRY(mImage->stageSubresourceUpdate(contextVk, getNativeImageIndex(index),
gl::Extents(area.width, area.height, area.depth),
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;

Просмотреть файл

@ -3668,6 +3668,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
const gl::Offset &offset,
const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type,
const uint8_t *pixels,
const Format &vkFormat,
@ -3779,8 +3780,11 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
uint8_t *stagingPointer = nullptr;
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));
BufferHelper *currentBuffer = stagingBuffer->getCurrentBuffer();
const uint8_t *source = pixels + static_cast<ptrdiff_t>(inputSkipBytes);
@ -3841,7 +3845,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
stencilCopy.imageOffset = copy.imageOffset;
stencilCopy.imageExtent = copy.imageExtent;
stencilCopy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), stencilCopy));
appendSubresourceUpdate(SubresourceUpdate(currentBuffer, stencilCopy));
aspectFlags &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
}
@ -3865,7 +3869,7 @@ angle::Result ImageHelper::stageSubresourceUpdateImpl(ContextVk *contextVk,
if (aspectFlags)
{
copy.imageSubresource.aspectMask = aspectFlags;
appendSubresourceUpdate(SubresourceUpdate(mStagingBuffer.getCurrentBuffer(), copy));
appendSubresourceUpdate(SubresourceUpdate(currentBuffer, copy));
}
return angle::Result::Continue;
@ -3902,6 +3906,7 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
const gl::Offset &offset,
const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type,
const uint8_t *pixels,
const Format &vkFormat)
@ -3913,8 +3918,8 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
&inputRowPitch, &inputDepthPitch, &inputSkipBytes));
ANGLE_TRY(stageSubresourceUpdateImpl(contextVk, index, glExtents, offset, formatInfo, unpack,
type, pixels, vkFormat, inputRowPitch, inputDepthPitch,
inputSkipBytes));
stagingBufferOverride, type, pixels, vkFormat,
inputRowPitch, inputDepthPitch, inputSkipBytes));
return angle::Result::Continue;
}

Просмотреть файл

@ -1262,6 +1262,7 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &offset,
const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type,
const uint8_t *pixels,
const Format &vkFormat,
@ -1275,6 +1276,7 @@ class ImageHelper final : public Resource, public angle::Subject
const gl::Offset &offset,
const gl::InternalFormat &formatInfo,
const gl::PixelUnpackState &unpack,
DynamicBuffer *stagingBufferOverride,
GLenum type,
const uint8_t *pixels,
const Format &vkFormat);