From 307315a7305e76529837fd1cdb677f534d5f539b Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 20 Oct 2024 09:28:13 -0700 Subject: Properly check switch case. (#5341) --- source/slang/slang-emit-wgsl.cpp | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) (limited to 'source/slang/slang-emit-wgsl.cpp') 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(caseVal); - IRBasicType *const caseInstType = as(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) -- cgit v1.2.3