Skip to content

Commit c0c1885

Browse files
committed
Example 07 Test QueryPools and Secondary CommandBuffers
1 parent c5b955b commit c0c1885

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

examples_tests/07.SubpassBaking/main.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class SubpassBaking : public ApplicationBase
6363
core::smart_refctd_ptr<video::IGPUBuffer> cameraUBO;
6464
video::CDumbPresentationOracle oracle;
6565
const asset::COBJMetadata::CRenderpassIndependentPipeline* pipelineMetadata = nullptr;
66+
67+
core::smart_refctd_ptr<video::IQueryPool> occlusionQueryPool;
68+
core::smart_refctd_ptr<video::IQueryPool> timestampQueryPool;
6669

6770
uint32_t acquiredNextFBO = {};
6871
int resourceIx = -1;
@@ -117,6 +120,25 @@ class SubpassBaking : public ApplicationBase
117120

118121
APP_CONSTRUCTOR(SubpassBaking)
119122

123+
void getAndLogQueryPoolResults()
124+
{
125+
#ifdef QUERY_POOL_LOGS
126+
bool all_results_available = false;
127+
uint64_t samples_passed[4] = {};
128+
while(!all_results_available)
129+
{
130+
auto queryResultFlags = core::bitflag<video::IQueryPool::E_QUERY_RESULTS_FLAGS>(video::IQueryPool::EQRF_WITH_AVAILABILITY_BIT) | video::IQueryPool::EQRF_64_BIT;
131+
logicalDevice->getQueryPoolResults(occlusionQueryPool.get(), 0u, 2u, sizeof(samples_passed), samples_passed, sizeof(uint64_t) * 2, queryResultFlags);
132+
133+
all_results_available = true;
134+
all_results_available &= samples_passed[1];
135+
// all_results_available &= samples_passed[3];
136+
}
137+
138+
logger->log("SamplesPassed[0] = %d, SamplesPassed[1] = %d", system::ILogger::ELL_INFO, samples_passed[0], samples_passed[2]);
139+
#endif
140+
}
141+
120142
void onAppInitialized_impl() override
121143
{
122144
CommonAPI::InitOutput initOutput;
@@ -142,6 +164,23 @@ class SubpassBaking : public ApplicationBase
142164
windowCb = std::move(initOutput.windowCb);
143165
cpu2gpuParams = std::move(initOutput.cpu2gpuParams);
144166
utilities = std::move(initOutput.utilities);
167+
168+
// Occlusion Query
169+
{
170+
video::IQueryPool::SCreationParams queryPoolCreationParams = {};
171+
queryPoolCreationParams.queryType = video::IQueryPool::EQT_OCCLUSION;
172+
queryPoolCreationParams.queryCount = 2u;
173+
occlusionQueryPool = logicalDevice->createQueryPool(std::move(queryPoolCreationParams));
174+
}
175+
176+
// Timestamp Query
177+
video::IQueryPool::SCreationParams queryPoolCreationParams = {};
178+
{
179+
video::IQueryPool::SCreationParams queryPoolCreationParams = {};
180+
queryPoolCreationParams.queryType = video::IQueryPool::EQT_TIMESTAMP;
181+
queryPoolCreationParams.queryCount = 2u;
182+
timestampQueryPool = logicalDevice->createQueryPool(std::move(queryPoolCreationParams));
183+
}
145184

146185
asset::ICPUMesh* meshRaw = nullptr;
147186
const asset::COBJMetadata* metaOBJ = nullptr;
@@ -247,7 +286,7 @@ class SubpassBaking : public ApplicationBase
247286
inheritanceInfo.renderpass = renderpass;
248287
inheritanceInfo.subpass = 0; // this should probably be kSubpassIx?
249288
// inheritanceInfo.framebuffer = ;
250-
// inheritanceInfo.occlusionQueryEnable = ;
289+
inheritanceInfo.occlusionQueryEnable = true;
251290
// inheritanceInfo.queryFlags = ;
252291

253292
bakedCommandBuffer->begin(video::IGPUCommandBuffer::EU_RENDER_PASS_CONTINUE_BIT | video::IGPUCommandBuffer::EU_SIMULTANEOUS_USE_BIT, &inheritanceInfo);
@@ -543,15 +582,24 @@ class SubpassBaking : public ApplicationBase
543582
beginInfo.clearValues = clear;
544583
}
545584

585+
commandBuffer->resetQueryPool(occlusionQueryPool.get(), 0u, 2u);
586+
commandBuffer->resetQueryPool(timestampQueryPool.get(), 0u, 2u);
587+
588+
commandBuffer->beginQuery(occlusionQueryPool.get(), 0u);
589+
546590
commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_SECONDARY_COMMAND_BUFFERS);
547591
commandBuffer->executeCommands(1u, &bakedCommandBuffer.get());
548592
commandBuffer->endRenderPass();
549593

594+
commandBuffer->endQuery(occlusionQueryPool.get(), 0u);
595+
550596
commandBuffer->end();
551597
}
552598

553599
CommonAPI::Submit(logicalDevice.get(), swapchain.get(), commandBuffer.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], imageAcquire[resourceIx].get(), renderFinished[resourceIx].get(), fence.get());
554600
CommonAPI::Present(logicalDevice.get(), swapchain.get(), queues[CommonAPI::InitOutput::EQT_GRAPHICS], renderFinished[resourceIx].get(), acquiredNextFBO);
601+
602+
getAndLogQueryPoolResults();
555603
}
556604

557605
bool keepRunning() override

0 commit comments

Comments
 (0)