Skip to content

Commit b674b06

Browse files
committed
Test QueryPools Example 06
1 parent 893fe7e commit b674b06

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

examples_tests/06.MeshLoaders/main.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class MeshLoadersApp : public ApplicationBase
8888
double dtList[NBL_FRAMES_TO_AVERAGE] = {};
8989

9090
video::CDumbPresentationOracle oracle;
91+
92+
core::smart_refctd_ptr<video::IGPUBuffer> queryResultsBuffer;
9193

9294
auto createDescriptorPool(const uint32_t textureCount)
9395
{
@@ -190,7 +192,7 @@ class MeshLoadersApp : public ApplicationBase
190192
const auto swapchainImageUsage = static_cast<asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT);
191193
const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_SRGB, asset::EOTF_sRGB);
192194

193-
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "MeshLoaders", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
195+
CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "MeshLoaders", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
194196
window = std::move(initOutput.window);
195197
windowCb = std::move(initOutput.windowCb);
196198
apiConnection = std::move(initOutput.apiConnection);
@@ -226,6 +228,22 @@ class MeshLoadersApp : public ApplicationBase
226228
timestampQueryPool = logicalDevice->createQueryPool(std::move(queryPoolCreationParams));
227229
}
228230

231+
{
232+
// SAMPLES_PASSED_0 + AVAILABILIY_0 + SAMPLES_PASSED_1 + AVAILABILIY_1 (uint32_t)
233+
const size_t queriesSize = sizeof(uint32_t) * 4;
234+
auto memreq = logicalDevice->getDeviceLocalGPUMemoryReqs();
235+
memreq.vulkanReqs.size = queriesSize;
236+
video::IGPUBuffer::SCreationParams gpuuboCreationParams;
237+
gpuuboCreationParams.canUpdateSubRange = true;
238+
gpuuboCreationParams.usage = core::bitflag<asset::IBuffer::E_USAGE_FLAGS>(asset::IBuffer::EUF_UNIFORM_BUFFER_BIT) | asset::IBuffer::EUF_TRANSFER_DST_BIT;
239+
gpuuboCreationParams.sharingMode = asset::E_SHARING_MODE::ESM_EXCLUSIVE;
240+
gpuuboCreationParams.queueFamilyIndexCount = 0u;
241+
gpuuboCreationParams.queueFamilyIndices = nullptr;
242+
243+
queryResultsBuffer = logicalDevice->createGPUBufferOnDedMem(gpuuboCreationParams, memreq);
244+
queryResultsBuffer->setObjectDebugName("QueryResults");
245+
}
246+
229247
nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
230248
{
231249
auto* quantNormalCache = assetManager->getMeshManipulator()->getQuantNormalCache();
@@ -502,11 +520,15 @@ class MeshLoadersApp : public ApplicationBase
502520
commandBuffer->drawMeshBuffer(gpuMeshBuffer);
503521

504522
if(i < 2)
505-
commandBuffer->endQuery(occlusionQueryPool.get(), i);
523+
commandBuffer->endQuery(occlusionQueryPool.get(), i);
506524
}
507525
commandBuffer->writeTimestamp(asset::E_PIPELINE_STAGE_FLAGS::EPSF_BOTTOM_OF_PIPE_BIT, timestampQueryPool.get(), 1u);
508526

509527
commandBuffer->endRenderPass();
528+
529+
auto queryResultFlags = core::bitflag<video::IQueryPool::E_QUERY_RESULTS_FLAGS>(video::IQueryPool::EQRF_WAIT_BIT) | video::IQueryPool::EQRF_WITH_AVAILABILITY_BIT;
530+
commandBuffer->copyQueryPoolResults(occlusionQueryPool.get(), 0, 2, queryResultsBuffer.get(), 0u, sizeof(uint32_t) * 2, queryResultFlags);
531+
510532
commandBuffer->end();
511533

512534
logicalDevice->resetFences(1, &fence.get());

0 commit comments

Comments
 (0)