From 57b09a8986668626c37055e431fa0ac6449d7214 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:27:23 -0800 Subject: Use and() and or() functions for logical-AND and OR (#6310) * Use and() and or() functions for logical-AND and OR With this commit, Slang will emit function calls to `and()` and `or()` for the logical-AND and logical-OR when the operands are non-scalar and the target profile is SM6.0 and above. This is required change from SM6.0. For WGSL, there is no operator overloadings of `&&` and `||` when the operands are non-scalar. Unlike HLSL, WGSL also don't have `and()` nor `or()`. Alternatively, we can use `select()`. --- source/slang/slang-emit.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index f093104bd..e20a4a90f 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -52,6 +52,7 @@ #include "slang-ir-insts.h" #include "slang-ir-layout.h" #include "slang-ir-legalize-array-return-type.h" +#include "slang-ir-legalize-binary-operator.h" #include "slang-ir-legalize-global-values.h" #include "slang-ir-legalize-image-subscript.h" #include "slang-ir-legalize-mesh-outputs.h" @@ -1469,6 +1470,10 @@ Result linkAndOptimizeIR( floatNonUniformResourceIndex(irModule, NonUniformResourceIndexFloatMode::Textual); } + if (isD3DTarget(targetRequest) || isKhronosTarget(targetRequest) || + isWGPUTarget(targetRequest) || isMetalTarget(targetRequest)) + legalizeLogicalAndOr(irModule->getModuleInst()); + // Legalize non struct parameters that are expected to be structs for HLSL. if (isD3DTarget(targetRequest)) legalizeNonStructParameterToStructForHLSL(irModule); -- cgit v1.2.3