Skip to content

Commit 69c7778

Browse files
committed
Added bit_field intrisic
1 parent 84d9aca commit 69c7778

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ NBL_ALIAS_TEMPLATE_FUNCTION(std::rotl, rotl);
2323
NBL_ALIAS_TEMPLATE_FUNCTION(std::rotr, rotr);
2424
NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
2525

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+
2632
}
2733
#else
2834

@@ -102,6 +108,13 @@ uint16_t countl_zero(T n)
102108
return impl::clz<sizeof(T)*8>(n);
103109
}
104110

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+
105118
}
106119
}
107120
#endif

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ void memoryBarrier(uint32_t memoryScope, uint32_t memorySemantics);
129129
template<class T, class U>
130130
[[vk::ext_instruction(spv::OpBitcast)]]
131131
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+
132141
}
133142
#endif
134143
}

0 commit comments

Comments
 (0)