Skip to content

Commit 56354d0

Browse files
Merge pull request #568 from Devsh-Graphics-Programming/new_hlsl_mpl
New hlsl mpl
2 parents 1abaf59 + 6ce5d42 commit 56354d0

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

include/nbl/builtin/hlsl/mpl.hlsl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ struct countl_zero
4141
{
4242
NBL_CONSTEXPR_STATIC_INLINE bool CHOOSE_HIGH = N&(countl_zero_masks<bits_log2>::LO_MASK<<countl_zero_masks<bits_log2>::SHIFT);
4343
NBL_CONSTEXPR_STATIC_INLINE uint64_t NEXT_N = (CHOOSE_HIGH ? (N>>countl_zero_masks<bits_log2>::SHIFT):N)&countl_zero_masks<bits_log2>::LO_MASK;
44-
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional<bits_log2,countl_zero<NEXT_N,bits_log2-1>,type_traits::integral_constant<uint16_t,0> >::type::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
44+
//NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional_value<bits_log2,uint16_t,countl_zero<NEXT_N,bits_log2-1>::value,0>::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
45+
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional<bits_log2,countl_zero<NEXT_N,bits_log2-1>,type_traits::integral_constant<uint16_t,0> >::type::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
4546
};
4647

4748
}
@@ -64,6 +65,22 @@ struct log2
6465
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = X ? (1ull<<6)-countl_zero<X>::value-1 : -1ull;
6566
};
6667

68+
template<typename T, T X, int32_t S>
69+
struct rotl
70+
{
71+
static const uint32_t N = 32u;
72+
static const int32_t r = S % N;
73+
static const T value = (S >= 0) ? ((X << r) | (X >> (N - r))) : (X >> (-r)) | (X << (N - (-r)));
74+
};
75+
76+
template<typename T, T X, int32_t S>
77+
struct rotr
78+
{
79+
static const uint32_t N = 32u;
80+
static const int32_t r = S % N;
81+
static const T value = (S >= 0) ? ((X >> r) | (X << (N - r))) : (X << (-r)) | (X >> (N - (-r)));
82+
};
83+
6784
}
6885
}
6986
}

include/nbl/builtin/hlsl/random/xoroshiro.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define _NBL_BUILTIN_GLSL_RANDOM_XOROSHIRO_HLSL_INCLUDED_
88

99
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
10+
1011
#include <nbl/builtin/hlsl/bit.hlsl>
1112

1213
namespace nbl

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,30 @@ struct integral_constant {
159159
using value_type = T;
160160
};
161161

162-
template <bool val>
162+
template<bool val>
163163
struct bool_constant : integral_constant<bool, val> {};
164164

165165
struct true_type : bool_constant<true> {};
166166
struct false_type : bool_constant<true> {};
167167

168-
template <bool C, class T, class F>
168+
template<bool C, class T, class F>
169169
struct conditional
170170
{
171171
using type = T;
172172
};
173173

174-
template <class T, class F>
174+
template<class T, class F>
175175
struct conditional<false, T, F>
176176
{
177177
using type = F;
178178
};
179179

180+
template<bool C, typename T, T A, T B>
181+
struct conditional_value
182+
{
183+
NBL_CONSTEXPR_STATIC_INLINE T value = C ? A : B;
184+
};
185+
180186
template<class A, class B>
181187
struct is_same : bool_constant<false> {};
182188

0 commit comments

Comments
 (0)