diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 715e0d5755..207bd0b9dc 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -1166,6 +1166,12 @@ void Device::allocateRTDispatchGlobals(uint32_t maxBvhLevels) { auto rtStacksPerDss = RayTracingHelper::getNumRtStacksPerDss(*this); dispatchGlobals.numDSSRTStacks = rtStacksPerDss; dispatchGlobals.maxBVHLevels = maxBvhLevels; + + constexpr auto maxProgrammableBvhLevels = 7; + if (maxBvhLevels > maxProgrammableBvhLevels) { + dispatchGlobals.maxBVHLevels = 0; // 0 = special case: use 8 levels + } + uint32_t *dispatchGlobalsAsArray = reinterpret_cast(&dispatchGlobals); dispatchGlobalsAsArray[7] = 1; diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index c4780c3b83..eee4b127d4 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -263,6 +263,15 @@ TEST_F(DeviceTest, whenAllocateRTDispatchGlobalsIsCalledThenStackSizePerRayIsSet } } +TEST_F(DeviceTest, given8MaxBvhLevelsWhenAllocateRTDispatchGlobalsIsCalledThenMaxBvhLevelsIsSetCorrectly) { + uint32_t maxBvhLevels = 8u; + pDevice->initializeRayTracing(maxBvhLevels); + pDevice->allocateRTDispatchGlobals(maxBvhLevels); + EXPECT_NE(nullptr, pDevice->getRTDispatchGlobals(maxBvhLevels)); + RTDispatchGlobals dispatchGlobals = *reinterpret_cast(pDevice->getRTDispatchGlobals(maxBvhLevels)->rtDispatchGlobalsArray->getUnderlyingBuffer()); + EXPECT_EQ(0u, static_cast(dispatchGlobals.maxBVHLevels)); +} + TEST_F(DeviceTest, givenNot48bResourceForRtWhenAllocateRTDispatchGlobalsIsCalledThenRTDispatchGlobalsIsAllocatedWithout48bResourceFlag) { auto mockProductHelper = std::make_unique(); mockProductHelper->is48bResourceNeededForRayTracingResult = false;