File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ NBL_ALIAS_TEMPLATE_FUNCTION(std::rotl, rotl);
23
23
NBL_ALIAS_TEMPLATE_FUNCTION (std::rotr, rotr);
24
24
NBL_ALIAS_TEMPLATE_FUNCTION (std::countl_zero, countl_zero);
25
25
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
+
26
32
}
27
33
#else
28
34
@@ -102,6 +108,13 @@ uint16_t countl_zero(T n)
102
108
return impl::clz<sizeof (T)*8 >(n);
103
109
}
104
110
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
+
105
118
}
106
119
}
107
120
#endif
Original file line number Diff line number Diff line change @@ -129,6 +129,15 @@ void memoryBarrier(uint32_t memoryScope, uint32_t memorySemantics);
129
129
template<class T, class U>
130
130
[[vk::ext_instruction (spv::OpBitcast)]]
131
131
T bitcast (U);
132
+
133
+ template<typename Unsigned>
134
+ [[vk::ext_instruction ( spv::OpBitFieldUExtract )]]
135
+ Unsigned bitfieldExtractUnsigned ( Unsigned val, uint32_t offsetBits, uint32_t numBits );
136
+
137
+ template<typename Signed>
138
+ [[vk::ext_instruction ( spv::OpBitFieldSExtract )]]
139
+ Signed bitfieldExtractSigned ( Signed val, uint32_t offsetBits, uint32_t numBits );
140
+
132
141
}
133
142
#endif
134
143
}
You can’t perform that action at this time.
0 commit comments