@@ -2745,11 +2745,49 @@ void Module::_discoverEntryPoints(DiagnosticSink* sink, const List<RefPtr<Target
2745
2745
return ;
2746
2746
_discoverEntryPointsImpl (m_moduleDecl, sink, targets);
2747
2747
}
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
+
2748
2777
void Module::_discoverEntryPointsImpl (
2749
2778
ContainerDecl* containerDecl,
2750
2779
DiagnosticSink* sink,
2751
2780
const List<RefPtr<TargetRequest>>& targets)
2752
2781
{
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
+
2753
2791
for (auto globalDecl : containerDecl->members )
2754
2792
{
2755
2793
auto maybeFuncDecl = globalDecl;
@@ -2776,7 +2814,20 @@ void Module::_discoverEntryPointsImpl(
2776
2814
targets,
2777
2815
funcDecl,
2778
2816
sink);
2817
+
2818
+ // Check if this function is marked as an entry point via compiler options
2819
+ bool resolvedStageOfProfileWithOptions = false ;
2779
2820
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)
2780
2831
{
2781
2832
// If there isn't a [shader] attribute, look for a [numthreads] attribute
2782
2833
// since that implicitly means a compute shader. We'll not do this when compiling for
0 commit comments