From b3f6d555c212a9e48a3527cfbfb5c1463295630d Mon Sep 17 00:00:00 2001 From: Przemog1 Date: Fri, 14 Nov 2025 21:07:07 +0100 Subject: [PATCH] Fixed `ResolveAccessor` concept --- examples_tests | 2 +- include/nbl/builtin/hlsl/rwmc/resolve.hlsl | 60 +++++++++++----------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/examples_tests b/examples_tests index d4e5754b04..16c8d4228f 160000 --- a/examples_tests +++ b/examples_tests @@ -1 +1 @@ -Subproject commit d4e5754b0400499ec8d8bbae4331fe3526944773 +Subproject commit 16c8d4228fce3bb2012941b994c3a7877fbd8585 diff --git a/include/nbl/builtin/hlsl/rwmc/resolve.hlsl b/include/nbl/builtin/hlsl/rwmc/resolve.hlsl index 6484ef38b7..d8f777d277 100644 --- a/include/nbl/builtin/hlsl/rwmc/resolve.hlsl +++ b/include/nbl/builtin/hlsl/rwmc/resolve.hlsl @@ -5,6 +5,8 @@ #include #include #include +#include +#include namespace nbl { @@ -19,23 +21,21 @@ namespace rwmc // not the greatest syntax but works #define NBL_CONCEPT_PARAM_0 (a,T) #define NBL_CONCEPT_PARAM_1 (scalar,VectorScalarType) -#define NBL_CONCEPT_PARAM_2 (vec,vector) // start concept NBL_CONCEPT_BEGIN(2) // need to be defined AFTER the concept begins #define a NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0 #define scalar NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1 -#define vec NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2 NBL_CONCEPT_END( - ((NBL_CONCEPT_REQ_EXPR)((a.calcLuma(vec)))) + ((NBL_CONCEPT_REQ_EXPR)((a.calcLuma(vector(scalar, scalar, scalar))))) ); #undef a -#undef vec +#undef scalar #include /* ResolveAccessor is required to: * - satisfy `LoadableImage` concept requirements -* - implement function called `calcLuma` which calculates luma from a pixel value +* - implement function called `calcLuma` which calculates luma from a 3 component pixel value */ template @@ -50,9 +50,9 @@ struct ResolveAccessorAdaptor RWTexture2DArray cascade; - float32_t calcLuma(in float32_t3 col) + float32_t calcLuma(NBL_REF_ARG(float32_t3) col) { - return hlsl::dot(hlsl::transpose(colorspace::scRGBtoXYZ)[1], col); + return hlsl::dot(colorspace::scRGB::ToXYZ()[1], col); } template @@ -69,10 +69,11 @@ struct ResolveAccessorAdaptor } }; -template //NBL_PRIMARY_REQUIRES(ResolveAccessor) +template && ResolveAccessor) struct Resolver { - using output_type = OutputColorType; + using output_type = OutputColorTypeVec; + using scalar_t = typename vector_traits::scalar_type; struct CascadeSample { @@ -91,13 +92,15 @@ struct Resolver output_type operator()(NBL_REF_ARG(CascadeAccessor) acc, const int16_t2 coord) { - float reciprocalBaseI = 1.f; + using scalar_t = typename vector_traits::scalar_type; + + scalar_t reciprocalBaseI = 1.f; CascadeSample curr = __sampleCascade(acc, coord, 0u, reciprocalBaseI); - float32_t3 accumulation = float32_t3(0.0f, 0.0f, 0.0f); - float Emin = params.initialEmin; + output_type accumulation = output_type(0.0f, 0.0f, 0.0f); + scalar_t Emin = params.initialEmin; - float prevNormalizedCenterLuma, prevNormalizedNeighbourhoodAverageLuma; + scalar_t prevNormalizedCenterLuma, prevNormalizedNeighbourhoodAverageLuma; for (int16_t i = 0u; i <= params.lastCascadeIndex; i++) { const bool notFirstCascade = i != 0; @@ -110,13 +113,13 @@ struct Resolver next = __sampleCascade(acc, coord, int16_t(i + 1), reciprocalBaseI); } - float reliability = 1.f; + scalar_t reliability = 1.f; // sample counting-based reliability estimation if (params.reciprocalKappa <= 1.f) { - float localReliability = curr.normalizedCenterLuma; + scalar_t localReliability = curr.normalizedCenterLuma; // reliability in 3x3 pixel block (see robustness) - float globalReliability = curr.normalizedNeighbourhoodAverageLuma; + scalar_t globalReliability = curr.normalizedNeighbourhoodAverageLuma; if (notFirstCascade) { localReliability += prevNormalizedCenterLuma; @@ -130,11 +133,11 @@ struct Resolver // check if above minimum sampling threshold (avg 9 sample occurences in 3x3 neighbourhood), then use per-pixel reliability (NOTE: tertiary op is in reverse) reliability = globalReliability < params.reciprocalN ? globalReliability : localReliability; { - const float accumLuma = acc.calcLuma(accumulation); + const scalar_t accumLuma = acc.calcLuma(accumulation); if (accumLuma > Emin) Emin = accumLuma; - const float colorReliability = Emin * reciprocalBaseI * params.colorReliabilityFactor; + const scalar_t colorReliability = Emin * reciprocalBaseI * params.colorReliabilityFactor; reliability += colorReliability; reliability *= params.NOverKappa; @@ -156,19 +159,18 @@ struct Resolver // pseudo private stuff: - CascadeSample __sampleCascade(NBL_REF_ARG(CascadeAccessor) acc, int16_t2 coord, uint16_t cascadeIndex, float reciprocalBaseI) + CascadeSample __sampleCascade(NBL_REF_ARG(CascadeAccessor) acc, int16_t2 coord, uint16_t cascadeIndex, scalar_t reciprocalBaseI) { - typename CascadeAccessor::output_type tmp; output_type neighbourhood[9]; - neighbourhood[0] = acc.template get(coord + int16_t2(-1, -1), cascadeIndex); - neighbourhood[1] = acc.template get(coord + int16_t2(0, -1), cascadeIndex); - neighbourhood[2] = acc.template get(coord + int16_t2(1, -1), cascadeIndex); - neighbourhood[3] = acc.template get(coord + int16_t2(-1, 0), cascadeIndex); - neighbourhood[4] = acc.template get(coord + int16_t2(0, 0), cascadeIndex); - neighbourhood[5] = acc.template get(coord + int16_t2(1, 0), cascadeIndex); - neighbourhood[6] = acc.template get(coord + int16_t2(-1, 1), cascadeIndex); - neighbourhood[7] = acc.template get(coord + int16_t2(0, 1), cascadeIndex); - neighbourhood[8] = acc.template get(coord + int16_t2(1, 1), cascadeIndex); + neighbourhood[0] = acc.template get(coord + int16_t2(-1, -1), cascadeIndex).xyz; + neighbourhood[1] = acc.template get(coord + int16_t2(0, -1), cascadeIndex).xyz; + neighbourhood[2] = acc.template get(coord + int16_t2(1, -1), cascadeIndex).xyz; + neighbourhood[3] = acc.template get(coord + int16_t2(-1, 0), cascadeIndex).xyz; + neighbourhood[4] = acc.template get(coord + int16_t2(0, 0), cascadeIndex).xyz; + neighbourhood[5] = acc.template get(coord + int16_t2(1, 0), cascadeIndex).xyz; + neighbourhood[6] = acc.template get(coord + int16_t2(-1, 1), cascadeIndex).xyz; + neighbourhood[7] = acc.template get(coord + int16_t2(0, 1), cascadeIndex).xyz; + neighbourhood[8] = acc.template get(coord + int16_t2(1, 1), cascadeIndex).xyz; // numerical robustness float32_t3 excl_hood_sum = ((neighbourhood[0] + neighbourhood[1]) + (neighbourhood[2] + neighbourhood[3])) +