|
4 | 4 | #include "nbl/video/CVulkanLogicalDevice.h"
|
5 | 5 | #include "nbl/video/IGPURayTracingPipeline.h"
|
6 | 6 |
|
7 |
| -#include <algorithm> |
8 | 7 | #include <span>
|
9 | 8 |
|
10 | 9 | namespace nbl::video
|
@@ -128,11 +127,22 @@ namespace nbl::video
|
128 | 127 | // calculation follow the formula from
|
129 | 128 | // https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#ray-tracing-pipeline-stack
|
130 | 129 | 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{}); |
136 | 146 | return raygenStackMax + std::min<uint16_t>(1, m_params.maxRecursionDepth) *
|
137 | 147 | std::max(closestHitStackMax, std::max<uint16_t>(missStackMax, intersectionStackMax + anyHitStackMax)) +
|
138 | 148 | std::max<uint16_t>(0, m_params.maxRecursionDepth - 1) * std::max(closestHitStackMax, missStackMax) + 2 *
|
|
0 commit comments