Skip to content

Commit b6e0955

Browse files
committed
Conform to glsl
1 parent 69c7778 commit b6e0955

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
6+
#include <nbl/builtin/hlsl/type_traits.hlsl>
67

78

89
#ifndef __HLSL_VERSION
@@ -23,12 +24,6 @@ NBL_ALIAS_TEMPLATE_FUNCTION(std::rotl, rotl);
2324
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotr, rotr);
2425
NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
2526

26-
template<typename Unsigned>
27-
Unsigned bitfield_extract_unsigned( Unsigned val, uint32_t offsetBits, uint32_t numBits )
28-
{
29-
return ( val >> offsetBits ) & ( ( 1 << numBits ) - 1 );
30-
}
31-
3227
}
3328
#else
3429

@@ -108,13 +103,6 @@ uint16_t countl_zero(T n)
108103
return impl::clz<sizeof(T)*8>(n);
109104
}
110105

111-
// TODO: templated "switch" depending on signedness
112-
template<typename Unsigned>
113-
Unsigned bitfield_extract_unsigned( Unsigned val, uint32_t offsetBits, uint32_t numBits )
114-
{
115-
return spirv::bitfieldExtractUnsigned<Unsigned>( val, offsetBits, numBits );
116-
}
117-
118106
}
119107
}
120108
#endif

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
5656
return spirv::atomicCompSwap<T>(ptr, spv::ScopeDevice, spv::DecorationRelaxedPrecision, spv::DecorationRelaxedPrecision, value, comparator);
5757
}
5858

59+
template<typename T>
60+
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
61+
{
62+
static_assert( is_integral<T>::value );
63+
if( is_unsigned<T>::value )
64+
{
65+
return spirv::bitFieldUExtract<T>( val, offsetBits, numBits );
66+
}
67+
//if( is_signed<T>::value )
68+
return spirv::bitFieldSExtract<T>( val, offsetBits, numBits );
69+
}
70+
5971
/**
6072
* For Compute Shaders
6173
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ T bitcast(U);
132132

133133
template<typename Unsigned>
134134
[[vk::ext_instruction( spv::OpBitFieldUExtract )]]
135-
Unsigned bitfieldExtractUnsigned( Unsigned val, uint32_t offsetBits, uint32_t numBits );
135+
Unsigned bitFieldUExtract( Unsigned val, uint32_t offsetBits, uint32_t numBits );
136136

137137
template<typename Signed>
138138
[[vk::ext_instruction( spv::OpBitFieldSExtract )]]
139-
Signed bitfieldExtractSigned( Signed val, uint32_t offsetBits, uint32_t numBits );
139+
Signed bitFieldSExtract( Signed val, uint32_t offsetBits, uint32_t numBits );
140140

141141
}
142142
#endif

0 commit comments

Comments
 (0)