From a09d554721ecf0c6d967d5f55b3416e3284e71f2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 27 Feb 2025 22:22:46 -0800 Subject: Fix regression in float to bool conversion. (#6497) --- source/slang/slang-ir.cpp | 9 ++++++++- tests/bugs/float-to-bool.slang | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/float-to-bool.slang diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 3a7ace37d..1b0f99cd3 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -4047,7 +4047,7 @@ IRInst* IRBuilder::emitCast(IRType* type, IRInst* value, bool fallbackToBuiltinC /* From Float */ {kIROp_CastFloatToInt, kIROp_FloatCast, - {kIROp_CastFloatToInt, kIROp_IntCast}, + {kIROp_Neq}, {kIROp_CastFloatToInt, kIROp_CastIntToPtr}, kIROp_CastToVoid}, /* From Bool */ @@ -4079,6 +4079,13 @@ IRInst* IRBuilder::emitCast(IRType* type, IRInst* value, bool fallbackToBuiltinC matType->getColumnCount(), matType->getLayout()); } + + if (op.op0 == kIROp_Neq) + { + IRInst* args[2] = {value, emitDefaultConstruct(value->getDataType())}; + return emitIntrinsicInst(type, op.op0, 2, args); + } + auto result = emitIntrinsicInst(t, op.op0, 1, &value); if (op.op1 != kIROp_Nop) { diff --git a/tests/bugs/float-to-bool.slang b/tests/bugs/float-to-bool.slang new file mode 100644 index 000000000..5ee605f5a --- /dev/null +++ b/tests/bugs/float-to-bool.slang @@ -0,0 +1,25 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -xslang -Wno-30081 +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -xslang -Wno-30081 + +//TEST_INPUT: set outputBuffer = out ubuffer(data=[0 0 0 0 0], stride = 4) +RWStructuredBuffer outputBuffer; + +//TEST_INPUT: set inputBuffer = ubuffer(data=[0.0 0.2 1.0 1.2], stride = 4) +RWStructuredBuffer inputBuffer; +[numthreads(1,1,1)] +void computeMain() +{ + bool4 bv = inputBuffer[0]; + outputBuffer[0] = bv.x; + outputBuffer[1] = bv.y; + outputBuffer[2] = bv.z; + outputBuffer[3] = bv.w; + bool b = inputBuffer[0].y; + outputBuffer[4] = b; +} + +// CHECK: 0 +// CHECK: 1 +// CHECK: 1 +// CHECK: 1 +// CHECK: 1 \ No newline at end of file -- cgit v1.2.3