Commit 21c5af31 by Tobin Ehlis Committed by Commit Bot

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/+/2156932Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCharlie Lao <cclao@google.com> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent 5578fc84
...@@ -4195,8 +4195,11 @@ angle::Result ContextVk::flushAndBeginRenderPass( ...@@ -4195,8 +4195,11 @@ angle::Result ContextVk::flushAndBeginRenderPass(
const std::vector<VkClearValue> &clearValues, const std::vector<VkClearValue> &clearValues,
vk::CommandBuffer **commandBufferOut) vk::CommandBuffer **commandBufferOut)
{ {
vk::PrimaryCommandBuffer *primary; // Flush any outside renderPass commands first
ANGLE_TRY(flushAndGetPrimaryCommandBuffer(&primary)); flushOutsideRenderPassCommands();
// Next end any currently outstanding renderPass
vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
gl::Rectangle rotatedRenderArea = renderArea; gl::Rectangle rotatedRenderArea = renderArea;
if (isRotatedAspectRatioForDrawFBO()) if (isRotatedAspectRatioForDrawFBO())
...@@ -4237,6 +4240,7 @@ angle::Result ContextVk::endRenderPass() ...@@ -4237,6 +4240,7 @@ angle::Result ContextVk::endRenderPass()
return angle::Result::Continue; return angle::Result::Continue;
} }
ASSERT(mOutsideRenderPassCommands.empty());
if (mActiveQueryAnySamples) if (mActiveQueryAnySamples)
{ {
mActiveQueryAnySamples->getQueryHelper()->endOcclusionQuery(this, mRenderPassCommandBuffer); mActiveQueryAnySamples->getQueryHelper()->endOcclusionQuery(this, mRenderPassCommandBuffer);
...@@ -4262,6 +4266,7 @@ angle::Result ContextVk::endRenderPass() ...@@ -4262,6 +4266,7 @@ angle::Result ContextVk::endRenderPass()
mRenderPassCommands.pauseTransformFeedbackIfStarted(); mRenderPassCommands.pauseTransformFeedbackIfStarted();
ANGLE_TRY(mRenderPassCommands.flushToPrimary(this, &mPrimaryCommands)); ANGLE_TRY(mRenderPassCommands.flushToPrimary(this, &mPrimaryCommands));
mHasPrimaryCommands = true;
if (mGpuEventsEnabled) if (mGpuEventsEnabled)
{ {
...@@ -4608,8 +4613,7 @@ void RenderPassCommandBuffer::beginTransformFeedback(size_t validBufferCount, ...@@ -4608,8 +4613,7 @@ void RenderPassCommandBuffer::beginTransformFeedback(size_t validBufferCount,
angle::Result RenderPassCommandBuffer::flushToPrimary(ContextVk *contextVk, angle::Result RenderPassCommandBuffer::flushToPrimary(ContextVk *contextVk,
vk::PrimaryCommandBuffer *primary) vk::PrimaryCommandBuffer *primary)
{ {
if (empty()) ASSERT(!empty());
return angle::Result::Continue;
if (kEnableCommandStreamDiagnostics) if (kEnableCommandStreamDiagnostics)
{ {
......
...@@ -652,17 +652,6 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -652,17 +652,6 @@ class ContextVk : public ContextImpl, public vk::Context
return mRenderPassCommands; return mRenderPassCommands;
} }
angle::Result flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer **primaryCommands)
{
flushOutsideRenderPassCommands();
ANGLE_TRY(endRenderPass());
*primaryCommands = &mPrimaryCommands;
// We assume any calling code is going to record primary commands.
mHasPrimaryCommands = true;
return angle::Result::Continue;
}
egl::ContextPriority getContextPriority() const override { return mContextPriority; } egl::ContextPriority getContextPriority() const override { return mContextPriority; }
angle::Result startRenderPass(gl::Rectangle renderArea); angle::Result startRenderPass(gl::Rectangle renderArea);
angle::Result endRenderPass(); angle::Result endRenderPass();
...@@ -770,6 +759,17 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -770,6 +759,17 @@ class ContextVk : public ContextImpl, public vk::Context
double cpuTimestampS; double cpuTimestampS;
}; };
angle::Result flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer **primaryCommands)
{
flushOutsideRenderPassCommands();
ANGLE_TRY(endRenderPass());
*primaryCommands = &mPrimaryCommands;
// We assume any calling code is going to record primary commands.
mHasPrimaryCommands = true;
return angle::Result::Continue;
}
angle::Result setupDraw(const gl::Context *context, angle::Result setupDraw(const gl::Context *context,
gl::PrimitiveMode mode, gl::PrimitiveMode mode,
GLint firstVertexOrInvalid, GLint firstVertexOrInvalid,
......
...@@ -46,9 +46,10 @@ angle::Result SyncHelper::initialize(ContextVk *contextVk) ...@@ -46,9 +46,10 @@ angle::Result SyncHelper::initialize(ContextVk *contextVk)
mEvent = event.release(); mEvent = event.release();
vk::PrimaryCommandBuffer *primary; vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary)); ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
primary->setEvent(mEvent.getHandle(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT); outsideRenderPassCommandBuffer->setEvent(mEvent.getHandle(),
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT);
retain(&contextVk->getResourceUseList()); retain(&contextVk->getResourceUseList());
return angle::Result::Continue; return angle::Result::Continue;
...@@ -100,10 +101,11 @@ angle::Result SyncHelper::clientWait(Context *context, ...@@ -100,10 +101,11 @@ angle::Result SyncHelper::clientWait(Context *context,
angle::Result SyncHelper::serverWait(ContextVk *contextVk) angle::Result SyncHelper::serverWait(ContextVk *contextVk)
{ {
vk::PrimaryCommandBuffer *primary; vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary)); ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
primary->waitEvents(1, mEvent.ptr(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, outsideRenderPassCommandBuffer->waitEvents(
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, nullptr, 0, nullptr, 0, nullptr); 1, mEvent.ptr(), VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0, nullptr, 0, nullptr, 0, nullptr);
retain(&contextVk->getResourceUseList()); retain(&contextVk->getResourceUseList());
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -1172,20 +1172,20 @@ void QueryHelper::deinit() ...@@ -1172,20 +1172,20 @@ void QueryHelper::deinit()
angle::Result QueryHelper::beginQuery(ContextVk *contextVk) angle::Result QueryHelper::beginQuery(ContextVk *contextVk)
{ {
vk::PrimaryCommandBuffer *primaryCommands; vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primaryCommands)); ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
const QueryPool &queryPool = getQueryPool(); const QueryPool &queryPool = getQueryPool();
primaryCommands->resetQueryPool(queryPool, mQuery, 1); outsideRenderPassCommandBuffer->resetQueryPool(queryPool.getHandle(), mQuery, 1);
primaryCommands->beginQuery(queryPool, mQuery, 0); outsideRenderPassCommandBuffer->beginQuery(queryPool.getHandle(), mQuery, 0);
mMostRecentSerial = contextVk->getCurrentQueueSerial(); mMostRecentSerial = contextVk->getCurrentQueueSerial();
return angle::Result::Continue; return angle::Result::Continue;
} }
angle::Result QueryHelper::endQuery(ContextVk *contextVk) angle::Result QueryHelper::endQuery(ContextVk *contextVk)
{ {
vk::PrimaryCommandBuffer *primaryCommands; vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primaryCommands)); ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
primaryCommands->endQuery(getQueryPool(), mQuery); outsideRenderPassCommandBuffer->endQuery(getQueryPool().getHandle(), mQuery);
mMostRecentSerial = contextVk->getCurrentQueueSerial(); mMostRecentSerial = contextVk->getCurrentQueueSerial();
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1209,9 +1209,9 @@ void QueryHelper::endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderP ...@@ -1209,9 +1209,9 @@ void QueryHelper::endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderP
angle::Result QueryHelper::flushAndWriteTimestamp(ContextVk *contextVk) angle::Result QueryHelper::flushAndWriteTimestamp(ContextVk *contextVk)
{ {
vk::PrimaryCommandBuffer *primary; vk::CommandBuffer *outsideRenderPassCommandBuffer;
ANGLE_TRY(contextVk->flushAndGetPrimaryCommandBuffer(&primary)); ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&outsideRenderPassCommandBuffer));
writeTimestamp(contextVk, primary); writeTimestamp(contextVk, outsideRenderPassCommandBuffer);
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1223,6 +1223,15 @@ void QueryHelper::writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *pri ...@@ -1223,6 +1223,15 @@ void QueryHelper::writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *pri
mMostRecentSerial = contextVk->getCurrentQueueSerial(); mMostRecentSerial = contextVk->getCurrentQueueSerial();
} }
void QueryHelper::writeTimestamp(ContextVk *contextVk, CommandBuffer *commandBuffer)
{
const QueryPool &queryPool = getQueryPool();
commandBuffer->resetQueryPool(queryPool.getHandle(), mQuery, 1);
commandBuffer->writeTimestamp(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPool.getHandle(),
mQuery);
mMostRecentSerial = contextVk->getCurrentQueueSerial();
}
bool QueryHelper::hasPendingWork(ContextVk *contextVk) bool QueryHelper::hasPendingWork(ContextVk *contextVk)
{ {
// If the renderer has a queue serial higher than the stored one, the command buffers that // If the renderer has a queue serial higher than the stored one, the command buffers that
......
...@@ -394,7 +394,10 @@ class QueryHelper final ...@@ -394,7 +394,10 @@ class QueryHelper final
void endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderPassCommandBuffer); void endOcclusionQuery(ContextVk *contextVk, CommandBuffer *renderPassCommandBuffer);
angle::Result flushAndWriteTimestamp(ContextVk *contextVk); angle::Result flushAndWriteTimestamp(ContextVk *contextVk);
// When syncing gpu/cpu time, main thread accesses primary directly
void writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *primary); void writeTimestamp(ContextVk *contextVk, PrimaryCommandBuffer *primary);
// All other timestamp accesses should be made on outsideRenderPassCommandBuffer
void writeTimestamp(ContextVk *contextVk, CommandBuffer *outsideRenderPassCommandBuffer);
Serial getStoredQueueSerial() { return mMostRecentSerial; } Serial getStoredQueueSerial() { return mMostRecentSerial; }
bool hasPendingWork(ContextVk *contextVk); bool hasPendingWork(ContextVk *contextVk);
......
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