Skip to content

Commit c7cbfb9

Browse files
committed
Fixed algorithm.hlsl
1 parent 23f1cfe commit c7cbfb9

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

include/nbl/builtin/hlsl/algorithm.hlsl

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _NBL_BUILTIN_HLSL_ALGORITHM_INCLUDED_
66

77
#include "nbl/builtin/hlsl/functional.hlsl"
8+
#include "nbl/builtin/hlsl/math/intutil.hlsl"
89

910
namespace nbl
1011
{
@@ -91,16 +92,10 @@ NBL_CONSTEXPR_INLINE_FUNC void swap(NBL_REF_ARG(T) lhs, NBL_REF_ARG(T) rhs)
9192
namespace impl
9293
{
9394

94-
// TODO: move this to some other header
95-
bool isNPoT(const uint x)
96-
{
97-
return x&(x-1);
98-
}
99-
10095
template<class Accessor, class Comparator>
10196
struct bound_t
10297
{
103-
static bound_t<Accessor,Comparator> setup(uint begin, const uint end, const typename Accessor::value_type _value, const Comparator _comp)
98+
static bound_t<Accessor,Comparator> setup(uint32_t begin, const uint32_t end, const typename Accessor::value_type _value, const Comparator _comp)
10499
{
105100
bound_t<Accessor,Comparator> retval;
106101
retval.comp = _comp;
@@ -111,12 +106,12 @@ struct bound_t
111106
}
112107

113108

114-
uint operator()(NBL_REF_ARG(Accessor) accessor)
109+
uint32_t operator()(NBL_REF_ARG(Accessor) accessor)
115110
{
116111
if (isNPoT(len))
117112
{
118-
const uint newLen = 0x1u<<firstbithigh(len);
119-
const uint testPoint = it+(len-newLen);
113+
const uint32_t newLen = 0x1u<<nbl::hlsl::findMSB(len);
114+
const uint32_t testPoint = it+(len-newLen);
120115
len = newLen;
121116
comp_step(accessor,testPoint);
122117
}
@@ -133,24 +128,24 @@ struct bound_t
133128
void iteration(NBL_REF_ARG(Accessor) accessor)
134129
{
135130
len >>= 1;
136-
const uint mid = it+len;
131+
const uint32_t mid = it+len;
137132
comp_step(accessor,mid);
138133
}
139134

140-
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint testPoint, const uint rightBegin)
135+
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint32_t testPoint, const uint32_t rightBegin)
141136
{
142137
if (comp(accessor[testPoint],value))
143138
it = rightBegin;
144139
}
145-
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint testPoint)
140+
void comp_step(NBL_REF_ARG(Accessor) accessor, const uint32_t testPoint)
146141
{
147142
comp_step(accessor,testPoint,testPoint);
148143
}
149144

150145
Comparator comp;
151146
typename Accessor::value_type value;
152-
uint it;
153-
uint len;
147+
uint32_t it;
148+
uint32_t len;
154149
};
155150

156151
template<class Accessor, class Comparator>
@@ -168,14 +163,14 @@ struct lower_to_upper_comparator_transform_t
168163

169164

170165
template<class Accessor, class Comparator>
171-
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
166+
uint32_t lower_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const typename Accessor::value_type value, const Comparator comp)
172167
{
173168
impl::bound_t<Accessor,Comparator> implementation = impl::bound_t<Accessor,Comparator>::setup(begin,end,value,comp);
174169
return implementation(accessor);
175170
}
176171

177172
template<class Accessor, class Comparator>
178-
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value, const Comparator comp)
173+
uint32_t upper_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const typename Accessor::value_type value, const Comparator comp)
179174
{
180175
//using TransformedComparator = impl::lower_to_upper_comparator_transform_t<Accessor,Comparator>;
181176
//TransformedComparator transformedComparator;
@@ -191,7 +186,7 @@ namespace impl
191186

192187
// extra indirection due to https://github.com/microsoft/DirectXShaderCompiler/issues/4771
193188
template<class Accessor, typename T>
194-
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const T value)
189+
uint32_t lower_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const T value)
195190
{
196191
//using Comparator = nbl::hlsl::less<T>;
197192
//Comparator comp;
@@ -200,7 +195,7 @@ uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint en
200195
return nbl::hlsl::lower_bound<Accessor, nbl::hlsl::less<T> >(accessor,begin,end,value,comp);
201196
}
202197
template<class Accessor, typename T>
203-
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const T value)
198+
uint32_t upper_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const T value)
204199
{
205200
//using Comparator = nbl::hlsl::less<T>;
206201
//Comparator comp;
@@ -212,12 +207,12 @@ uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint en
212207
}
213208

214209
template<class Accessor>
215-
uint lower_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value)
210+
uint32_t lower_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const typename Accessor::value_type value)
216211
{
217212
return impl::lower_bound<Accessor,typename Accessor::value_type>(accessor,begin,end,value);
218213
}
219214
template<class Accessor>
220-
uint upper_bound(NBL_REF_ARG(Accessor) accessor, const uint begin, const uint end, const typename Accessor::value_type value)
215+
uint32_t upper_bound(NBL_REF_ARG(Accessor) accessor, const uint32_t begin, const uint32_t end, const typename Accessor::value_type value)
221216
{
222217
return impl::upper_bound<Accessor,typename Accessor::value_type>(accessor,begin,end,value);
223218
}

0 commit comments

Comments
 (0)