Skip to content

Commit 4fdfb15

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla into ies
# Conflicts: # examples_tests
2 parents 925023e + 8a5e648 commit 4fdfb15

5 files changed

Lines changed: 366 additions & 213 deletions

File tree

include/nbl/builtin/hlsl/glsl_compat/core.hlsl

Lines changed: 83 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,33 @@ namespace glsl
2222
#ifndef __HLSL_VERSION
2323

2424
// GLM Aliases
25-
template<typename genIUType>
26-
genIUType bitfieldExtract(genIUType Value, int Offset, int Bits)
25+
namespace impl
2726
{
28-
return glm::bitfieldExtract<genIUType>(Value, Offset, Bits);
29-
}
27+
template<typename T NBL_STRUCT_CONSTRAINABLE>
28+
struct bitfieldInsert;
3029

31-
template<typename genIUType>
32-
genIUType bitfieldInsert(genIUType const& Base, genIUType const& Insert, int Offset, int Bits)
30+
template<typename T>
31+
NBL_PARTIAL_REQ_TOP(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4)
32+
struct bitfieldInsert<T NBL_PARTIAL_REQ_BOT(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4) >
33+
{
34+
static T __call( T base, T insert, uint32_t offset, uint32_t bits )
35+
{
36+
return glm::bitfieldInsert<T>(base, insert, offset, bits);
37+
}
38+
};
39+
40+
template<typename T NBL_STRUCT_CONSTRAINABLE>
41+
struct bitfieldExtract;
42+
43+
template<typename T>
44+
NBL_PARTIAL_REQ_TOP(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4)
45+
struct bitfieldExtract<T NBL_PARTIAL_REQ_BOT(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4) >
3346
{
34-
return glm::bitfieldInsert<genIUType>(Base, Insert, Offset, Bits);
47+
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
48+
{
49+
return glm::bitfieldExtract<T>(val, offsetBits, numBits);
50+
}
51+
};
3552
}
3653

3754
template<typename genIUType>
@@ -184,21 +201,25 @@ void memoryBarrierShared() {
184201
namespace impl
185202
{
186203

187-
template<typename T, bool isSigned, bool isIntegral>
188-
struct bitfieldExtract {};
204+
template<typename T NBL_STRUCT_CONSTRAINABLE>
205+
struct bitfieldInsert;
189206

190-
template<typename T, bool isSigned>
191-
struct bitfieldExtract<T, isSigned, false>
207+
template<typename T>
208+
NBL_PARTIAL_REQ_TOP(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4)
209+
struct bitfieldInsert<T NBL_PARTIAL_REQ_BOT(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4) >
192210
{
193-
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
211+
static T __call( T base, T insert, uint32_t offset, uint32_t bits )
194212
{
195-
static_assert( is_integral<T>::value, "T is not an integral type!" );
196-
return val;
213+
return spirv::bitFieldInsert<T>(base, insert, offset, bits);
197214
}
198215
};
199216

217+
template<typename T NBL_STRUCT_CONSTRAINABLE>
218+
struct bitfieldExtract;
219+
200220
template<typename T>
201-
struct bitfieldExtract<T, true, true>
221+
NBL_PARTIAL_REQ_TOP(concepts::SignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4)
222+
struct bitfieldExtract<T NBL_PARTIAL_REQ_BOT(concepts::SignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4) >
202223
{
203224
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
204225
{
@@ -207,7 +228,8 @@ struct bitfieldExtract<T, true, true>
207228
};
208229

209230
template<typename T>
210-
struct bitfieldExtract<T, false, true>
231+
NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4)
232+
struct bitfieldExtract<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> >= 4) >
211233
{
212234
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
213235
{
@@ -218,25 +240,63 @@ struct bitfieldExtract<T, false, true>
218240
} //namespace impl
219241

220242
template<typename T>
221-
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
243+
T bitfieldReverse(T value)
244+
{
245+
return spirv::bitReverse<T>(value);
246+
}
247+
248+
#endif
249+
250+
namespace impl
251+
{
252+
template<typename T>
253+
NBL_PARTIAL_REQ_TOP(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2)
254+
struct bitfieldInsert<T NBL_PARTIAL_REQ_BOT(concepts::Integral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2) >
255+
{
256+
static T __call( T base, T insert, uint32_t offset, uint32_t bits )
257+
{
258+
const T mask = (T(1u) << bits) - T(1u);
259+
const T shifted_mask = mask << offset;
260+
return (base & ~shifted_mask) | ((insert & mask) << T(offset));
261+
}
262+
};
263+
264+
template<typename T>
265+
NBL_PARTIAL_REQ_TOP(concepts::SignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2)
266+
struct bitfieldExtract<T NBL_PARTIAL_REQ_BOT(concepts::SignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2) >
267+
{
268+
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
269+
{
270+
const T ret = (val >> T(offsetBits)) & T((T(1u) << numBits) - T(1u));
271+
if (ret & (T(1u) << (numBits-1u)))
272+
ret |= T(~0ull) << numBits;
273+
return ret;
274+
}
275+
};
276+
277+
template<typename T>
278+
NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2)
279+
struct bitfieldExtract<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegral<typename vector_traits<T>::scalar_type> && size_of_v<typename vector_traits<T>::scalar_type> == 2) >
222280
{
223-
return impl::bitfieldExtract<T, is_signed<T>::value, is_integral<T>::value>::__call(val,offsetBits,numBits);
281+
static T __call( T val, uint32_t offsetBits, uint32_t numBits )
282+
{
283+
return (val >> T(offsetBits)) & T((T(1u) << numBits) - T(1u));
284+
}
285+
};
224286
}
225287

226288
template<typename T>
227289
T bitfieldInsert(T base, T insert, uint32_t offset, uint32_t bits)
228290
{
229-
return spirv::bitFieldInsert<T>(base, insert, offset, bits);
291+
return impl::bitfieldInsert<T>::__call(base, insert, offset, bits);
230292
}
231293

232294
template<typename T>
233-
T bitfieldReverse(T value)
295+
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
234296
{
235-
return spirv::bitReverse<T>(value);
297+
return impl::bitfieldExtract<T>::__call(val, offsetBits, numBits);
236298
}
237299

238-
#endif
239-
240300
namespace impl
241301
{
242302
template<typename T NBL_STRUCT_CONSTRAINABLE>

include/nbl/builtin/hlsl/math/quaternions.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ struct quaternion
110110
uniformScaleSq = traits.uniformScaleSq;
111111

112112
if (dontAssertValidMatrix)
113+
{
113114
if (!valid)
114115
{
115116
this_t retval;
116117
retval.data = hlsl::promote<data_type>(bit_cast<scalar_type>(numeric_limits<scalar_type>::quiet_NaN));
117118
return retval;
118119
}
120+
}
119121
else
120-
{
121122
assert(valid);
122-
}
123123
}
124124
if (uniformScaleSq < numeric_limits<scalar_type>::min)
125125
{

include/nbl/builtin/hlsl/matrix_utils/transformation_matrix_utils.hlsl

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,13 @@ template<typename T, uint32_t N>
129129
inline void setRotation(matrix<T, N, 4>& outMat, NBL_CONST_REF_ARG(math::quaternion<T>) quat)
130130
{
131131
static_assert(N == 3 || N == 4);
132+
matrix<T, 3, 3> mat = _static_cast<matrix<T, 3, 3>>(quat);
132133

133-
outMat[0] = vector<T, 4>(
134-
1 - 2 * (quat.y * quat.y + quat.z * quat.z),
135-
2 * (quat.x * quat.y - quat.z * quat.w),
136-
2 * (quat.x * quat.z + quat.y * quat.w),
137-
outMat[0][3]
138-
);
139-
140-
outMat[1] = vector<T, 4>(
141-
2 * (quat.x * quat.y + quat.z * quat.w),
142-
1 - 2 * (quat.x * quat.x + quat.z * quat.z),
143-
2 * (quat.y * quat.z - quat.x * quat.w),
144-
outMat[1][3]
145-
);
146-
147-
outMat[2] = vector<T, 4>(
148-
2 * (quat.x * quat.z - quat.y * quat.w),
149-
2 * (quat.y * quat.z + quat.x * quat.w),
150-
1 - 2 * (quat.x * quat.x + quat.y * quat.y),
151-
outMat[2][3]
152-
);
134+
outMat[0] = mat[0];
135+
136+
outMat[1] = mat[1];
137+
138+
outMat[2] = mat[2];
153139
}
154140

155141
template<typename T, uint32_t N>

0 commit comments

Comments
 (0)