diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-01 08:30:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-01 08:30:45 -0700 |
| commit | ec41631032b65973e8f92348e0a86bb9924ef981 (patch) | |
| tree | e047fec206bb9fc3ed6303c6963b9e7207097d3a /source/slang/compiler.cpp | |
| parent | e2b473060133ae25a0be92fcfe80c5c7e51fa10a (diff) | |
Allow use of dxc compiler for DXIL generation (#241)
- Add shader model 6.0, 6.1, and 6.2 targets
- Add DXIL and DXIL assembly as output formats
- Add header for DXC API to `external/`
- Add `dxc-support.cpp` that wraps usage of the API
- Add `-pass-through dxc` option, equivalent to what we have for `fxc`
Notes:
* This does *not* include any logic to add `dxcompiler.dll` to our build process; that is way out of scope for the build complexity I'm ready to deal with
* For right now, the use of `dxcompiler.dll` is hard-coded, and it must be discoverable in the current executable's search path; options to customize can come later
* The `-pass-through` option is kind of silly because the code doesn't actually pay attention to the value (just whether it is set). If you set it to `fxc` but ask for DXIL, we pass through `dxc` anyway.
Diffstat (limited to 'source/slang/compiler.cpp')
| -rw-r--r-- | source/slang/compiler.cpp | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index 8cf801a79..f045253b0 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -15,7 +15,7 @@ #include "reflection.h" #include "emit.h" -// Enable calling through to `fxc` to +// Enable calling through to `fxc` or `dxc` to // generate code on Windows. #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN @@ -27,12 +27,18 @@ #ifndef SLANG_ENABLE_DXBC_SUPPORT #define SLANG_ENABLE_DXBC_SUPPORT 1 #endif + #ifndef SLANG_ENABLE_DXIL_SUPPORT + #define SLANG_ENABLE_DXIL_SUPPORT 1 + #endif #endif // -// Otherwise, don't enable DXBC by default: +// Otherwise, don't enable DXBC/DXIL by default: #ifndef SLANG_ENABLE_DXBC_SUPPORT #define SLANG_ENABLE_DXBC_SUPPORT 0 #endif +#ifndef SLANG_ENABLE_DXIL_SUPPORT + #define SLANG_ENABLE_DXIL_SUPPORT 0 +#endif // Enable calling through to `glslang` on // all platforms. @@ -356,6 +362,22 @@ namespace Slang } #endif +#if SLANG_ENABLE_DXIL_SUPPORT + +// Implementations in `dxc-support.cpp` + +int emitDXILForEntryPointUsingDXC( + EntryPointRequest* entryPoint, + TargetRequest* targetReq, + List<uint8_t>& outCode); + +String dissassembleDXILUsingDXC( + CompileRequest* compileRequest, + void const* data, + size_t size); + +#endif + #if SLANG_ENABLE_GLSLANG_SUPPORT SharedLibrary loadGLSLCompilerDLL(CompileRequest* request) @@ -540,6 +562,38 @@ namespace Slang break; #endif +#if SLANG_ENABLE_DXIL_SUPPORT + case CodeGenTarget::DXIL: + { + List<uint8_t> code; + int err = emitDXILForEntryPointUsingDXC(entryPoint, targetReq, code); + if (!err) + { + maybeDumpIntermediate(compileRequest, code.Buffer(), code.Count(), target); + result = CompileResult(code); + } + } + break; + + case CodeGenTarget::DXILAssembly: + { + List<uint8_t> code; + int err = emitDXILForEntryPointUsingDXC(entryPoint, targetReq, code); + if (!err) + { + String assembly = dissassembleDXILUsingDXC( + compileRequest, + code.Buffer(), + code.Count()); + + maybeDumpIntermediate(compileRequest, assembly.Buffer(), target); + + result = CompileResult(assembly); + } + } + break; +#endif + case CodeGenTarget::SPIRV: { List<uint8_t> code = emitSPIRVForEntryPoint(entryPoint, targetReq); @@ -703,6 +757,17 @@ namespace Slang break; #endif + #if SLANG_ENABLE_DXIL_SUPPORT + case CodeGenTarget::DXIL: + { + String assembly = dissassembleDXILUsingDXC(compileRequest, + data.begin(), + data.end() - data.begin()); + writeOutputToConsole(compileRequest, assembly); + } + break; + #endif + case CodeGenTarget::SPIRV: { String assembly = dissassembleSPIRV(compileRequest, @@ -943,6 +1008,20 @@ namespace Slang } break; #endif + + #if SLANG_ENABLE_DXIL_SUPPORT + case CodeGenTarget::DXILAssembly: + dumpIntermediateText(compileRequest, data, size, ".dxil.asm"); + break; + + case CodeGenTarget::DXIL: + dumpIntermediateBinary(compileRequest, data, size, ".dxil"); + { + String dxilAssembly = dissassembleDXILUsingDXC(compileRequest, data, size); + dumpIntermediateText(compileRequest, dxilAssembly.begin(), dxilAssembly.Length(), ".dxil.asm"); + } + break; + #endif } } |
