From 14764896c34b230a5563f48d8b8e565de2f3aa10 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 2 Feb 2024 22:28:02 -0800 Subject: Capability type checking. (#3530) * Capability type checking. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-check-shader.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-check-shader.cpp') diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index b45107640..2e854554e 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -396,7 +396,6 @@ namespace Slang auto module = getModule(entryPointFuncDecl); auto linkage = module->getLinkage(); - // Every entry point needs to have a stage specified either via // command-line/API options, or via an explicit `[shader("...")]` attribute. // @@ -506,6 +505,38 @@ namespace Slang } } } + + for (auto target : linkage->targets) + { + auto targetCaps = target->getTargetCaps(); + auto stageCapabilitySet = CapabilitySet(entryPoint->getProfile().getCapabilityName()); + targetCaps.join(stageCapabilitySet); + if (targetCaps.isIncompatibleWith(entryPointFuncDecl->inferredCapabilityRequirements)) + { + sink->diagnose(entryPointFuncDecl, Diagnostics::entryPointUsesUnavailableCapability, entryPointFuncDecl, entryPointFuncDecl->inferredCapabilityRequirements, targetCaps); + auto& interredCapConjunctions = entryPointFuncDecl->inferredCapabilityRequirements.getExpandedAtoms(); + + // Find out what exactly is incompatible and print out a trace of provenance to + // help user diagnose their code. + auto& conjunctions = targetCaps.getExpandedAtoms(); + if (conjunctions.getCount() == 1 && interredCapConjunctions.getCount() == 1) + { + for (auto atom : conjunctions[0].getExpandedAtoms()) + { + for (auto inferredAtom : interredCapConjunctions[0].getExpandedAtoms()) + { + if (CapabilityConjunctionSet(inferredAtom).isIncompatibleWith(atom)) + { + diagnoseCapabilityProvenance(sink, entryPointFuncDecl, inferredAtom); + goto breakLabel; + } + } + } + } + } + } + breakLabel:; + } // Given an entry point specified via API or command line options, @@ -533,7 +564,7 @@ namespace Slang auto entryPointName = entryPointReq->getName(); FuncDecl* entryPointFuncDecl = findFunctionDeclByName(translationUnit->getModule(), entryPointName, sink); - + // Did we find a function declaration in our search? if(!entryPointFuncDecl) { -- cgit v1.2.3