Commit dceaabb1 by Jamie Madill Committed by Commit Bot

Vulkan: Clean up ImageHelper barrier functions.

We don't need to explicitly check if a barrier is required for write barriers. Write barriers always require a barrier and read barriers need the layout change check. We introduce a new enum encoding ReadOnly vs Write layout types and call specialized write/read functions instead. Also renames the helper APIs to be more consistent. Refactoring change only. Bug: angleproject:4959 Change-Id: I0ce39ceaca6be588327c381194a580dc6b11f036 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2344744 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCharlie Lao <cclao@google.com> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 863115fb
......@@ -4364,12 +4364,10 @@ angle::Result ContextVk::onImageRead(VkImageAspectFlags aspectFlags,
// than a transfer read. So we cannot support simultaneous read usage as easily as for Buffers.
ANGLE_TRY(endRenderPassIfImageUsed(*image));
if (image->isLayoutChangeNecessary(imageLayout))
{
image->changeLayout(aspectFlags, imageLayout,
&mOutsideRenderPassCommands->getCommandBuffer());
}
image->recordReadBarrier(aspectFlags, imageLayout,
&mOutsideRenderPassCommands->getCommandBuffer());
image->retain(&mResourceUseList);
return angle::Result::Continue;
}
......@@ -4380,12 +4378,10 @@ angle::Result ContextVk::onImageWrite(VkImageAspectFlags aspectFlags,
ASSERT(!image->isReleasedToExternal());
ASSERT(image->getImageSerial().valid());
// Barriers are always required for image writes.
ASSERT(image->isLayoutChangeNecessary(imageLayout));
ANGLE_TRY(endRenderPassIfImageUsed(*image));
image->changeLayout(aspectFlags, imageLayout, &mOutsideRenderPassCommands->getCommandBuffer());
image->recordWriteBarrier(aspectFlags, imageLayout,
&mOutsideRenderPassCommands->getCommandBuffer());
image->retain(&mResourceUseList);
image->onWrite();
......
......@@ -1195,7 +1195,8 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk,
}
// This does nothing if it already in the requested layout
image.image.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::Present, commandBuffer);
image.image.recordReadBarrier(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::Present,
commandBuffer);
// Knowing that the kSwapHistorySize'th submission ago has finished, we can know that the
// (kSwapHistorySize+1)'th present ago of this image is definitely finished and so its wait
......
......@@ -798,11 +798,11 @@ class BufferHelper final : public Resource
// Returns true if the image is owned by an external API or instance.
bool isReleasedToExternal() const;
bool updateReadBarrier(VkAccessFlags readAccessType,
bool recordReadBarrier(VkAccessFlags readAccessType,
VkPipelineStageFlags readStage,
PipelineBarrier *barrier);
bool updateWriteBarrier(VkAccessFlags writeAccessType,
bool recordWriteBarrier(VkAccessFlags writeAccessType,
VkPipelineStageFlags writeStage,
PipelineBarrier *barrier);
......@@ -1353,22 +1353,26 @@ class ImageHelper final : public Resource, public angle::Subject
bool isUpdateStaged(uint32_t levelGL, uint32_t layer);
bool hasStagedUpdates() const { return !mSubresourceUpdates.empty(); }
// changeLayout automatically skips the layout change if it's unnecessary. This function can be
// used to prevent creating a command graph node and subsequently a command buffer for the sole
// purpose of performing a transition (which may then not be issued).
bool isLayoutChangeNecessary(ImageLayout newLayout) const;
void recordWriteBarrier(VkImageAspectFlags aspectMask,
ImageLayout newLayout,
CommandBuffer *commandBuffer)
{
barrierImpl(aspectMask, newLayout, mCurrentQueueFamilyIndex, commandBuffer);
}
template <typename CommandBufferT>
void changeLayout(VkImageAspectFlags aspectMask,
ImageLayout newLayout,
CommandBufferT *commandBuffer)
// This function can be used to prevent issuing redundant layout transition commands.
bool isReadBarrierNecessary(ImageLayout newLayout) const;
void recordReadBarrier(VkImageAspectFlags aspectMask,
ImageLayout newLayout,
CommandBuffer *commandBuffer)
{
if (!isLayoutChangeNecessary(newLayout))
if (!isReadBarrierNecessary(newLayout))
{
return;
}
forceChangeLayoutAndQueue(aspectMask, newLayout, mCurrentQueueFamilyIndex, commandBuffer);
barrierImpl(aspectMask, newLayout, mCurrentQueueFamilyIndex, commandBuffer);
}
bool isQueueChangeNeccesary(uint32_t newQueueFamilyIndex) const
......@@ -1531,10 +1535,10 @@ class ImageHelper final : public Resource, public angle::Subject
// Generalized to accept both "primary" and "secondary" command buffers.
template <typename CommandBufferT>
void forceChangeLayoutAndQueue(VkImageAspectFlags aspectMask,
ImageLayout newLayout,
uint32_t newQueueFamilyIndex,
CommandBufferT *commandBuffer);
void barrierImpl(VkImageAspectFlags aspectMask,
ImageLayout newLayout,
uint32_t newQueueFamilyIndex,
CommandBufferT *commandBuffer);
// If the image has emulated channels, we clear them once so as not to leave garbage on those
// channels.
......
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