summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorjarcherNV <jarcher@nvidia.com>2025-06-10 09:44:08 -0700
committerGitHub <noreply@github.com>2025-06-10 09:44:08 -0700
commit3fa382505271834514d47612efee8e51a06204c5 (patch)
treea76ff3a3969ed229bfbe4452326335d1db62418a /source/slang/slang-emit-hlsl.cpp
parente37202002276b679c5241b2678af612552b06d2c (diff)
Allow checking capabilities in specific stages (#7375)
This allows checking capabilities in any stage, needed specifically for the hlsl_2018 capability which is defined for sm_5_1 and above. Stage specific capabilities such as cs_5_1 would not find this in any stage other than compute, so we need to restrict the check to only desired stages.
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index ba167676a..b022a2db9 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -785,6 +785,29 @@ bool HLSLSourceEmitter::tryEmitInstStmtImpl(IRInst* inst)
}
}
+static bool isTargetHLSL2018(HLSLSourceEmitter* emitter, CapabilitySet targetCaps, Stage stage)
+{
+ auto stageAtom = getAtomFromStage(stage);
+
+ // Cache the result of this function for easier lookup.
+ auto result = emitter->getCachedCapability(stageAtom);
+ if (result)
+ return *result;
+
+ // Here we check for presence of the `hlsl_2018` capability for the
+ // current target+stage.
+ auto capabilitySetForStageOfEntryPoint = CapabilitySet(CapabilityName(stageAtom));
+ auto hlsl2018CapabilitySet =
+ CapabilitySet(CapabilityName::hlsl_2018).join(capabilitySetForStageOfEntryPoint);
+ if (targetCaps.join(capabilitySetForStageOfEntryPoint).implies(hlsl2018CapabilitySet))
+ {
+ emitter->addCachedCapability(stageAtom, false);
+ return false;
+ }
+ emitter->addCachedCapability(stageAtom, true);
+ return true;
+}
+
bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOuterPrec)
{
switch (inst->getOp())
@@ -827,7 +850,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
if (targetProfile.getVersion() < ProfileVersion::DX_6_0)
return false;
auto targetCaps = getTargetReq()->getTargetCaps();
- if (targetCaps.implies(CapabilityAtom::hlsl_2018))
+ if (!isTargetHLSL2018(this, targetCaps, m_entryPointStage))
return false;
if (as<IRBasicType>(inst->getDataType()))
@@ -855,7 +878,7 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
if (targetProfile.getVersion() < ProfileVersion::DX_6_0)
return false;
auto targetCaps = getTargetReq()->getTargetCaps();
- if (targetCaps.implies(CapabilityAtom::hlsl_2018))
+ if (!isTargetHLSL2018(this, targetCaps, m_entryPointStage))
return false;
if (as<IRBasicType>(inst->getDataType()))