summaryrefslogtreecommitdiff
path: root/source/slang/slang-compiler.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2019-11-14 13:11:07 -0800
committerGitHub <noreply@github.com>2019-11-14 13:11:07 -0800
commitce4829b03622c7c23096253b0ee80b0fc923321e (patch)
treee1232ee908b2e3fa604d1c68c08ca4df4f4f8652 /source/slang/slang-compiler.cpp
parentd631233f4fcc2e41a9e7d7e0d3e277c90c81582b (diff)
Initial work on direct emission of SPIR-V (#1118)
* Initial work on direct emission of SPIR-V This change adds a first vertical slice of support for emitting SPIR-V code directly from the Slang IR, instead of generating it indirectly via GLSL. This work isn't usable for anything valuable right now; the goal is just to get something checked in that we can incrementally extend over time. When invoking `slangc`, the `-emit-spirv-directly` option can be used to turn on the new code path. I have not bothered to add an equivalent API option, because this flag is only intended to be used for testing in the immediate future. The existing `emitEntryPoint()` function has become `emitEntryPointSource()` to more accurately reflect its role in a world where we can also emit entry points to a binary format. Much of the logic that was inside `emitEntryPoint()` had to do with linking and then optimizing/transforming Slang IR code to get it ready for emission on a particular target. This logic has been factored into a new `linkAndOptimizeIR()` function that can be shared between the path that emits source and the new one that emits SPIR-V. The meat of the change is then the `emitSPIRVFromIR()` function in `slang-emit-spirv.cpp`, which is called *after* all the optimizations and transformations have been applied to the Slang IR to get it ready. Rather than repeat myself here, I will try to make the comments in `slang-emit-spirv.cpp` usable as documentation of the approach being taken. Smaller notes: * I've included a test case that compares `slangc` output directly to expected SPIR-V. This is perhaps not an ideal plan for how to test SPIR-V emission going forward, but it suffices for now. * The `external/` directory needed to be added to the include dirs for the `slang` project so that the new code can depend on the SPIR-V header. * In `slang-ir-link`, the direct SPIR-V generation path means that we now link with a target of SPIR-V instead of GLSL. In principle this can be used to ensure that appropriate variants of intrinsics are selected based on the knowledge that we are emitting SPIR-V. In practice, that isn't being used at all. * Fixup: path for SPIR-V headers While working on this PR I used a copy of `spirv.h` that I placed into the repository tree manually, but since I started the work we ended up with SPIR-V headers in our tree anyway, albeit at a different path. This change tries to fix things up so that my code uses the headers that were already placed in the repository. * fixup; 64-bit build issue * fixup: typo fixes based on review
Diffstat (limited to 'source/slang/slang-compiler.cpp')
-rw-r--r--source/slang/slang-compiler.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index ba2ad1dd8..2ab376181 100644
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -660,7 +660,7 @@ namespace Slang
}
else
{
- return emitEntryPoint(
+ return emitEntryPointSource(
compileRequest,
entryPointIndex,
CodeGenTarget::HLSL,
@@ -692,7 +692,7 @@ namespace Slang
}
else
{
- return emitEntryPoint(compileRequest, entryPointIndex, CodeGenTarget::CPPSource, targetReq);
+ return emitEntryPointSource(compileRequest, entryPointIndex, CodeGenTarget::CPPSource, targetReq);
}
}
@@ -732,7 +732,7 @@ namespace Slang
}
else
{
- return emitEntryPoint(
+ return emitEntryPointSource(
compileRequest,
entryPointIndex,
CodeGenTarget::GLSL,
@@ -1624,7 +1624,13 @@ SlangResult dissassembleDXILUsingDXC(
return SLANG_OK;
}
- SlangResult emitSPIRVForEntryPoint(
+ SlangResult emitSPIRVForEntryPointDirectly(
+ BackEndCompileRequest* compileRequest,
+ Int entryPointIndex,
+ TargetRequest* targetReq,
+ List<uint8_t>& spirvOut);
+
+ SlangResult emitSPIRVForEntryPointViaGLSL(
BackEndCompileRequest* slangRequest,
EntryPoint* entryPoint,
Int entryPointIndex,
@@ -1663,6 +1669,34 @@ SlangResult dissassembleDXILUsingDXC(
return SLANG_OK;
}
+ SlangResult emitSPIRVForEntryPoint(
+ BackEndCompileRequest* slangRequest,
+ EntryPoint* entryPoint,
+ Int entryPointIndex,
+ TargetRequest* targetReq,
+ EndToEndCompileRequest* endToEndReq,
+ List<uint8_t>& spirvOut)
+ {
+ if( slangRequest->shouldEmitSPIRVDirectly )
+ {
+ return emitSPIRVForEntryPointDirectly(
+ slangRequest,
+ entryPointIndex,
+ targetReq,
+ spirvOut);
+ }
+ else
+ {
+ return emitSPIRVForEntryPointViaGLSL(
+ slangRequest,
+ entryPoint,
+ entryPointIndex,
+ targetReq,
+ endToEndReq,
+ spirvOut);
+ }
+ }
+
SlangResult emitSPIRVAssemblyForEntryPoint(
BackEndCompileRequest* slangRequest,
EntryPoint* entryPoint,
@@ -1755,7 +1789,7 @@ SlangResult dissassembleDXILUsingDXC(
case CodeGenTarget::CPPSource:
case CodeGenTarget::CSource:
{
- return emitEntryPoint(
+ return emitEntryPointSource(
compileRequest,
entryPointIndex,
target,