Skip to content

Commit c35d01a

Browse files
author
kevyuu
committed
Fix stack size calculation when the shader group is empty
1 parent c09154b commit c35d01a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/nbl/video/CVulkanRayTracingPipeline.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "nbl/video/CVulkanLogicalDevice.h"
55
#include "nbl/video/IGPURayTracingPipeline.h"
66

7-
#include <algorithm>
87
#include <span>
98

109
namespace nbl::video
@@ -128,11 +127,22 @@ namespace nbl::video
128127
// calculation follow the formula from
129128
// https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#ray-tracing-pipeline-stack
130129
const auto raygenStackMax = m_raygenStackSize;
131-
const auto closestHitStackMax = std::ranges::max_element(getHitStackSizes(), std::ranges::less{}, &SHitGroupStackSize::closestHit)->closestHit;
132-
const auto anyHitStackMax = std::ranges::max_element(getHitStackSizes(), std::ranges::less{}, &SHitGroupStackSize::anyHit)->anyHit;
133-
const auto intersectionStackMax = std::ranges::max_element(getHitStackSizes(), std::ranges::less{}, &SHitGroupStackSize::intersection)->intersection;
134-
const auto missStackMax = *std::ranges::max_element(getMissStackSizes());
135-
const auto callableStackMax = *std::ranges::max_element(getCallableStackSizes());
130+
131+
auto getMaxSize = [&](auto ranges, auto valProj) -> uint16_t
132+
{
133+
auto maxValue = 0;
134+
for (const auto& val : ranges)
135+
{
136+
maxValue = std::max<uint16_t>(maxValue, std::invoke(valProj, val));
137+
}
138+
return maxValue;
139+
};
140+
141+
const auto closestHitStackMax = getMaxSize(getHitStackSizes(), &SHitGroupStackSize::closestHit);
142+
const auto anyHitStackMax = getMaxSize(getHitStackSizes(), &SHitGroupStackSize::anyHit);
143+
const auto intersectionStackMax = getMaxSize(getHitStackSizes(), &SHitGroupStackSize::intersection);
144+
const auto missStackMax = getMaxSize(getMissStackSizes(), std::identity{});
145+
const auto callableStackMax = getMaxSize(getCallableStackSizes(), std::identity{});
136146
return raygenStackMax + std::min<uint16_t>(1, m_params.maxRecursionDepth) *
137147
std::max(closestHitStackMax, std::max<uint16_t>(missStackMax, intersectionStackMax + anyHitStackMax)) +
138148
std::max<uint16_t>(0, m_params.maxRecursionDepth - 1) * std::max(closestHitStackMax, missStackMax) + 2 *

0 commit comments

Comments
 (0)