summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-09 12:47:03 -0700
committerGitHub <noreply@github.com>2024-04-09 12:47:03 -0700
commit6a465a4db65b924b03930261da3b64b1c792ef85 (patch)
tree8d90c1864fc47e2ed08ded8000a3eadb41ef8f60 /source/slang/slang.cpp
parent957b2fbb67efa82d778052c0d63d4de339e89e6f (diff)
Allow COM based API to discover and check entrypoints without [shader] attribute. (#3914)
* Allow COM based API to discover and check entrypoints without [shader] attribute. * Undo changes. * More comments.
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 6d40b46a2..0db833c7a 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -3987,13 +3987,6 @@ void Module::setName(String name)
RefPtr<EntryPoint> Module::findEntryPointByName(UnownedStringSlice const& name)
{
- // TODO: We should consider having this function be expanded to be able
- // to look up and validate possible entry-point functions in teh module
- // even if they were not marked with `[shader(...)]` in the source code.
- //
- // With such a change the function would probably need to accept a stage
- // to use and a sink to write validation errors to.
-
for(auto entryPoint : m_entryPoints)
{
if(entryPoint->getName()->text.getUnownedSlice() == name)
@@ -4003,6 +3996,41 @@ RefPtr<EntryPoint> Module::findEntryPointByName(UnownedStringSlice const& name)
return nullptr;
}
+
+RefPtr<EntryPoint> Module::findAndCheckEntryPoint(
+ UnownedStringSlice const& name,
+ SlangStage stage,
+ ISlangBlob** outDiagnostics)
+{
+ // If there is already an entrypoint marked with the [shader] attribute,
+ // we should just return that.
+ //
+ if (auto existingEntryPoint = findEntryPointByName(name))
+ return existingEntryPoint;
+
+ // If the function hasn't been marked as [shader], then it won't be discovered
+ // by findEntryPointByName. We need to route this to the `findAndValidateEntryPoint`
+ // function. To do that we need to setup a FrontEndCompileRequest and a FrontEndEntryPointRequest.
+ //
+ DiagnosticSink sink(getLinkage()->getSourceManager(), DiagnosticSink::SourceLocationLexer());
+ FrontEndCompileRequest frontEndRequest(getLinkage(), StdWriters::getSingleton(), &sink);
+ RefPtr<TranslationUnitRequest> tuRequest = new TranslationUnitRequest(&frontEndRequest);
+ tuRequest->module = this;
+ tuRequest->moduleName = m_name;
+ frontEndRequest.translationUnits.add(tuRequest);
+ FrontEndEntryPointRequest entryPointRequest(
+ &frontEndRequest,
+ 0,
+ getLinkage()->getNamePool()->getName(name),
+ Profile((Stage)stage));
+ auto result = findAndValidateEntryPoint(&entryPointRequest);
+ if (outDiagnostics)
+ {
+ sink.getBlobIfNeeded(outDiagnostics);
+ }
+ return result;
+}
+
void Module::_addEntryPoint(EntryPoint* entryPoint)
{
m_entryPoints.add(entryPoint);