@@ -130,23 +130,39 @@ bool partitionRandVariable(float leftProb, NBL_REF_ARG(float) xi, NBL_REF_ARG(fl
130
130
}
131
131
132
132
133
+ namespace impl
134
+ {
133
135
// TODO: impl signed integer versions
134
136
// @ return abs(x) if cond==true, max(x,0.0) otherwise
135
- template <typename T NBL_FUNC_REQUIRES (is_floating_point_v<T> || concepts::FloatingPointVector<T> || concepts::FloatingPointVectorial<T>)
136
- T conditionalAbsOrMax (bool cond, T x, T limit);
137
+ template<typename T NBL_PRIMARY_REQUIRES (is_floating_point_v<T> || concepts::FloatingPointVector<T> || concepts::FloatingPointVectorial<T>)
138
+ struct ConditionalAbsOrMax;
139
+
140
+ template<>
141
+ struct ConditionalAbsOrMax<float >
142
+ {
143
+ static float absOrMax (bool cond, float x, float limit)
144
+ {
145
+ const float condAbs = nbl::hlsl::bit_cast<float32_t, uint32_t>(nbl::hlsl::bit_cast<uint32_t, float32_t>(x) & uint32_t (cond ? 0x7fFFffFFu : 0xffFFffFFu));
146
+ return nbl::hlsl::max <float >(condAbs,limit);
147
+ }
148
+ };
137
149
138
- template < >
139
- float conditionalAbsOrMax< float >( bool cond, float x, float limit)
150
+ template<uint32_t N >
151
+ struct ConditionalAbsOrMax< vector < float , N> >
140
152
{
141
- const float condAbs = nbl::hlsl::bit_cast<float32_t, uint32_t>(nbl::hlsl::bit_cast<uint32_t, float32_t>(x) & uint (cond ? 0x7fFFffFFu : 0xffFFffFFu));
142
- return nbl::hlsl::max <float >(condAbs,limit);
153
+ static vector <float , N> absOrMax (bool cond, NBL_CONST_REF_ARG (vector <float , N>) x, NBL_CONST_REF_ARG (vector <float , N>) limit)
154
+ {
155
+ const vector <float , N> condAbs = nbl::hlsl::bit_cast<vector <float , N>, vector <uint32_t, N> >(nbl::hlsl::bit_cast<vector <uint32_t, N>, vector <float , N> >(x) & nbl::hlsl::mix ((vector <uint32_t, N>)0x7fFFffFFu, (vector <uint32_t, N>)0xffFFffFFu, promote<vector <bool , N>, bool >(cond)));
156
+ return nbl::hlsl::max <vector <float , N> >(condAbs,limit);
157
+ }
158
+ };
159
+
143
160
}
144
161
145
- template <uint16_t N >
146
- vector < float , N> conditionalAbsOrMax< vector < float , N> > (bool cond, NBL_CONST_REF_ARG (vector < float , N> ) x, NBL_CONST_REF_ARG (vector < float , N> ) limit)
162
+ template<typename T >
163
+ T conditionalAbsOrMax (bool cond, NBL_CONST_REF_ARG (T ) x, NBL_CONST_REF_ARG (T ) limit)
147
164
{
148
- const vector <float , N> condAbs = nbl::hlsl::bit_cast<vector <float , N>, vector <uint , N> >(nbl::hlsl::bit_cast<vector <uint , N>, vector <float , N> >(x) & nbl::hlsl::mix ((vector <uint , N>)0x7fFFffFFu, (vector <uint , N>)0xffFFffFFu, promote<vector <bool , N>, bool >(cond)));
149
- return nbl::hlsl::max <vector <float , N> >(condAbs,limit);
165
+ return impl::ConditionalAbsOrMax<T>::absOrMax (cond, x, limit);
150
166
}
151
167
152
168
0 commit comments