From 3fa382505271834514d47612efee8e51a06204c5 Mon Sep 17 00:00:00 2001 From: jarcherNV Date: Tue, 10 Jun 2025 09:44:08 -0700 Subject: 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. --- source/slang/slang-emit-hlsl.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-emit-hlsl.cpp') 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(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(inst->getDataType())) -- cgit v1.2.3