Skip to content

Commit 46ee809

Browse files
committed
Discover entry points specified via options
This closes #6452.
1 parent e685359 commit 46ee809

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

source/slang/slang-compiler.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -2745,11 +2745,49 @@ void Module::_discoverEntryPoints(DiagnosticSink* sink, const List<RefPtr<Target
27452745
return;
27462746
_discoverEntryPointsImpl(m_moduleDecl, sink, targets);
27472747
}
2748+
2749+
static void addEntryPointStagesFromOptions(
2750+
Slang::CompilerOptionSet& optionSet,
2751+
Dictionary<String, Stage>& optionEntryPointStages)
2752+
{
2753+
for (auto& entry : optionSet.options)
2754+
{
2755+
if (entry.key != CompilerOptionName::EntryPointName)
2756+
continue;
2757+
2758+
for (auto& value : entry.value)
2759+
{
2760+
// Assume the options have been validated
2761+
SLANG_ASSERT(value.kind == CompilerOptionValueKind::String);
2762+
Stage stage = optionSet.getEnumOption<Stage>(CompilerOptionName::Stage);
2763+
if (stage != Stage::Unknown)
2764+
{
2765+
// We're assuming option validation forbids inconsistent entry points
2766+
Stage existingStage;
2767+
SLANG_ASSERT(
2768+
!optionEntryPointStages.tryGetValue(value.stringValue, existingStage) ||
2769+
existingStage == stage);
2770+
optionEntryPointStages.add(value.stringValue, stage);
2771+
break;
2772+
}
2773+
}
2774+
}
2775+
}
2776+
27482777
void Module::_discoverEntryPointsImpl(
27492778
ContainerDecl* containerDecl,
27502779
DiagnosticSink* sink,
27512780
const List<RefPtr<TargetRequest>>& targets)
27522781
{
2782+
// Get entry points from global and per-target compiler options
2783+
Dictionary<String, Stage> optionEntryPointStages;
2784+
addEntryPointStagesFromOptions(getLinkage()->m_optionSet, optionEntryPointStages);
2785+
for (auto target : targets)
2786+
{
2787+
auto& targetOptionSet = target->getOptionSet();
2788+
addEntryPointStagesFromOptions(targetOptionSet, optionEntryPointStages);
2789+
}
2790+
27532791
for (auto globalDecl : containerDecl->members)
27542792
{
27552793
auto maybeFuncDecl = globalDecl;
@@ -2776,7 +2814,20 @@ void Module::_discoverEntryPointsImpl(
27762814
targets,
27772815
funcDecl,
27782816
sink);
2817+
2818+
// Check if this function is marked as an entry point via compiler options
2819+
bool resolvedStageOfProfileWithOptions = false;
27792820
if (!resolvedStageOfProfileWithEntryPoint)
2821+
{
2822+
Stage stage;
2823+
if (optionEntryPointStages.tryGetValue(funcDecl->getName()->text, stage))
2824+
{
2825+
profile.setStage(stage);
2826+
resolvedStageOfProfileWithOptions = true;
2827+
}
2828+
}
2829+
2830+
if (!resolvedStageOfProfileWithEntryPoint && !resolvedStageOfProfileWithOptions)
27802831
{
27812832
// If there isn't a [shader] attribute, look for a [numthreads] attribute
27822833
// since that implicitly means a compute shader. We'll not do this when compiling for

0 commit comments

Comments
 (0)