@@ -397,11 +397,13 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
397397 shaderGroups.callables = callableGroups;
398398
399399 params.cached .maxRecursionDepth = 1 ;
400+ params.cached .dynamicStackSize = true ;
400401
401402 if (!m_device->createRayTracingPipelines (nullptr , { ¶ms, 1 }, &m_rayTracingPipeline))
402403 return logFail (" Failed to create ray tracing pipeline" );
403- m_logger->log (" Ray Tracing Pipeline Created!" , system::ILogger::ELL_INFO);
404404
405+ calculateRayTracingStackSize (m_rayTracingPipeline);
406+
405407 if (!createShaderBindingTable (gQueue , m_rayTracingPipeline))
406408 return logFail (" Could not create shader binding table" );
407409
@@ -732,6 +734,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
732734 memcpy (&pc.invMVP , invModelViewProjectionMatrix.pointer (), sizeof (pc.invMVP ));
733735
734736 cmdbuf->bindRayTracingPipeline (m_rayTracingPipeline.get ());
737+ cmdbuf->setRayTracingPipelineStackSize (m_rayTracingStackSize);
735738 cmdbuf->pushConstants (m_rayTracingPipeline->getLayout (), IShader::E_SHADER_STAGE::ESS_ALL_RAY_TRACING, 0 , sizeof (SPushConstants), &pc);
736739 cmdbuf->bindDescriptorSets (EPBP_RAY_TRACING, m_rayTracingPipeline->getLayout (), 0 , 1 , &m_rayTracingDs.get ());
737740 if (m_useIndirectCommand)
@@ -1332,6 +1335,29 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
13321335 return true ;
13331336 }
13341337
1338+ void calculateRayTracingStackSize (const smart_refctd_ptr<video::IGPURayTracingPipeline>& pipeline)
1339+ {
1340+ const auto raygenStackSize = pipeline->getRaygenStackSize ();
1341+ auto getMaxSize = [&](auto ranges, auto valProj) -> uint16_t
1342+ {
1343+ auto maxValue = 0 ;
1344+ for (const auto & val : ranges)
1345+ {
1346+ maxValue = std::max<uint16_t >(maxValue, std::invoke (valProj, val));
1347+ }
1348+ return maxValue;
1349+ };
1350+
1351+ const auto closestHitStackMax = getMaxSize (pipeline->getHitStackSizes (), &IGPURayTracingPipeline::SHitGroupStackSize::closestHit);
1352+ const auto anyHitStackMax = getMaxSize (pipeline->getHitStackSizes (), &IGPURayTracingPipeline::SHitGroupStackSize::anyHit);
1353+ const auto intersectionStackMax = getMaxSize (pipeline->getHitStackSizes (), &IGPURayTracingPipeline::SHitGroupStackSize::intersection);
1354+ const auto missStackMax = getMaxSize (pipeline->getMissStackSizes (), std::identity{});
1355+ const auto callableStackMax = getMaxSize (pipeline->getCallableStackSizes (), std::identity{});
1356+ auto firstDepthStackSizeMax = std::max (closestHitStackMax, missStackMax);
1357+ firstDepthStackSizeMax = std::max<uint16_t >(firstDepthStackSizeMax, intersectionStackMax + anyHitStackMax);
1358+ m_rayTracingStackSize = raygenStackSize + std::max (firstDepthStackSizeMax, callableStackMax);
1359+ }
1360+
13351361 bool createShaderBindingTable (video::CThreadSafeQueueAdapter* queue, const smart_refctd_ptr<video::IGPURayTracingPipeline>& pipeline)
13361362 {
13371363 const auto & limits = m_device->getPhysicalDevice ()->getLimits ();
@@ -1823,6 +1849,7 @@ class RaytracingPipelineApp final : public examples::SimpleWindowedApplication,
18231849 smart_refctd_ptr<IDescriptorPool> m_rayTracingDsPool;
18241850 smart_refctd_ptr<IGPUDescriptorSet> m_rayTracingDs;
18251851 smart_refctd_ptr<IGPURayTracingPipeline> m_rayTracingPipeline;
1852+ uint64_t m_rayTracingStackSize;
18261853 ShaderBindingTable m_shaderBindingTable;
18271854
18281855 smart_refctd_ptr<IGPUDescriptorSet> m_presentDs;
0 commit comments