Skip to content

Commit 568a4a1

Browse files
authored
Adds bitfieldReverse to glsl_compat.hlsl via its spirv op. Some QOL changes to type_traits.hlsl
1 parent ea5af44 commit 568a4a1

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
208208
return impl::bitfieldExtract<T, is_signed<T>::value, is_integral<T>::value>::__call(val,offsetBits,numBits);
209209
}
210210

211-
212211
namespace impl
213212
{
214213

215214
template<typename T>
216215
struct bitfieldInsert
217216
{
218-
static enable_if_t<is_integral_v<T>, T> __call( T base, T insert, uint32_t offset, uint32_t count )
217+
static T __call( T base, T insert, uint32_t offset, uint32_t count )
219218
{
220219
return spirv::bitFieldInsert<T>( base, insert, offset, count );
221220
}
@@ -224,9 +223,29 @@ struct bitfieldInsert
224223
} //namespace impl
225224

226225
template<typename T>
227-
T bitfieldInsert( T base, T insert, uint32_t offset, uint32_t count )
226+
T bitfieldInsert( T base, T insert, uint32_t offset, uint32_t bits )
227+
{
228+
return impl::bitfieldInsert<T>::__call(base, insert, offset, bits);
229+
}
230+
231+
namespace impl
232+
{
233+
234+
template<typename T>
235+
struct bitfieldReverse
236+
{
237+
static T __call( T base )
238+
{
239+
return spirv::bitFieldReverse<T>( base );
240+
}
241+
};
242+
243+
} //namespace impl
244+
245+
template<typename T>
246+
T bitfieldReverse( T value )
228247
{
229-
return impl::bitfieldInsert<T>::__call(base, insert, offset, count);
248+
return impl::bitfieldReverse<T>::__call(value);
230249
}
231250

232251
#endif

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ enable_if_t<is_signed_v<Signed>, Signed> bitFieldSExtract( Signed val, uint32_t
234234

235235
template<typename Integral>
236236
[[vk::ext_instruction( spv::OpBitFieldInsert )]]
237-
Integral bitFieldInsert( Integral base, Integral insert, uint32_t offset, uint32_t count );
237+
enable_if_t<is_integral_v<Integral>, Integral> bitFieldInsert( Integral base, Integral insert, uint32_t offset, uint32_t count );
238+
239+
template<typename Integral>
240+
[[vk::ext_instruction( spv::OpBitReverse )]]
241+
enable_if_t<is_integral_v<Integral>, Integral> bitFieldReverse( Integral base );
238242

239243
}
240244

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ template<class T>
306306
NBL_CONSTEXPR_STATIC_INLINE bool is_unsigned_v = is_unsigned<T>::value;
307307

308308
template<class T>
309-
struct is_integral : impl::base_type_forwarder<impl::is_integral, T> {};
309+
struct is_integral : impl::base_type_forwarder<impl::is_integral, typename remove_cv<T>::type> {};
310+
template<class T>
311+
NBL_CONSTEXPR_STATIC_INLINE bool is_integral_v = is_integral<T>::value;
310312

311313
template<class T>
312314
struct is_floating_point : impl::base_type_forwarder<impl::is_floating_point, typename remove_cv<T>::type> {};
@@ -321,6 +323,8 @@ struct is_scalar : bool_constant<
321323
impl::is_integral<typename remove_cv<T>::type>::value ||
322324
impl::is_floating_point<typename remove_cv<T>::type>::value
323325
> {};
326+
template<class T>
327+
NBL_CONSTEXPR_STATIC_INLINE bool is_scalar_v = is_scalar<T>::value;
324328

325329
template<class T>
326330
struct is_const : bool_constant<false> {};
@@ -395,12 +399,6 @@ struct enable_if<true, T> : type_identity<T> {};
395399
template<bool B, class T = void>
396400
using enable_if_t = typename enable_if<B, T>::type;
397401

398-
template<class T>
399-
NBL_CONSTEXPR_STATIC_INLINE bool is_integral_v = is_integral<T>::value;
400-
401-
template<class T>
402-
NBL_CONSTEXPR_STATIC_INLINE bool is_scalar_v = is_scalar<T>::value;
403-
404402
template<class T>
405403
struct alignment_of;
406404
template<class T>

0 commit comments

Comments
 (0)