Skip to content

Commit 481e3bd

Browse files
committed
hlsl_generator: add type constraint for bit instructions
Signed-off-by: Ali Cheraghi <[email protected]>
1 parent 5b34f6d commit 481e3bd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tools/hlsl_generator/gen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def processInst(writer: io.TextIOWrapper, instruction, options: InstOptions):
217217
result_types = ["float16_t", "float32_t", "float64_t"]
218218
break
219219

220+
match instruction["class"]:
221+
case "Bit":
222+
if len(result_types) == 0: conds.append("(is_signed_v<T> || is_unsigned_v<T>)")
223+
220224
if "operands" in instruction:
221225
operands = instruction["operands"]
222226
if operands[0]["kind"] == "IdResultType":

tools/hlsl_generator/out.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ void store(pointer_t<spv::StorageClassPhysicalStorageBuffer, T> pointer, T objec
561561
template<typename T>
562562
[[vk::ext_capability(spv::CapabilityBitInstructions)]]
563563
[[vk::ext_instruction(spv::OpBitFieldInsert)]]
564-
T bitFieldInsert(T base, T insert, uint32_t offset, uint32_t count);
564+
enable_if_t<(is_signed_v<T> || is_unsigned_v<T>), T> bitFieldInsert(T base, T insert, uint32_t offset, uint32_t count);
565565

566566
[[vk::ext_capability(spv::CapabilityBitInstructions)]]
567567
[[vk::ext_instruction(spv::OpBitFieldSExtract)]]
@@ -606,11 +606,11 @@ uint64_t bitFieldExtract_Int64(uint64_t base, uint32_t offset, uint32_t count);
606606
template<typename T>
607607
[[vk::ext_capability(spv::CapabilityBitInstructions)]]
608608
[[vk::ext_instruction(spv::OpBitReverse)]]
609-
T bitReverse(T base);
609+
enable_if_t<(is_signed_v<T> || is_unsigned_v<T>), T> bitReverse(T base);
610610

611611
template<typename T>
612612
[[vk::ext_instruction(spv::OpBitCount)]]
613-
T bitCount(T base);
613+
enable_if_t<(is_signed_v<T> || is_unsigned_v<T>), T> bitCount(T base);
614614

615615
[[vk::ext_instruction(spv::OpControlBarrier)]]
616616
void controlBarrier(uint32_t executionScope, uint32_t memoryScope, uint32_t semantics);

0 commit comments

Comments
 (0)