Commit efd2a669 by Jamie Madill Committed by Commit Bot

Vulkan: Command graph linearization for SemaphoreVk.

This doesn't seem to be tested in the default CQ configuration. Bug: angleproject:4029 Change-Id: If0acd5c78602324433b63498e2de8c16881023de Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2057354Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarMichael Spang <spang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent f6e73131
......@@ -4103,6 +4103,21 @@ void ContextVk::onRenderPassImageWrite(VkImageAspectFlags aspectFlags,
mRenderPassCommands.imageWrite(&mResourceUseList, aspectFlags, imageLayout, image);
}
angle::Result ContextVk::syncExternalMemory()
{
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(getOutsideRenderPassCommandBuffer(&commandBuffer));
VkMemoryBarrier memoryBarrier = {};
memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
memoryBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
memoryBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
commandBuffer->memoryBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, &memoryBarrier);
return angle::Result::Continue;
}
CommandBufferHelper::CommandBufferHelper()
: mImageBarrierSrcStageMask(0),
mImageBarrierDstStageMask(0),
......
......@@ -626,6 +626,8 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
egl::ContextPriority getContextPriority() const override { return mContextPriority; }
angle::Result endRenderPass();
angle::Result syncExternalMemory();
private:
// Dirty bits.
enum DirtyBitType : size_t
......
......@@ -85,7 +85,14 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
if (!bufferBarriers.empty() || !textureBarriers.empty())
{
// Create one global memory barrier to cover all barriers.
contextVk->getCommandGraph()->syncExternalMemory();
if (contextVk->commandGraphEnabled())
{
contextVk->getCommandGraph()->syncExternalMemory();
}
else
{
ANGLE_TRY(contextVk->syncExternalMemory());
}
}
uint32_t rendererQueueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex();
......@@ -98,15 +105,22 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
BufferVk *bufferVk = vk::GetImpl(buffer);
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
// If there were GL commands using this buffer prior to this call, that's a
// synchronization error on behalf of the program.
ASSERT(!bufferHelper.hasRecordedCommands());
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
// If there were GL commands using this buffer prior to this call, that's a
// synchronization error on behalf of the program.
ASSERT(!bufferHelper.hasRecordedCommands());
vk::CommandBuffer *queueChange;
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange));
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
// Queue ownership transfer.
bufferHelper.changeQueue(rendererQueueFamilyIndex, queueChange);
bufferHelper.changeQueue(rendererQueueFamilyIndex, commandBuffer);
}
}
......@@ -121,19 +135,24 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
vk::ImageHelper &image = textureVk->getImage();
vk::ImageLayout layout = GetVulkanImageLayout(textureAndLayout.layout);
// If there were GL commands using this image prior to this call, that's a
// synchronization error on behalf of the program.
ASSERT(!image.hasRecordedCommands());
// Inform the image that the layout has been externally changed.
image.onExternalLayoutChange(layout);
vk::CommandBuffer *queueChange;
ANGLE_TRY(image.recordCommands(contextVk, &queueChange));
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
// If there were GL commands using this image prior to this call, that's a
// synchronization error on behalf of the program.
ASSERT(!image.hasRecordedCommands());
ANGLE_TRY(image.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
// Queue ownership transfer.
image.changeLayoutAndQueue(image.getAspectFlags(), layout, rendererQueueFamilyIndex,
queueChange);
commandBuffer);
}
}
......@@ -155,11 +174,18 @@ angle::Result SemaphoreVk::signal(gl::Context *context,
BufferVk *bufferVk = vk::GetImpl(buffer);
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
vk::CommandBuffer *queueChange;
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange));
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
// Queue ownership transfer.
bufferHelper.changeQueue(VK_QUEUE_FAMILY_EXTERNAL, queueChange);
bufferHelper.changeQueue(VK_QUEUE_FAMILY_EXTERNAL, commandBuffer);
}
}
......@@ -181,19 +207,33 @@ angle::Result SemaphoreVk::signal(gl::Context *context,
layout = image.getCurrentImageLayout();
}
vk::CommandBuffer *layoutChange;
ANGLE_TRY(image.recordCommands(contextVk, &layoutChange));
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(image.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
// Queue ownership transfer and layout transition.
image.changeLayoutAndQueue(image.getAspectFlags(), layout, VK_QUEUE_FAMILY_EXTERNAL,
layoutChange);
commandBuffer);
}
}
if (!bufferBarriers.empty() || !textureBarriers.empty())
{
// Create one global memory barrier to cover all barriers.
contextVk->getCommandGraph()->syncExternalMemory();
if (contextVk->commandGraphEnabled())
{
contextVk->getCommandGraph()->syncExternalMemory();
}
else
{
ANGLE_TRY(contextVk->syncExternalMemory());
}
}
return contextVk->flushImpl(&mSemaphore);
......
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