Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit efd2a66

Browse files
null77Commit Bot
authored andcommitted
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/+/2057354 Reviewed-by: Tim Van Patten <timvp@google.com> Reviewed-by: Michael Spang <spang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 parent f6e7313 commit efd2a66

File tree

3 files changed

+79
-22
lines changed

3 files changed

+79
-22
lines changed

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4103,6 +4103,21 @@ void ContextVk::onRenderPassImageWrite(VkImageAspectFlags aspectFlags,
41034103
mRenderPassCommands.imageWrite(&mResourceUseList, aspectFlags, imageLayout, image);
41044104
}
41054105

4106+
angle::Result ContextVk::syncExternalMemory()
4107+
{
4108+
vk::CommandBuffer *commandBuffer;
4109+
ANGLE_TRY(getOutsideRenderPassCommandBuffer(&commandBuffer));
4110+
4111+
VkMemoryBarrier memoryBarrier = {};
4112+
memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
4113+
memoryBarrier.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
4114+
memoryBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
4115+
4116+
commandBuffer->memoryBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4117+
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, &memoryBarrier);
4118+
return angle::Result::Continue;
4119+
}
4120+
41064121
CommandBufferHelper::CommandBufferHelper()
41074122
: mImageBarrierSrcStageMask(0),
41084123
mImageBarrierDstStageMask(0),

src/libANGLE/renderer/vulkan/ContextVk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
626626
egl::ContextPriority getContextPriority() const override { return mContextPriority; }
627627
angle::Result endRenderPass();
628628

629+
angle::Result syncExternalMemory();
630+
629631
private:
630632
// Dirty bits.
631633
enum DirtyBitType : size_t

src/libANGLE/renderer/vulkan/SemaphoreVk.cpp

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
8585
if (!bufferBarriers.empty() || !textureBarriers.empty())
8686
{
8787
// Create one global memory barrier to cover all barriers.
88-
contextVk->getCommandGraph()->syncExternalMemory();
88+
if (contextVk->commandGraphEnabled())
89+
{
90+
contextVk->getCommandGraph()->syncExternalMemory();
91+
}
92+
else
93+
{
94+
ANGLE_TRY(contextVk->syncExternalMemory());
95+
}
8996
}
9097

9198
uint32_t rendererQueueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex();
@@ -98,15 +105,22 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
98105
BufferVk *bufferVk = vk::GetImpl(buffer);
99106
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
100107

101-
// If there were GL commands using this buffer prior to this call, that's a
102-
// synchronization error on behalf of the program.
103-
ASSERT(!bufferHelper.hasRecordedCommands());
108+
vk::CommandBuffer *commandBuffer;
109+
if (contextVk->commandGraphEnabled())
110+
{
111+
// If there were GL commands using this buffer prior to this call, that's a
112+
// synchronization error on behalf of the program.
113+
ASSERT(!bufferHelper.hasRecordedCommands());
104114

105-
vk::CommandBuffer *queueChange;
106-
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange));
115+
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &commandBuffer));
116+
}
117+
else
118+
{
119+
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
120+
}
107121

108122
// Queue ownership transfer.
109-
bufferHelper.changeQueue(rendererQueueFamilyIndex, queueChange);
123+
bufferHelper.changeQueue(rendererQueueFamilyIndex, commandBuffer);
110124
}
111125
}
112126

@@ -121,19 +135,24 @@ angle::Result SemaphoreVk::wait(gl::Context *context,
121135
vk::ImageHelper &image = textureVk->getImage();
122136
vk::ImageLayout layout = GetVulkanImageLayout(textureAndLayout.layout);
123137

124-
// If there were GL commands using this image prior to this call, that's a
125-
// synchronization error on behalf of the program.
126-
ASSERT(!image.hasRecordedCommands());
127-
128138
// Inform the image that the layout has been externally changed.
129139
image.onExternalLayoutChange(layout);
130140

131-
vk::CommandBuffer *queueChange;
132-
ANGLE_TRY(image.recordCommands(contextVk, &queueChange));
133-
141+
vk::CommandBuffer *commandBuffer;
142+
if (contextVk->commandGraphEnabled())
143+
{
144+
// If there were GL commands using this image prior to this call, that's a
145+
// synchronization error on behalf of the program.
146+
ASSERT(!image.hasRecordedCommands());
147+
ANGLE_TRY(image.recordCommands(contextVk, &commandBuffer));
148+
}
149+
else
150+
{
151+
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
152+
}
134153
// Queue ownership transfer.
135154
image.changeLayoutAndQueue(image.getAspectFlags(), layout, rendererQueueFamilyIndex,
136-
queueChange);
155+
commandBuffer);
137156
}
138157
}
139158

@@ -155,11 +174,18 @@ angle::Result SemaphoreVk::signal(gl::Context *context,
155174
BufferVk *bufferVk = vk::GetImpl(buffer);
156175
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
157176

158-
vk::CommandBuffer *queueChange;
159-
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &queueChange));
177+
vk::CommandBuffer *commandBuffer;
178+
if (contextVk->commandGraphEnabled())
179+
{
180+
ANGLE_TRY(bufferHelper.recordCommands(contextVk, &commandBuffer));
181+
}
182+
else
183+
{
184+
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
185+
}
160186

161187
// Queue ownership transfer.
162-
bufferHelper.changeQueue(VK_QUEUE_FAMILY_EXTERNAL, queueChange);
188+
bufferHelper.changeQueue(VK_QUEUE_FAMILY_EXTERNAL, commandBuffer);
163189
}
164190
}
165191

@@ -181,19 +207,33 @@ angle::Result SemaphoreVk::signal(gl::Context *context,
181207
layout = image.getCurrentImageLayout();
182208
}
183209

184-
vk::CommandBuffer *layoutChange;
185-
ANGLE_TRY(image.recordCommands(contextVk, &layoutChange));
210+
vk::CommandBuffer *commandBuffer;
211+
if (contextVk->commandGraphEnabled())
212+
{
213+
ANGLE_TRY(image.recordCommands(contextVk, &commandBuffer));
214+
}
215+
else
216+
{
217+
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
218+
}
186219

187220
// Queue ownership transfer and layout transition.
188221
image.changeLayoutAndQueue(image.getAspectFlags(), layout, VK_QUEUE_FAMILY_EXTERNAL,
189-
layoutChange);
222+
commandBuffer);
190223
}
191224
}
192225

193226
if (!bufferBarriers.empty() || !textureBarriers.empty())
194227
{
195228
// Create one global memory barrier to cover all barriers.
196-
contextVk->getCommandGraph()->syncExternalMemory();
229+
if (contextVk->commandGraphEnabled())
230+
{
231+
contextVk->getCommandGraph()->syncExternalMemory();
232+
}
233+
else
234+
{
235+
ANGLE_TRY(contextVk->syncExternalMemory());
236+
}
197237
}
198238

199239
return contextVk->flushImpl(&mSemaphore);

0 commit comments

Comments
 (0)