Skip to content

Commit 2125787

Browse files
committed
Template specialization
1 parent 7085798 commit 2125787

File tree

2 files changed

+44
-53
lines changed

2 files changed

+44
-53
lines changed

include/nbl/builtin/hlsl/glsl_compat/bit.hlsl

Lines changed: 0 additions & 46 deletions
This file was deleted.

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
88
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
9-
#include "nbl/builtin/hlsl/glsl_compat/bit.hlsl"
109

1110
namespace nbl
1211
{
@@ -57,12 +56,6 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
5756
return spirv::atomicCompSwap<T>(ptr, spv::ScopeDevice, spv::DecorationRelaxedPrecision, spv::DecorationRelaxedPrecision, value, comparator);
5857
}
5958

60-
template<typename T>
61-
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
62-
{
63-
return impl::bitfieldExtract<T, is_signed<T>::value, is_integral<T>::value>( val, offsetBits, numBits );
64-
}
65-
6659
/**
6760
* For Compute Shaders
6861
*/
@@ -90,6 +83,50 @@ void tess_ctrl_barrier() {
9083
void memoryBarrierShared() {
9184
spirv::memoryBarrier(spv::ScopeDevice, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsWorkgroupMemoryMask);
9285
}
86+
87+
88+
namespace impl
89+
{
90+
91+
template<typename T, bool isSigned, bool isIntegral>
92+
struct bitfieldExtract {};
93+
94+
template<typename T, bool isSigned>
95+
struct bitfieldExtract<T, isSigned, false>
96+
{
97+
T operator()( T val, uint32_t offsetBits, uint32_t numBits )
98+
{
99+
static_assert(is_integral<T>::value, "T is not an integral type!" )
100+
return val;
101+
}
102+
};
103+
104+
template<typename T>
105+
struct bitfieldExtract<T, true, true>
106+
{
107+
T operator()( T val, uint32_t offsetBits, uint32_t numBits )
108+
{
109+
return spirv::bitFieldSExtract<T>( val, offsetBits, numBits );
110+
}
111+
};
112+
113+
template<typename T>
114+
struct bitfieldExtract<T, false, true>
115+
{
116+
T operator()( T val, uint32_t offsetBits, uint32_t numBits )
117+
{
118+
return spirv::bitFieldUExtract<T>( val, offsetBits, numBits );
119+
}
120+
};
121+
122+
}
123+
124+
template<typename T>
125+
T bitfieldExtract( T val, uint32_t offsetBits, uint32_t numBits )
126+
{
127+
return impl::bitfieldExtract<T, is_signed<T>::value, is_integral<T>::value>( val, offsetBits, numBits );
128+
}
129+
93130
#endif
94131

95132
}

0 commit comments

Comments
 (0)