From f12c2552b3f494cbc8245edb90b32b93ca8a1539 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 16 Oct 2017 13:12:11 -0700 Subject: 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. --- examples/hello/hello.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/hello/hello.cpp b/examples/hello/hello.cpp index 8e48b3c13..2d7bb81b5 100644 --- a/examples/hello/hello.cpp +++ b/examples/hello/hello.cpp @@ -100,8 +100,8 @@ HRESULT initialize( ID3D11Device* dxDevice ) char const* vertexProfileName = "vs_4_0"; char const* fragmentProfileName = "ps_4_0"; - spAddEntryPoint(slangRequest, translationUnitIndex, vertexEntryPointName, spFindProfile(slangSession, vertexProfileName)); - spAddEntryPoint(slangRequest, translationUnitIndex, fragmentEntryPointName, spFindProfile(slangSession, fragmentProfileName)); + int vertexIndex = spAddEntryPoint(slangRequest, translationUnitIndex, vertexEntryPointName, spFindProfile(slangSession, vertexProfileName)); + int fragmentIndex = spAddEntryPoint(slangRequest, translationUnitIndex, fragmentEntryPointName, spFindProfile(slangSession, fragmentProfileName)); int compileErr = spCompile(slangRequest); if(auto diagnostics = spGetDiagnosticOutput(slangRequest)) @@ -114,17 +114,17 @@ HRESULT initialize( ID3D11Device* dxDevice ) return E_FAIL; } - char const* translatedCode = spGetTranslationUnitSource(slangRequest, translationUnitIndex); - + char const* vertexCode = spGetEntryPointSource(slangRequest, vertexIndex); + char const* fragmentCode = spGetEntryPointSource(slangRequest, fragmentIndex); // TODO(tfoley): Query the required constant-buffer size int constantBufferSize = 16 * sizeof(float); // Compile the generated HLSL code - ID3DBlob* dxVertexShaderBlob = compileHLSLShader(translatedCode, vertexEntryPointName, vertexProfileName); + ID3DBlob* dxVertexShaderBlob = compileHLSLShader(vertexCode, vertexEntryPointName, vertexProfileName); if(!dxVertexShaderBlob) return E_FAIL; - ID3DBlob* dxPixelShaderBlob = compileHLSLShader(translatedCode, fragmentEntryPointName, fragmentProfileName); + ID3DBlob* dxPixelShaderBlob = compileHLSLShader(fragmentCode, fragmentEntryPointName, fragmentProfileName); if(!dxPixelShaderBlob) return E_FAIL; HRESULT hr = S_OK; -- cgit v1.2.3