|
6 | 6 |
|
7 | 7 | #include "nbl/builtin/hlsl/cpp_compat.hlsl"
|
8 | 8 | #include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
|
9 |
| -#include "nbl/builtin/hlsl/glsl_compat/bit.hlsl" |
10 | 9 |
|
11 | 10 | namespace nbl
|
12 | 11 | {
|
@@ -57,12 +56,6 @@ T atomicCompSwap(NBL_REF_ARG(T) ptr, T comparator, T value)
|
57 | 56 | return spirv::atomicCompSwap<T>(ptr, spv::ScopeDevice, spv::DecorationRelaxedPrecision, spv::DecorationRelaxedPrecision, value, comparator);
|
58 | 57 | }
|
59 | 58 |
|
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 |
| - |
66 | 59 | /**
|
67 | 60 | * For Compute Shaders
|
68 | 61 | */
|
@@ -90,6 +83,50 @@ void tess_ctrl_barrier() {
|
90 | 83 | void memoryBarrierShared() {
|
91 | 84 | spirv::memoryBarrier(spv::ScopeDevice, spv::MemorySemanticsAcquireReleaseMask | spv::MemorySemanticsWorkgroupMemoryMask);
|
92 | 85 | }
|
| 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 | + |
93 | 130 | #endif
|
94 | 131 |
|
95 | 132 | }
|
|
0 commit comments