From 879ee3d187e577189eba9aed7bc6326b740cb627 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 5 Sep 2024 11:53:14 -0700 Subject: Support entrypoints defined in a namespace. (#5011) * Support entrypoints defined in a namespace. * Fix test. --- source/slang/slang-compiler.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-compiler.cpp') diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index a5a09204b..7d2dbed0d 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -2535,8 +2535,11 @@ namespace Slang { if (m_entryPoints.getCount() > 0) return; - - for (auto globalDecl : m_moduleDecl->members) + _discoverEntryPointsImpl(m_moduleDecl, sink, targets); + } + void Module::_discoverEntryPointsImpl(ContainerDecl* containerDecl, DiagnosticSink* sink, const List>& targets) + { + for (auto globalDecl : containerDecl->members) { auto maybeFuncDecl = globalDecl; if (auto genericDecl = as(maybeFuncDecl)) @@ -2544,13 +2547,19 @@ namespace Slang maybeFuncDecl = genericDecl->inner; } + if (as(globalDecl) || as(globalDecl) || as(globalDecl)) + { + _discoverEntryPointsImpl(as(globalDecl), sink, targets); + continue; + } + auto funcDecl = as(maybeFuncDecl); if (!funcDecl) continue; Profile profile; bool resolvedStageOfProfileWithEntryPoint = resolveStageOfProfileWithEntryPoint(profile, getLinkage()->m_optionSet, targets, funcDecl, sink); - if(!resolvedStageOfProfileWithEntryPoint) + if (!resolvedStageOfProfileWithEntryPoint) { // If there isn't a [shader] attribute, look for a [numthreads] attribute // since that implicitly means a compute shader. We'll not do this when compiling for @@ -2560,7 +2569,7 @@ namespace Slang bool allTargetsCUDARelated = true; for (auto target : targets) { - if (!isCUDATarget(target) && + if (!isCUDATarget(target) && target->getTarget() != CodeGenTarget::PyTorchCppBinding) { allTargetsCUDARelated = false; @@ -2614,6 +2623,5 @@ namespace Slang _addEntryPoint(entryPoint); } } - } -- cgit v1.2.3