summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/spirv/direct-spirv-emit.slang9
-rw-r--r--tests/spirv/direct-spirv-emit.slang.expected20
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/spirv/direct-spirv-emit.slang b/tests/spirv/direct-spirv-emit.slang
new file mode 100644
index 000000000..99507f795
--- /dev/null
+++ b/tests/spirv/direct-spirv-emit.slang
@@ -0,0 +1,9 @@
+// direct-spirv-emit.slang
+
+//TEST:SIMPLE:-target spirv -entry computeMain -stage compute -emit-spirv-directly
+
+// Test ability to directly output SPIR-V
+
+[numthreads(4,1,1)]
+void computeMain()
+{}
diff --git a/tests/spirv/direct-spirv-emit.slang.expected b/tests/spirv/direct-spirv-emit.slang.expected
new file mode 100644
index 000000000..28b7ed85a
--- /dev/null
+++ b/tests/spirv/direct-spirv-emit.slang.expected
@@ -0,0 +1,20 @@
+result code = 0
+standard error = {
+}
+standard output = {
+// Module Version 10400
+// Generated by (magic number): 0
+// Id's are bound by 5
+
+ Capability Shader
+ MemoryModel Logical GLSL450
+ EntryPoint GLCompute 2 "computeMain"
+ ExecutionMode 2 LocalSize 4 1 1
+ Name 2 "computeMain"
+ 1: TypeVoid
+ 3: TypeFunction 1
+ 2(computeMain): 1 Function None 3
+ 4: Label
+ Return
+ FunctionEnd
+}