summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-wgsl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-10-20 09:28:13 -0700
committerGitHub <noreply@github.com>2024-10-20 09:28:13 -0700
commit307315a7305e76529837fd1cdb677f534d5f539b (patch)
treeba39e96ba2e9b3d62d1213aab2f1cc54febe451a /source/slang/slang-emit-wgsl.cpp
parent9936178dd3efb026bfa142512a2bf061d7a75ab5 (diff)
Properly check switch case. (#5341)
Diffstat (limited to 'source/slang/slang-emit-wgsl.cpp')
-rw-r--r--source/slang/slang-emit-wgsl.cpp35
1 files changed, 1 insertions, 34 deletions
diff --git a/source/slang/slang-emit-wgsl.cpp b/source/slang/slang-emit-wgsl.cpp
index b1a723dc5..105f5c3cf 100644
--- a/source/slang/slang-emit-wgsl.cpp
+++ b/source/slang/slang-emit-wgsl.cpp
@@ -27,7 +27,6 @@ namespace Slang
{
void WGSLSourceEmitter::emitSwitchCaseSelectorsImpl(
- IRBasicType *const switchConditionType,
const SwitchRegion::Case *const currentCase,
const bool isDefault)
{
@@ -38,39 +37,7 @@ void WGSLSourceEmitter::emitSwitchCaseSelectorsImpl(
m_writer->emit("case ");
for (auto caseVal : currentCase->values)
{
- // TODO: Fix this in the front-end [1], remove the if-path and just do the else-path.
- // We can't do that at the moment because it would break Falcor [2].
- // [1] https://github.com/shader-slang/slang/pull/5025/commits/a32156ef52f43b8503b2c77f2f1d51220ab9bdea
- // [2] https://github.com/shader-slang/slang/pull/5025#issuecomment-2334495120
- if (caseVal->getOp() == kIROp_IntLit)
- {
- auto caseLitInst = static_cast<IRConstant*>(caseVal);
- IRBasicType *const caseInstType = as<IRBasicType>(caseLitInst->getDataType());
- // WGSL doesn't allow switch condition and case type mismatches, see [1].
- // Thus we need to insert explicit conversions.
- // Doing a wrapping cast will match Slang's de facto semantics, according to
- // [2].
- // (This is just a bitcast, assuming a two's complement representation.)
- // [1] https://www.w3.org/TR/WGSL/#switch-statement
- // [2] https://github.com/shader-slang/slang/issues/4921
- const bool needBitcast =
- caseInstType->getBaseType() != switchConditionType->getBaseType();
- if (needBitcast)
- {
- m_writer->emit("bitcast<");
- emitType(switchConditionType);
- m_writer->emit(">(");
- }
- emitOperand(caseVal, getInfo(EmitOp::General));
- if (needBitcast)
- {
- m_writer->emit(")");
- }
- }
- else
- {
- emitOperand(caseVal, getInfo(EmitOp::General));
- }
+ emitOperand(caseVal, getInfo(EmitOp::General));
m_writer->emit(", ");
}
if (isDefault)