diff options
| author | Yong He <yonghe@outlook.com> | 2025-02-27 22:22:46 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-27 22:22:46 -0800 |
| commit | a09d554721ecf0c6d967d5f55b3416e3284e71f2 (patch) | |
| tree | bd42082eb500c7ef67bb13782bdf87362a35336a | |
| parent | 4872eebaa26dad7809fb6c58f5569ec64099e0c1 (diff) | |
Fix regression in float to bool conversion. (#6497)
| -rw-r--r-- | source/slang/slang-ir.cpp | 9 | ||||
| -rw-r--r-- | tests/bugs/float-to-bool.slang | 25 |
2 files changed, 33 insertions, 1 deletions
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<int> outputBuffer; + +//TEST_INPUT: set inputBuffer = ubuffer(data=[0.0 0.2 1.0 1.2], stride = 4) +RWStructuredBuffer<float4> 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 |
