diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2025-05-06 00:27:00 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-05 17:27:00 -0700 |
| commit | 6907ea5c8f83712f40fbc7713de4f4bb656c6c35 (patch) | |
| tree | da8b9ce1154eeb96f5155095b6e78154e34c6872 | |
| parent | 50d9781b7387b0f7f56d19c72afcf390cca72b72 (diff) | |
Add a new capability hlsl_2018 that avoid using select/and/or (#7003)
Co-authored-by: Yong He <yonghe@outlook.com>
| -rw-r--r-- | source/slang/slang-capabilities.capdef | 5 | ||||
| -rw-r--r-- | source/slang/slang-emit-hlsl.cpp | 6 | ||||
| -rw-r--r-- | tests/compute/logic-no-short-circuit-evaluation.slang | 4 |
3 files changed, 15 insertions, 0 deletions
diff --git a/source/slang/slang-capabilities.capdef b/source/slang/slang-capabilities.capdef index 8f6aa254c..b50519a72 100644 --- a/source/slang/slang-capabilities.capdef +++ b/source/slang/slang-capabilities.capdef @@ -219,6 +219,11 @@ def _sm_6_9 : _sm_6_8; /// [Version] def hlsl_nvapi : hlsl; + +/// Represet HLSL compatibility support. +/// [Version] +def hlsl_2018 : _sm_5_1; + /// Represents capabilities required for DXIL Library compilation. /// [Version] alias dxil_lib = _sm_6_3; diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 2d963866d..3813cf9cb 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -826,6 +826,9 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu auto targetProfile = getTargetProgram()->getOptionSet().getProfile(); if (targetProfile.getVersion() < ProfileVersion::DX_6_0) return false; + auto targetCaps = getTargetReq()->getTargetCaps(); + if (targetCaps.implies(CapabilityAtom::hlsl_2018)) + return false; if (as<IRBasicType>(inst->getDataType())) return false; @@ -851,6 +854,9 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu auto targetProfile = getTargetProgram()->getOptionSet().getProfile(); if (targetProfile.getVersion() < ProfileVersion::DX_6_0) return false; + auto targetCaps = getTargetReq()->getTargetCaps(); + if (targetCaps.implies(CapabilityAtom::hlsl_2018)) + return false; if (as<IRBasicType>(inst->getDataType())) return false; diff --git a/tests/compute/logic-no-short-circuit-evaluation.slang b/tests/compute/logic-no-short-circuit-evaluation.slang index 74351a505..ea2b7a0c3 100644 --- a/tests/compute/logic-no-short-circuit-evaluation.slang +++ b/tests/compute/logic-no-short-circuit-evaluation.slang @@ -1,4 +1,5 @@ //TEST(compute):SIMPLE(filecheck=SM5):-target hlsl -profile cs_5_1 -entry computeMain +//TEST(compute):SIMPLE(filecheck=HLSL2018):-target hlsl -profile cs_6_0 -capability hlsl_2018 -entry computeMain //TEST(compute):SIMPLE(filecheck=SM6):-target hlsl -profile cs_6_0 -entry computeMain //TEST(compute):SIMPLE(filecheck=WGS):-target wgsl -stage compute -entry computeMain //TEST(compute):SIMPLE(filecheck=MTL):-target metal -stage compute -entry computeMain @@ -29,6 +30,7 @@ void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) // No short-circuiting for vector types //SM5:(all({{.*}}&& + //HLSL2018:(all({{.*}}&& //SM6:(all(and( //WGS:(all(select(vec2<bool>(false), //MTL:(all({{.*}}&& @@ -40,6 +42,7 @@ void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) // Intentionally using non-boolean type for testing. //SM5:(all({{.*}}|| + //HLSL2018:(all({{.*}}|| //SM6:(or(vector<bool,2>( //WGS:(select({{.*}}, vec2<bool>(true), vec2<bool>( //MTL:(all(bool2({{.*}}|| @@ -49,6 +52,7 @@ void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) } //SM5:(all({{.*}}?{{.*}}: + //HLSL2018:(all({{.*}}?{{.*}}: //SM6:(all(select( //WGS:(all(select(vec2<bool>(false), //MTL:(all(select(bool2(false) |
