Commit b84969ad by Jamie Madill Committed by Commit Bot

Vulkan: Use QueryHelper for internal GPU timing.

This cleans up the code. Using QueryHelper means we don't need to duplicate the timestamp query/result code. It also means we don't need special allocate/free functions in DynamicQueryPool. Done while investigating timing GPU events for T-Rex. Bug: angleproject:4433 Change-Id: I8512a5618e1dd00956942ae2d12d46d8193c4e51 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2081379Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 4fb29948
...@@ -1678,22 +1678,14 @@ angle::Result ContextVk::traceGpuEventImpl(vk::PrimaryCommandBuffer *commandBuff ...@@ -1678,22 +1678,14 @@ angle::Result ContextVk::traceGpuEventImpl(vk::PrimaryCommandBuffer *commandBuff
{ {
ASSERT(mGpuEventsEnabled); ASSERT(mGpuEventsEnabled);
GpuEventQuery event; GpuEventQuery gpuEvent;
gpuEvent.name = name;
gpuEvent.phase = phase;
ANGLE_TRY(mGpuEventQueryPool.allocateQuery(this, &gpuEvent.queryHelper));
event.name = name; gpuEvent.queryHelper.writeTimestamp(commandBuffer);
event.phase = phase;
event.serial = getCurrentQueueSerial();
ANGLE_TRY(mGpuEventQueryPool.allocateQuery(this, &event.queryPoolIndex, &event.queryIndex));
const vk::QueryPool &queryPool = mGpuEventQueryPool.getQueryPool(event.queryPoolIndex);
commandBuffer->resetQueryPool(queryPool, event.queryIndex, 1);
commandBuffer->writeTimestamp(VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, queryPool,
event.queryIndex);
mInFlightGpuEventQueries.push_back(std::move(event));
mInFlightGpuEventQueries.push_back(std::move(gpuEvent));
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1711,31 +1703,29 @@ angle::Result ContextVk::checkCompletedGpuEvents() ...@@ -1711,31 +1703,29 @@ angle::Result ContextVk::checkCompletedGpuEvents()
for (GpuEventQuery &eventQuery : mInFlightGpuEventQueries) for (GpuEventQuery &eventQuery : mInFlightGpuEventQueries)
{ {
// Only check the timestamp query if the submission has finished. // Only check the timestamp query if the submission has finished.
if (eventQuery.serial > lastCompletedSerial) if (eventQuery.queryHelper.getStoredQueueSerial() > lastCompletedSerial)
{ {
break; break;
} }
// See if the results are available. // See if the results are available.
uint64_t gpuTimestampCycles = 0; uint64_t gpuTimestampCycles = 0;
const vk::QueryPool &queryPool = mGpuEventQueryPool.getQueryPool(eventQuery.queryPoolIndex); bool available = false;
VkResult result = queryPool.getResults(getDevice(), eventQuery.queryIndex, 1, ANGLE_TRY(eventQuery.queryHelper.getUint64ResultNonBlocking(this, &gpuTimestampCycles,
sizeof(gpuTimestampCycles), &gpuTimestampCycles, &available));
sizeof(gpuTimestampCycles), VK_QUERY_RESULT_64_BIT); if (!available)
if (result == VK_NOT_READY)
{ {
break; break;
} }
ANGLE_VK_TRY(this, result);
mGpuEventQueryPool.freeQuery(this, eventQuery.queryPoolIndex, eventQuery.queryIndex); mGpuEventQueryPool.freeQuery(this, &eventQuery.queryHelper);
GpuEvent event; GpuEvent gpuEvent;
event.gpuTimestampCycles = gpuTimestampCycles; gpuEvent.gpuTimestampCycles = gpuTimestampCycles;
event.name = eventQuery.name; gpuEvent.name = eventQuery.name;
event.phase = eventQuery.phase; gpuEvent.phase = eventQuery.phase;
mGpuEvents.emplace_back(event); mGpuEvents.emplace_back(gpuEvent);
++finishedCount; ++finishedCount;
} }
......
...@@ -711,11 +711,7 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -711,11 +711,7 @@ class ContextVk : public ContextImpl, public vk::Context
{ {
const char *name; const char *name;
char phase; char phase;
vk::QueryHelper queryHelper;
uint32_t queryIndex;
size_t queryPoolIndex;
Serial serial;
}; };
// Once a query result is available, the timestamp is read and a GpuEvent object is kept until // Once a query result is available, the timestamp is read and a GpuEvent object is kept until
......
...@@ -933,11 +933,14 @@ angle::Result DynamicQueryPool::allocateQuery(ContextVk *contextVk, QueryHelper ...@@ -933,11 +933,14 @@ angle::Result DynamicQueryPool::allocateQuery(ContextVk *contextVk, QueryHelper
{ {
ASSERT(!queryOut->valid()); ASSERT(!queryOut->valid());
size_t poolIndex = 0; if (mCurrentFreeEntry >= mPoolSize)
uint32_t queryIndex = 0; {
ANGLE_TRY(allocateQuery(contextVk, &poolIndex, &queryIndex)); // No more queries left in this pool, create another one.
ANGLE_TRY(allocateNewPool(contextVk));
}
queryOut->init(this, poolIndex, queryIndex); uint32_t queryIndex = mCurrentFreeEntry++;
queryOut->init(this, mCurrentPool, queryIndex);
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -949,34 +952,12 @@ void DynamicQueryPool::freeQuery(ContextVk *contextVk, QueryHelper *query) ...@@ -949,34 +952,12 @@ void DynamicQueryPool::freeQuery(ContextVk *contextVk, QueryHelper *query)
size_t poolIndex = query->mQueryPoolIndex; size_t poolIndex = query->mQueryPoolIndex;
ASSERT(getQueryPool(poolIndex).valid()); ASSERT(getQueryPool(poolIndex).valid());
freeQuery(contextVk, poolIndex, query->mQuery); onEntryFreed(contextVk, poolIndex);
query->deinit(); query->deinit();
} }
} }
angle::Result DynamicQueryPool::allocateQuery(ContextVk *contextVk,
size_t *poolIndex,
uint32_t *queryIndex)
{
if (mCurrentFreeEntry >= mPoolSize)
{
// No more queries left in this pool, create another one.
ANGLE_TRY(allocateNewPool(contextVk));
}
*poolIndex = mCurrentPool;
*queryIndex = mCurrentFreeEntry++;
return angle::Result::Continue;
}
void DynamicQueryPool::freeQuery(ContextVk *contextVk, size_t poolIndex, uint32_t queryIndex)
{
ANGLE_UNUSED_VARIABLE(queryIndex);
onEntryFreed(contextVk, poolIndex);
}
angle::Result DynamicQueryPool::allocateNewPool(ContextVk *contextVk) angle::Result DynamicQueryPool::allocateNewPool(ContextVk *contextVk)
{ {
if (findFreeEntryPool(contextVk)) if (findFreeEntryPool(contextVk))
......
...@@ -281,11 +281,6 @@ class DynamicQueryPool final : public DynamicallyGrowingPool<QueryPool> ...@@ -281,11 +281,6 @@ class DynamicQueryPool final : public DynamicallyGrowingPool<QueryPool>
angle::Result allocateQuery(ContextVk *contextVk, QueryHelper *queryOut); angle::Result allocateQuery(ContextVk *contextVk, QueryHelper *queryOut);
void freeQuery(ContextVk *contextVk, QueryHelper *query); void freeQuery(ContextVk *contextVk, QueryHelper *query);
// Special allocator that doesn't work with QueryHelper, which is a CommandGraphResource.
// Currently only used with RendererVk::GpuEventQuery.
angle::Result allocateQuery(ContextVk *contextVk, size_t *poolIndex, uint32_t *queryIndex);
void freeQuery(ContextVk *contextVk, size_t poolIndex, uint32_t queryIndex);
const QueryPool &getQueryPool(size_t index) const { return mPools[index]; } const QueryPool &getQueryPool(size_t index) const { return mPools[index]; }
private: private:
......
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