Skip to content

Commit 0b6f269

Browse files
fix all DXC warnings and refactor the CascadeAccumulator (ex 31 needs to get fixed)
1 parent 93ad437 commit 0b6f269

11 files changed

Lines changed: 97 additions & 68 deletions

File tree

include/nbl/builtin/hlsl/bxdf/fresnel.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,9 @@ struct iridescent_base
665665
using vector_type = T;
666666

667667
template<bool SupportsTransmission, typename Colorspace>
668-
T __call(const vector_type iork3, const vector_type etak23, const scalar_type clampedCosTheta) NBL_CONST_MEMBER_FUNC
668+
T __call(const vector_type _iork3, const vector_type etak23, const scalar_type clampedCosTheta) NBL_CONST_MEMBER_FUNC
669669
{
670-
return impl::iridescent_helper<T,false>::template __call<Colorspace>(D, ior1, ior2, ior3, iork3,
670+
return impl::iridescent_helper<T,false>::template __call<Colorspace>(D, ior1, ior2, ior3, _iork3,
671671
eta12, eta23, etak23, clampedCosTheta);
672672
}
673673

@@ -684,9 +684,9 @@ struct iridescent_base
684684

685685
// workaround due to DXC bug: github.com/microsoft/DirectXShaderCompiler/issues/5966
686686
template<typename T, bool SupportsTransmission, typename Colorspace>
687-
T __iridescent_base__call_const(NBL_CONST_REF_ARG(iridescent_base<T>) _this, const T iork3, const T etak23, const typename vector_traits<T>::scalar_type clampedCosTheta)
687+
T __iridescent_base__call_const(NBL_CONST_REF_ARG(iridescent_base<T>) _this, const T _iork3, const T etak23, const typename vector_traits<T>::scalar_type clampedCosTheta)
688688
{
689-
return _this.template __call<SupportsTransmission, Colorspace>(iork3, etak23, clampedCosTheta);
689+
return _this.template __call<SupportsTransmission, Colorspace>(_iork3, etak23, clampedCosTheta);
690690
}
691691
}
692692

include/nbl/builtin/hlsl/ieee754.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ template<typename Float>
1616
struct traits_base
1717
{
1818
static_assert(is_same<Float, float16_t>::value || is_same<Float, float32_t>::value || is_same<Float, float64_t>::value);
19-
NBL_CONSTEXPR_STATIC_INLINE int16_t exponentBitCnt = int16_t(0xbeef);
20-
NBL_CONSTEXPR_STATIC_INLINE int16_t mantissaBitCnt = int16_t(0xbeef);
19+
NBL_CONSTEXPR_STATIC_INLINE int16_t exponentBitCnt = (int16_t)0xbeef;
20+
NBL_CONSTEXPR_STATIC_INLINE int16_t mantissaBitCnt = (int16_t)0xbeef;
2121
};
2222

2323
template<>
@@ -73,7 +73,7 @@ template<>
7373
inline uint32_t extractBiasedExponent(uint64_t x)
7474
{
7575
uint64_t output = (x >> traits<float64_t>::mantissaBitCnt) & (traits<float64_t>::exponentMask >> traits<float64_t>::mantissaBitCnt);
76-
return uint32_t(output);
76+
return _static_cast<uint32_t>(output);
7777
}
7878

7979
template<>
@@ -100,7 +100,7 @@ NBL_CONSTEXPR_FUNC T replaceBiasedExponent(T x, typename unsigned_integer_of_siz
100100
template <typename T>
101101
NBL_CONSTEXPR_FUNC T fastMulExp2(T x, int n)
102102
{
103-
return replaceBiasedExponent(x, extractBiasedExponent(x) + uint32_t(n));
103+
return replaceBiasedExponent(x, extractBiasedExponent(x) + _static_cast<uint32_t>(n));
104104
}
105105

106106
template <typename T>

include/nbl/builtin/hlsl/limits.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ struct num_traits<float16_t> : num_base<float16_t>
215215
float16_t
216216
#endif
217217
;
218-
NBL_CONSTEXPR_STATIC_INLINE type min = 6.103515e-05F;
219-
NBL_CONSTEXPR_STATIC_INLINE type max = 65504.0F;
220-
NBL_CONSTEXPR_STATIC_INLINE type denorm_min = 5.96046448e-08F;
221-
NBL_CONSTEXPR_STATIC_INLINE uint16_t quiet_NaN = 0x7FFF;
222-
NBL_CONSTEXPR_STATIC_INLINE uint16_t signaling_NaN = 0x7DFF;
223-
NBL_CONSTEXPR_STATIC_INLINE uint16_t infinity = 0x7C00;
218+
NBL_CONSTEXPR_STATIC_INLINE type min = (type)6.103515e-05F;
219+
NBL_CONSTEXPR_STATIC_INLINE type max = (type)65504.0F;
220+
NBL_CONSTEXPR_STATIC_INLINE type denorm_min = (type)5.96046448e-08F;
221+
NBL_CONSTEXPR_STATIC_INLINE uint16_t quiet_NaN = (uint16_t)0x7FFF;
222+
NBL_CONSTEXPR_STATIC_INLINE uint16_t signaling_NaN = (uint16_t)0x7DFF;
223+
NBL_CONSTEXPR_STATIC_INLINE uint16_t infinity = (uint16_t)0x7C00;
224224
};
225225

226226
template<>

include/nbl/builtin/hlsl/math/functions.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ struct lp_norm<T,1,true NBL_PARTIAL_REQ_BOT(concepts::FloatingPointLikeVectorial
5151
array_get<T, scalar_type> getter;
5252

5353
scalar_type retval = abs<scalar_type>(getter(v, 0));
54-
for (int i = 1; i < vector_traits<T>::Dimension; i++)
54+
for (uint32_t i = 1; i < vector_traits<T>::Dimension; i++)
5555
retval += abs<scalar_type>(getter(v, i));
5656
return retval;
5757
}

include/nbl/builtin/hlsl/math/linalg/basic.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef __HLSL_VERSION
55
#include <nbl/core/math/glslFunctions.h>
66
#include "vectorSIMD.h"
7+
#include <nbl/builtin/hlsl/type_traits.hlsl>
78
#endif
89
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl>
910
#include <nbl/builtin/hlsl/matrix_utils/matrix_traits.hlsl>
@@ -140,7 +141,7 @@ namespace impl
140141
{
141142
To retval;
142143

143-
NBL_UNROLL for (int i = 0; i < N; ++i)
144+
NBL_UNROLL for (uint16_t i = 0; i < N; ++i)
144145
{
145146
retval[i] = hlsl::_static_cast<ScalarTo>(vec[i]);
146147
}

include/nbl/builtin/hlsl/numbers.hlsl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@ namespace numbers
1111
{
1212

1313
template <typename float_t>
14-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t e = float_t(2.718281828459045);
14+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t e = (float_t)2.718281828459045;
1515
template <typename float_t>
16-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t log2e = float_t(1.4426950408889634);
16+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t log2e = (float_t)1.4426950408889634;
1717
template <typename float_t>
18-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t log10e = float_t(0.4342944819032518);
18+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t log10e = (float_t)0.4342944819032518;
1919
template <typename float_t>
20-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t pi = float_t(3.141592653589793);
20+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t pi = (float_t)3.141592653589793;
2121
template <typename float_t>
22-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_pi = float_t(0.3183098861837907);
22+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_pi = (float_t)0.3183098861837907;
2323
template <typename float_t>
24-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_sqrtpi = float_t(0.5641895835477563);
24+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_sqrtpi = (float_t)0.5641895835477563;
2525
template <typename float_t>
26-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t ln2 = float_t(0.6931471805599453);
26+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t ln2 = (float_t)0.6931471805599453;
2727
template <typename float_t>
28-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_ln2 = float_t(1.44269504088896);
28+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_ln2 = (float_t)1.44269504088896;
2929
template <typename float_t>
30-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t ln10 = float_t(2.302585092994046);
30+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t ln10 = (float_t)2.302585092994046;
3131
template <typename float_t>
32-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t sqrt2 = float_t(1.4142135623730951);
32+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t sqrt2 = (float_t)1.4142135623730951;
3333
template <typename float_t>
34-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t sqrt3 = float_t(1.7320508075688772);
34+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t sqrt3 = (float_t)1.7320508075688772;
3535
template <typename float_t>
36-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_sqrt3 = float_t(0.5773502691896257);
36+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t inv_sqrt3 = (float_t)0.5773502691896257;
3737
template <typename float_t>
38-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t egamma = float_t(0.5772156649015329);
38+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t egamma = (float_t)0.5772156649015329;
3939
template <typename float_t>
40-
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t phi = float_t(1.618033988749895);
40+
NBL_CONSTEXPR_INLINE_NSPC_SCOPE_VAR float_t phi = (float_t)1.618033988749895;
4141

4242
}
4343
}

include/nbl/builtin/hlsl/rwmc/CascadeAccumulator.hlsl

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,45 @@ namespace hlsl
1212
namespace rwmc
1313
{
1414

15-
template<typename CascadeLayerType, uint32_t CascadeCountValue, typename SampleCountType = uint16_t NBL_PRIMARY_REQUIRES(concepts::Vector<CascadeLayerType> && concepts::UnsignedIntegralScalar<SampleCountType>)
15+
template<typename CascadeLayerType, uint16_t CascadeCount, typename SampleCountType = uint16_t NBL_PRIMARY_REQUIRES(concepts::Vector<CascadeLayerType> && concepts::UnsignedIntegralScalar<SampleCountType>)
1616
struct DefaultCascades
1717
{
18+
// required public interfaces (TODO: a concept for it)
1819
using layer_type = CascadeLayerType;
1920
using sample_count_type = SampleCountType;
20-
NBL_CONSTEXPR_STATIC_INLINE uint32_t CascadeCount = CascadeCountValue;
21+
using weight_t = typename SSplattingParameters::scalar_t;
2122

22-
sample_count_type cascadeSampleCounter[CascadeCount];
23-
CascadeLayerType data[CascadeCount];
23+
inline uint16_t getLastCascade() {return CascadeCount-uint16_t(1);}
2424

25-
void clear(uint32_t cascadeIx)
25+
void clear()
2626
{
27-
cascadeSampleCounter[cascadeIx] = sample_count_type(0u);
28-
data[cascadeIx] = promote<CascadeLayerType, float32_t>(0.0f);
27+
for (uint16_t i=0u; i<CascadeCount; ++i)
28+
{
29+
__cascadeSampleCounter[i] = sample_count_type(0u);
30+
__data[i] = promote<CascadeLayerType,float32_t>(0.0f);
31+
}
2932
}
3033

31-
void addSampleIntoCascadeEntry(layer_type _sample, uint16_t lowerCascadeIndex, SSplattingParameters::scalar_t lowerCascadeLevelWeight, SSplattingParameters::scalar_t higherCascadeLevelWeight, sample_count_type sampleCount)
34+
void addSampleIntoCascadeEntry(const layer_type _sample, const uint16_t lowerCascadeIndex, const weight_t lowerCascadeLevelWeight, const weight_t higherCascadeLevelWeight, const sample_count_type sampleCount)
3235
{
33-
const SSplattingParameters::scalar_t reciprocalSampleCount = SSplattingParameters::scalar_t(1.0f) / SSplattingParameters::scalar_t(sampleCount);
36+
const weight_t reciprocalSampleCount = _static_cast<weight_t>(1)/_static_cast<weight_t>(sampleCount);
3437

35-
sample_count_type lowerCascadeSampleCount = cascadeSampleCounter[lowerCascadeIndex];
36-
data[lowerCascadeIndex] += (_sample * lowerCascadeLevelWeight - (sampleCount - lowerCascadeSampleCount) * data[lowerCascadeIndex]) * reciprocalSampleCount;
37-
cascadeSampleCounter[lowerCascadeIndex] = sampleCount;
38+
sample_count_type lowerCascadeSampleCount = __cascadeSampleCounter[lowerCascadeIndex];
39+
__data[lowerCascadeIndex] += (_sample * lowerCascadeLevelWeight - (sampleCount - lowerCascadeSampleCount) * __data[lowerCascadeIndex]) * reciprocalSampleCount;
40+
__cascadeSampleCounter[lowerCascadeIndex] = sampleCount;
3841

3942
uint16_t higherCascadeIndex = lowerCascadeIndex + uint16_t(1u);
4043
if (higherCascadeIndex < CascadeCount)
4144
{
42-
sample_count_type higherCascadeSampleCount = cascadeSampleCounter[higherCascadeIndex];
43-
data[higherCascadeIndex] += (_sample * higherCascadeLevelWeight - (sampleCount - higherCascadeSampleCount) * data[higherCascadeIndex]) * reciprocalSampleCount;
44-
cascadeSampleCounter[higherCascadeIndex] = sampleCount;
45+
sample_count_type higherCascadeSampleCount = __cascadeSampleCounter[higherCascadeIndex];
46+
__data[higherCascadeIndex] += (_sample * higherCascadeLevelWeight - (sampleCount - higherCascadeSampleCount) * __data[higherCascadeIndex]) * reciprocalSampleCount;
47+
__cascadeSampleCounter[higherCascadeIndex] = sampleCount;
4548
}
4649
}
50+
51+
// private
52+
sample_count_type __cascadeSampleCounter[CascadeCount];
53+
CascadeLayerType __data[CascadeCount];
4754
};
4855

4956
template<typename CascadesType>
@@ -52,19 +59,18 @@ struct CascadeAccumulator
5259
using scalar_t = typename SSplattingParameters::scalar_t;
5360
using input_sample_type = typename CascadesType::layer_type;
5461
using sample_count_type = typename CascadesType::sample_count_type;
62+
using weight_t = typename CascadesType::weight_t;
5563
using this_t = CascadeAccumulator<CascadesType>;
5664
using cascades_type = CascadesType;
57-
NBL_CONSTEXPR_STATIC_INLINE uint16_t CascadeCount = cascades_type::CascadeCount;
58-
NBL_CONSTEXPR_STATIC_INLINE scalar_t LastCascade = scalar_t(CascadeCount - 1u);
65+
5966
cascades_type accumulation;
60-
6167
SSplattingParameters splattingParameters;
6268

63-
static this_t create(NBL_CONST_REF_ARG(SPackedSplattingParameters) settings)
69+
static this_t create(NBL_CONST_REF_ARG(SPackedSplattingParameters) settings, const bool clear=true)
6470
{
6571
this_t retval;
66-
for (uint16_t i = 0u; i < CascadeCount; ++i)
67-
retval.accumulation.clear(i);
72+
if (clear)
73+
retval.accumulation.clear();
6874
retval.splattingParameters = settings.unpack();
6975

7076
return retval;
@@ -73,25 +79,27 @@ struct CascadeAccumulator
7379
// most of this code is stolen from https://cg.ivd.kit.edu/publications/2018/rwmc/tool/split.cpp
7480
void addSample(const sample_count_type sampleCount, input_sample_type _sample)
7581
{
76-
const scalar_t luma = splattingParameters.calcLuma<input_sample_type>(_sample);
77-
const scalar_t log2Luma = log2<scalar_t>(luma);
82+
const uint16_t lastCascade = accumulation.getLastCascade();
83+
84+
const weight_t luma = splattingParameters.calcLuma<input_sample_type>(_sample);
85+
const weight_t log2Luma = hlsl::log2<weight_t>(luma);
7886
const scalar_t cascade = log2Luma * splattingParameters.RcpLog2Base - splattingParameters.Log2BaseRootOfStart;
79-
const scalar_t clampedCascade = clamp(cascade, scalar_t(0), LastCascade);
80-
const scalar_t clampedCascadeFloor = floor<scalar_t>(clampedCascade);
87+
const scalar_t clampedCascade = hlsl::clamp<scalar_t>(cascade, scalar_t(0), lastCascade);
88+
const scalar_t clampedCascadeFloor = hlsl::floor(clampedCascade);
8189
// c<=0 -> 0, c>=Count-1 -> Count-1
82-
uint16_t lowerCascadeIndex = uint16_t(clampedCascadeFloor);
90+
const uint16_t lowerCascadeIndex = _static_cast<uint16_t>(clampedCascadeFloor);
8391
// 0 whenever clamped or `cascade` is integer (when `clampedCascade` is integer)
84-
scalar_t higherCascadeWeight = clampedCascade - clampedCascadeFloor;
92+
const weight_t higherCascadeWeight = _static_cast<weight_t>(clampedCascade - clampedCascadeFloor);
8593
// never 0 thanks to magic of `1-fract(x)`
86-
scalar_t lowerCascadeWeight = scalar_t(1) - higherCascadeWeight;
94+
weight_t lowerCascadeWeight = weight_t(1) - higherCascadeWeight;
8795

8896
// handle super bright sample case
89-
if (cascade > LastCascade)
90-
lowerCascadeWeight = exp2(splattingParameters.BrightSampleLumaBias - log2Luma);
97+
if (cascade > lastCascade)
98+
lowerCascadeWeight = hlsl::exp2(_static_cast<weight_t>(splattingParameters.BrightSampleLumaBias - log2Luma));
9199

92100
accumulation.addSampleIntoCascadeEntry(_sample, lowerCascadeIndex, lowerCascadeWeight, higherCascadeWeight, sampleCount);
93101
}
94-
102+
95103

96104
};
97105

include/nbl/builtin/hlsl/rwmc/SplattingParameters.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace hlsl
1212
namespace rwmc
1313
{
1414

15+
// TODO: template both on the ScalarType
1516
struct SSplattingParameters
1617
{
1718
using scalar_t = float32_t;
@@ -20,9 +21,9 @@ struct SSplattingParameters
2021
scalar_t BrightSampleLumaBias;
2122

2223
template<typename CascadeLayerType, typename Colorspace = colorspace::scRGB>
23-
scalar_t calcLuma(NBL_CONST_REF_ARG(CascadeLayerType) col)
24+
typename vector_traits<CascadeLayerType>::scalar_type calcLuma(NBL_CONST_REF_ARG(CascadeLayerType) col)
2425
{
25-
return hlsl::dot<CascadeLayerType>(hlsl::transpose(Colorspace::ToXYZ())[1], col);
26+
return hlsl::dot(_static_cast<CascadeLayerType>(hlsl::transpose(Colorspace::ToXYZ())[1]), col);
2627
}
2728
};
2829

include/nbl/builtin/hlsl/tgmath/impl.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ struct erf_helper<float16_t>
393393
static float16_t __call(float16_t _x)
394394
{
395395
// A&S approximation to 2.5x10-5
396-
const float16_t a1 = float16_t(0.3480242f);
397-
const float16_t a2 = float16_t(-0.0958798f);
398-
const float16_t a3 = float16_t(0.7478556f);
399-
const float16_t p = float16_t(0.47047f);
396+
const float16_t a1 = _static_cast<float16_t>(0.3480242f);
397+
const float16_t a2 = _static_cast<float16_t>(-0.0958798f);
398+
const float16_t a3 = _static_cast<float16_t>(0.7478556f);
399+
const float16_t p = _static_cast<float16_t>(0.47047f);
400400

401401
float16_t _sign = float16_t(sign<float16_t>(_x));
402402
float16_t x = abs_helper<float16_t>::__call(_x);

0 commit comments

Comments
 (0)