summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-11-06 18:43:33 -0800
committerGitHub <noreply@github.com>2019-11-06 18:43:33 -0800
commitfedda2e5342d3bfbdbbdd3ca232b3f69fff81ef7 (patch)
treee6edb884d601c5f71ac70370904b2b04274a518f /tools
parent7a877c380c3c84d03326e6fb982f85547d0bd338 (diff)
Add basic support for entry points in `.slang-lib` files. (#1112)
* Add basic support for entry points in `.slang-lib` files. The basic idea here is that when writing out a `.slang-lib` file based on a compile request, we include new sections in the generated RIFF that represent the entry points that were requested. The entry-point information is serialized in an entirely ad hoc fashion (a future change might clean it up to use the `OffsetContainer` machinery), and contains the name, profile, and mangled symbol name of an entry point. When deserializing this information, we create a list of "extra" entry points that gets attached to the front-end compile requests. These "extra" entry points get turned into `EntryPoint` objects at the same place in the code that entry points specified on the command line or via API would be checked, but the extra entry points bypass the semantic checking and just create "dummy" `EntryPoint` objects. Aside: the ability for a compile request to end up with entry points that weren't originally specified via API or command-line is not new. We already had support for compiling a translation unit with entry points entirely specified via `[shader(...)]` attributes, and this new support tries to function similarly. Because the "dummy" entry points don't retain AST-level information, several parts of the code have been modified to defensively check for `EntryPoint` objects without a matching AST declaration, and skip over them. The main place where this creates a problem is paramete binding, where ignoring the dummy entry point is appropriate since we currently assume linked-in library code has been laid out manually. One small cleanup here is that the `-r` command-line flag and the `spAddLibraryReference` API functio now bottleneck through a common routine to do their work, so that they both gain the new behavior without needing copy-paste programming. In order to keep the existing test case for library linking with entry points working, I had to add a flag to the `render-test` tool so that it can skip specifying entry point names as part of the compile request it creates. In that case it must instead assume that the entry points will be added to the compile request via other means. This logic is a bit magical, and hints that we should be looking for other ways to expose the library linking functionality over time. * fixup: remove alignment assertion
Diffstat (limited to 'tools')
-rw-r--r--tools/render-test/options.cpp4
-rw-r--r--tools/render-test/options.h2
-rw-r--r--tools/render-test/slang-support.cpp29
3 files changed, 25 insertions, 10 deletions
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
index 3d5df6f62..fec934afc 100644
--- a/tools/render-test/options.cpp
+++ b/tools/render-test/options.cpp
@@ -255,6 +255,10 @@ SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper s
gOptions.sourceLanguage = sourceLanguage;
}
+ else if( strcmp(arg, "-no-default-entry-point") == 0 )
+ {
+ gOptions.dontAddDefaultEntryPoints = true;
+ }
else
{
// Lookup
diff --git a/tools/render-test/options.h b/tools/render-test/options.h
index 1bb4af74c..1048a29f4 100644
--- a/tools/render-test/options.h
+++ b/tools/render-test/options.h
@@ -62,6 +62,8 @@ struct Options
bool performanceProfile = false;
+ bool dontAddDefaultEntryPoints = false;
+
Slang::List<Slang::String> renderFeatures; /// Required render features for this test to run
Slang::List<Slang::CommandLine::Arg> compileArgs;
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index 9afddc09b..06284e1e3 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -149,13 +149,17 @@ static const char computeEntryPointName[] = "computeMain";
if (request.computeShader.name)
{
- int computeEntryPoint = spAddEntryPointEx(slangRequest, computeTranslationUnit,
- computeEntryPointName,
- SLANG_STAGE_COMPUTE,
- (int)rawEntryPointTypeNames.getCount(),
- rawEntryPointTypeNames.getBuffer());
+ int computeEntryPoint = 0;
+ if(!gOptions.dontAddDefaultEntryPoints)
+ {
+ computeEntryPoint = spAddEntryPointEx(slangRequest, computeTranslationUnit,
+ computeEntryPointName,
+ SLANG_STAGE_COMPUTE,
+ (int)rawEntryPointTypeNames.getCount(),
+ rawEntryPointTypeNames.getBuffer());
- setEntryPointExistentialTypeArgs(computeEntryPoint);
+ setEntryPointExistentialTypeArgs(computeEntryPoint);
+ }
spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE);
const SlangResult res = spCompile(slangRequest);
@@ -180,11 +184,16 @@ static const char computeEntryPointName[] = "computeMain";
}
else
{
- int vertexEntryPoint = spAddEntryPointEx(slangRequest, vertexTranslationUnit, vertexEntryPointName, SLANG_STAGE_VERTEX, (int)rawEntryPointTypeNames.getCount(), rawEntryPointTypeNames.getBuffer());
- int fragmentEntryPoint = spAddEntryPointEx(slangRequest, fragmentTranslationUnit, fragmentEntryPointName, SLANG_STAGE_FRAGMENT, (int)rawEntryPointTypeNames.getCount(), rawEntryPointTypeNames.getBuffer());
+ int vertexEntryPoint = 0;
+ int fragmentEntryPoint = 1;
+ if( !gOptions.dontAddDefaultEntryPoints )
+ {
+ vertexEntryPoint = spAddEntryPointEx(slangRequest, vertexTranslationUnit, vertexEntryPointName, SLANG_STAGE_VERTEX, (int)rawEntryPointTypeNames.getCount(), rawEntryPointTypeNames.getBuffer());
+ fragmentEntryPoint = spAddEntryPointEx(slangRequest, fragmentTranslationUnit, fragmentEntryPointName, SLANG_STAGE_FRAGMENT, (int)rawEntryPointTypeNames.getCount(), rawEntryPointTypeNames.getBuffer());
- setEntryPointExistentialTypeArgs(vertexEntryPoint);
- setEntryPointExistentialTypeArgs(fragmentEntryPoint);
+ setEntryPointExistentialTypeArgs(vertexEntryPoint);
+ setEntryPointExistentialTypeArgs(fragmentEntryPoint);
+ }
const SlangResult res = spCompile(slangRequest);
if (auto diagnostics = spGetDiagnosticOutput(slangRequest))