summaryrefslogtreecommitdiffstats
path: root/tools/render-test/slang-support.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-10-16 13:12:11 -0700
committerGitHub <noreply@github.com>2017-10-16 13:12:11 -0700
commitf12c2552b3f494cbc8245edb90b32b93ca8a1539 (patch)
tree4cd08ad6037067dc70844a4a847fb3228e0176ee /tools/render-test/slang-support.cpp
parent3e3e2473bf85365593629bd1f6f070d11f0b8ab2 (diff)
Implement notion of a "container format" (#213)
The big addition here is that the Slang "bytecode" is no longer treated as just a "code generation target" (`CodeGenTarget`) akin to DX bytecode (DXBC) or SPIR-V, but instead is a `ContainerFormat` that can be used to emit all the results of a compile request (well, currently just the IR-as-BC, but the intention is there). Getting to this goal involved some prior checkins that eliminated bogus "targets" that weren't really akin to SPIR-V or DXBC: `-target slang-ir-asm` and `-target reflection-json`. Those targets were really in place to support testing, and so they've been made more explicit testing/debug options. This change eliminates `-target slang-ir` and instead tries to allow the user to specify `-o foo.slang-module` as an output file name, that indicates the intention to output a "container" file that will wrap up all the generated code. I've also gone ahead and generalized the existing `-target` option so that we are actually building up a *list* of code generation targets. This is largely just a cleanup, since it forces code to be more aware of when it is doing something target-specific vs. target independent. For example, reflection layout information lives on a requested target, and not on the compile request as a whole, and similarly output code is per-target, per-entry-point. As a cleanup, I eliminated support for per-translation-unit output. This was vestigial code from back when I used to try and do HLSL generation for a whole translation unit instead of per-entry-point (which turned out to be a lot of complexity for little gain), and it was only being used in the `hello` example and the `render-test` test fixture - in both cases fixing it up was easy enough. I've stubbed out the old `spGetTranslationUnitSource` API, but haven't removed it yet.
Diffstat (limited to 'tools/render-test/slang-support.cpp')
-rw-r--r--tools/render-test/slang-support.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp
index dbddd9c4f..bf8b7b9c7 100644
--- a/tools/render-test/slang-support.cpp
+++ b/tools/render-test/slang-support.cpp
@@ -38,6 +38,8 @@ struct SlangShaderCompilerWrapper : public ShaderCompiler
int vertexTranslationUnit = 0;
int fragmentTranslationUnit = 0;
+ char const* vertexEntryPointName = request.vertexShader.name;
+ char const* fragmentEntryPointName = request.fragmentShader.name;
if( sourceLanguage == SLANG_SOURCE_LANGUAGE_GLSL )
{
// GLSL presents unique challenges because, frankly, it got the whole
@@ -48,13 +50,13 @@ struct SlangShaderCompilerWrapper : public ShaderCompiler
vertexTranslationUnit = spAddTranslationUnit(slangRequest, sourceLanguage, nullptr);
spAddTranslationUnitSourceString(slangRequest, vertexTranslationUnit, request.source.path, request.source.text);
-
spTranslationUnit_addPreprocessorDefine(slangRequest, vertexTranslationUnit, "__GLSL_VERTEX__", "1");
+ vertexEntryPointName = "main";
fragmentTranslationUnit = spAddTranslationUnit(slangRequest, sourceLanguage, nullptr);
spAddTranslationUnitSourceString(slangRequest, fragmentTranslationUnit, request.source.path, request.source.text);
-
spTranslationUnit_addPreprocessorDefine(slangRequest, fragmentTranslationUnit, "__GLSL_FRAGMENT__", "1");
+ fragmentEntryPointName = "main";
}
else
{
@@ -72,8 +74,8 @@ struct SlangShaderCompilerWrapper : public ShaderCompiler
spSetCompileFlags(slangRequest, SLANG_COMPILE_FLAG_NO_CHECKING);
}
- int vertexEntryPoint = spAddEntryPoint(slangRequest, vertexTranslationUnit, request.vertexShader.name, spFindProfile(slangSession, request.vertexShader.profile));
- int fragmentEntryPoint = spAddEntryPoint(slangRequest, fragmentTranslationUnit, request.fragmentShader.name, spFindProfile(slangSession, request.fragmentShader.profile));
+ int vertexEntryPoint = spAddEntryPoint(slangRequest, vertexTranslationUnit, vertexEntryPointName, spFindProfile(slangSession, request.vertexShader.profile));
+ int fragmentEntryPoint = spAddEntryPoint(slangRequest, fragmentTranslationUnit, fragmentEntryPointName, spFindProfile(slangSession, request.fragmentShader.profile));
int compileErr = spCompile(slangRequest);
if(auto diagnostics = spGetDiagnosticOutput(slangRequest))
@@ -90,12 +92,6 @@ struct SlangShaderCompilerWrapper : public ShaderCompiler
ShaderCompileRequest innerRequest = request;
- if( sourceLanguage != SLANG_SOURCE_LANGUAGE_GLSL )
- {
- char const* translatedCode = spGetTranslationUnitSource(slangRequest, 0);
- innerRequest.source.text = translatedCode;
- }
-
char const* vertexCode = spGetEntryPointSource(slangRequest, vertexEntryPoint);
char const* fragmentCode = spGetEntryPointSource(slangRequest, fragmentEntryPoint);