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

Commit 21c5af3

Browse files
tobineCommit Bot
authored andcommitted
Vulkan:Migrate events and queries to secondary Cmd Buffer
Replace flushAndGetPrimaryCommandBuffer() function with endRenderPassAndGetCommandBuffer() for events and queries. The end result should be the same, but this allows a number of places that were putting commands directly into the primary to put the commands into ANGLE's custom SecondaryCommandBuffer (SCB) instead. This also fixes a couple of minor bugs related to command buffer ordering. flushAndBeginRenderPass() now flushes any outside RenderPass (RP) commands first. Also, when insideRP commands are flushed to the primary, set "mHasPrimaryCommands = true;" Bug: b/153666475 Change-Id: I68413f25d27175afed0a20bc49f22f4c8d01e4fb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2156932 Reviewed-by: Jamie Madill <[email protected]> Reviewed-by: Charlie Lao <[email protected]> Commit-Queue: Tobin Ehlis <[email protected]>
1 parent 5578fc8 commit 21c5af3

File tree

5 files changed

+50
-32
lines changed

5 files changed

+50
-32
lines changed

src/libANGLE/renderer/vulkan/ContextVk.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,8 +4195,11 @@ angle::Result ContextVk::flushAndBeginRenderPass(
41954195
const std::vector<VkClearValue> &clearValues,
41964196
vk::CommandBuffer **commandBufferOut)
41974197
{
4198-
vk::PrimaryCommandBuffer *primary;
4199-
ANGLE_TRY(flushAndGetPrimaryCommandBuffer(&primary));
4198+
// Flush any outside renderPass commands first
4199+
flushOutsideRenderPassCommands();
4200+
// Next end any currently outstanding renderPass
4201+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
4202+
ANGLE_TRY(endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
42004203

42014204
gl::Rectangle rotatedRenderArea = renderArea;
42024205
if (isRotatedAspectRatioForDrawFBO())
@@ -4237,6 +4240,7 @@ angle::Result ContextVk::endRenderPass()
42374240
return angle::Result::Continue;
42384241
}
42394242

4243+
ASSERT(mOutsideRenderPassCommands.empty());
42404244
if (mActiveQueryAnySamples)
42414245
{
42424246
mActiveQueryAnySamples->getQueryHelper()->endOcclusionQuery(this, mRenderPassCommandBuffer);
@@ -4262,6 +4266,7 @@ angle::Result ContextVk::endRenderPass()
42624266
mRenderPassCommands.pauseTransformFeedbackIfStarted();
42634267

42644268
ANGLE_TRY(mRenderPassCommands.flushToPrimary(this, &mPrimaryCommands));
4269+
mHasPrimaryCommands = true;
42654270

42664271
if (mGpuEventsEnabled)
42674272
{
@@ -4608,8 +4613,7 @@ void RenderPassCommandBuffer::beginTransformFeedback(size_t validBufferCount,
46084613
angle::Result RenderPassCommandBuffer::flushToPrimary(ContextVk *contextVk,
46094614
vk::PrimaryCommandBuffer *primary)
46104615
{
4611-
if (empty())
4612-
return angle::Result::Continue;
4616+
ASSERT(!empty());
46134617

46144618
if (kEnableCommandStreamDiagnostics)
46154619
{

src/libANGLE/renderer/vulkan/ContextVk.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -652,17 +652,6 @@ class ContextVk : public ContextImpl, public vk::Context
652652
return mRenderPassCommands;
653653
}
654654

655-
angle::Result flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer **primaryCommands)
656-
{
657-
flushOutsideRenderPassCommands();
658-
ANGLE_TRY(endRenderPass());
659-
*primaryCommands = &mPrimaryCommands;
660-
661-
// We assume any calling code is going to record primary commands.
662-
mHasPrimaryCommands = true;
663-
return angle::Result::Continue;
664-
}
665-
666655
egl::ContextPriority getContextPriority() const override { return mContextPriority; }
667656
angle::Result startRenderPass(gl::Rectangle renderArea);
668657
angle::Result endRenderPass();
@@ -770,6 +759,17 @@ class ContextVk : public ContextImpl, public vk::Context
770759
double cpuTimestampS;
771760
};
772761

762+
angle::Result flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer **primaryCommands)
763+
{
764+
flushOutsideRenderPassCommands();
765+
ANGLE_TRY(endRenderPass());
766+
*primaryCommands = &mPrimaryCommands;
767+
768+
// We assume any calling code is going to record primary commands.
769+
mHasPrimaryCommands = true;
770+
return angle::Result::Continue;
771+
}
772+
773773
angle::Result setupDraw(const gl::Context *context,
774774
gl::PrimitiveMode mode,
775775
GLint firstVertexOrInvalid,

src/libANGLE/renderer/vulkan/SyncVk.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ angle::Result SyncHelper::initialize(ContextVk *contextVk)
4646

4747
mEvent = event.release();
4848

49-
vk::PrimaryCommandBuffer *primary;
50-
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary));
51-
primary->setEvent(mEvent.getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
49+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
50+
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
51+
outsideRenderPassCommandBuffer->setEvent(mEvent.getHandle(),
52+
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
5253
retain(&contextVk->getResourceUseList());
5354

5455
return angle::Result::Continue;
@@ -100,10 +101,11 @@ angle::Result SyncHelper::clientWait(Context *context,
100101

101102
angle::Result SyncHelper::serverWait(ContextVk *contextVk)
102103
{
103-
vk::PrimaryCommandBuffer *primary;
104-
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary));
105-
primary->waitEvents(1, mEvent.ptr(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
106-
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, nullptr, 0, nullptr, 0, nullptr);
104+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
105+
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
106+
outsideRenderPassCommandBuffer->waitEvents(
107+
1, mEvent.ptr(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
108+
0, nullptr, 0, nullptr, 0, nullptr);
107109
retain(&contextVk->getResourceUseList());
108110
return angle::Result::Continue;
109111
}

src/libANGLE/renderer/vulkan/vk_helpers.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,20 +1172,20 @@ void QueryHelper::deinit()
11721172

11731173
angle::Result QueryHelper::beginQuery(ContextVk *contextVk)
11741174
{
1175-
vk::PrimaryCommandBuffer *primaryCommands;
1176-
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primaryCommands));
1175+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
1176+
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
11771177
const QueryPool &queryPool = getQueryPool();
1178-
primaryCommands->resetQueryPool(queryPool, mQuery, 1);
1179-
primaryCommands->beginQuery(queryPool, mQuery, 0);
1178+
outsideRenderPassCommandBuffer->resetQueryPool(queryPool.getHandle(), mQuery, 1);
1179+
outsideRenderPassCommandBuffer->beginQuery(queryPool.getHandle(), mQuery, 0);
11801180
mMostRecentSerial = contextVk->getCurrentQueueSerial();
11811181
return angle::Result::Continue;
11821182
}
11831183

11841184
angle::Result QueryHelper::endQuery(ContextVk *contextVk)
11851185
{
1186-
vk::PrimaryCommandBuffer *primaryCommands;
1187-
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primaryCommands));
1188-
primaryCommands->endQuery(getQueryPool(), mQuery);
1186+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
1187+
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
1188+
outsideRenderPassCommandBuffer->endQuery(getQueryPool().getHandle(), mQuery);
11891189
mMostRecentSerial = contextVk->getCurrentQueueSerial();
11901190
return angle::Result::Continue;
11911191
}
@@ -1209,9 +1209,9 @@ void QueryHelper::endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderP
12091209

12101210
angle::Result QueryHelper::flushAndWriteTimestamp(ContextVk *contextVk)
12111211
{
1212-
vk::PrimaryCommandBuffer *primary;
1213-
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary));
1214-
writeTimestamp(contextVk, primary);
1212+
vk::CommandBuffer *outsideRenderPassCommandBuffer;
1213+
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
1214+
writeTimestamp(contextVk, outsideRenderPassCommandBuffer);
12151215
return angle::Result::Continue;
12161216
}
12171217

@@ -1223,6 +1223,15 @@ void QueryHelper::writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *pri
12231223
mMostRecentSerial = contextVk->getCurrentQueueSerial();
12241224
}
12251225

1226+
void QueryHelper::writeTimestamp(ContextVk *contextVk, CommandBuffer *commandBuffer)
1227+
{
1228+
const QueryPool &queryPool = getQueryPool();
1229+
commandBuffer->resetQueryPool(queryPool.getHandle(), mQuery, 1);
1230+
commandBuffer->writeTimestamp(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPool.getHandle(),
1231+
mQuery);
1232+
mMostRecentSerial = contextVk->getCurrentQueueSerial();
1233+
}
1234+
12261235
bool QueryHelper::hasPendingWork(ContextVk *contextVk)
12271236
{
12281237
// If the renderer has a queue serial higher than the stored one, the command buffers that

src/libANGLE/renderer/vulkan/vk_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ class QueryHelper final
394394
void endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderPassCommandBuffer);
395395

396396
angle::Result flushAndWriteTimestamp(ContextVk *contextVk);
397+
// When syncing gpu/cpu time, main thread accesses primary directly
397398
void writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *primary);
399+
// All other timestamp accesses should be made on outsideRenderPassCommandBuffer
400+
void writeTimestamp(ContextVk *contextVk, CommandBuffer *outsideRenderPassCommandBuffer);
398401

399402
Serial getStoredQueueSerial() { return mMostRecentSerial; }
400403
bool hasPendingWork(ContextVk *contextVk);

0 commit comments

Comments
 (0)