summaryrefslogtreecommitdiffstats
path: root/tests/render
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-12 12:26:12 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-13 13:53:47 -0700
commitd81c347e0edcbbf181885baf2b13978c28dfc9a8 (patch)
treeed48ba12c7db141d517b29343b9127692e72ad8c /tests/render
parenta14f3c50ef2cf7d3e34e729dfe10ce1cec880955 (diff)
First pass at support for cross-compilation
This is a large change that contains many pieces: - Update the `cross-compile0` test to actually make use of cross compilation. Now the `cross-compile0.hlsl` file contains both HLSL and GLSL source code, and then imports code from `cross-compile0.slang`, which provides a "library" (one function) that can be shared between both the HLSL and GLSL version of things. - Fixed a bug in the support for backslash-escaped newlines. - Added a new `__import` declaration type (replaces the `using` directive that was still around in a vestigial form) An `__import` causes the compiler to look for a Slang source file (currently using the ordinary `#include` lookup logic), and then parse/check the found file as an additional module ("translation unit"), before making its declarations visible in the current scope. - Refactored the main compilation flow to be simpler. There were the `ShaderCompiler` and `ShaderCompilerImpl` classes that weren't relaly doing anything, but added complexity to the whole workflow. - The `render-test` application has been heavily modified to better support testing cross-compilation workflows. At the most basic level we are starting to distinguish pass-through vs. rewriter workflows, and are passing various `#define`s down to the compiler(s) to let the source code be customized as needed for each case. Several annoying corner cases are caused here by having to support the GLSL compilation model, which really wants each entry point in its own specific translation unit, whereas we really want to keep things nicely contained in single files. - Added support for `__intrinsic` operations to have target-specific behavior. This allows a function to be given a different name for some specific target (so a call gets emitted as a call to that other operation). More generally, the library writer can put together an arbitrary format string that will be used in place of expressions that call the given function, e.g.: __intrinsic(hlsl, "$1 - $0") __intrinsic int foo(int a, int b); Given this declaration, a call like `foo(x,y)` will code generate as `x - y` for HLSL, and as `foo(x,y)` for all other targets. Annoying things still to be dealt with: - The way that I'm filtering the user-provided options when passing things down to the compilation of dynamically loaded modules is a bit ad hoc. It would be good to have a systematic notion of which options will be inherited and which won't. There is also more code duplication than I'd like, so we risk having the compiler behave differently when compiling a file at the top level, vs. because of `__import`. - Adding target-specific behavior to intrinsics is all well and good, but the current approach means we can only add this to the original declaration, which limits the ability to easily extend the set of targets. A better approach long-term would be to add a more robust notion of target-based overload resolution (which would happen after semantic checking). Then one mechanism would be used to find the right target-specific overload to use for an operation, and then each (target-specific) definition could use a simpler attribute to intercept code-generation behavior. Note that we might eventually need a similar notion to deal with stage- or profile-specific functions and the overloading behavior around them, so using this for intrinsics doesn't seem like a bad idea.
Diffstat (limited to 'tests/render')
-rw-r--r--tests/render/cross-compile0.hlsl8
-rw-r--r--tests/render/cross-compile0.slang21
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/render/cross-compile0.hlsl b/tests/render/cross-compile0.hlsl
index e41de7ef1..b482035d1 100644
--- a/tests/render/cross-compile0.hlsl
+++ b/tests/render/cross-compile0.hlsl
@@ -6,6 +6,10 @@
// but the two will share a dependency on a file of
// pure Spire code that provides the actual shading logic.
+
+// Pull in Spire code depdendency using extended syntax:
+__import cross_compile0;
+
#if defined(__HLSL__)
cbuffer Uniforms
@@ -74,6 +78,8 @@ FragmentStageOutput fragmentMain(FragmentStageInput input)
float3 color = input.coarseVertex.color;
+ color = transformColor(color);
+
output.fragment.color = float4(color, 1.0);
return output;
@@ -130,6 +136,8 @@ void main()
{
vec3 color = coarse_color;
+ color = transformColor(color);
+
fragment_color = vec4(color, 1.0);
}
diff --git a/tests/render/cross-compile0.slang b/tests/render/cross-compile0.slang
new file mode 100644
index 000000000..d53005688
--- /dev/null
+++ b/tests/render/cross-compile0.slang
@@ -0,0 +1,21 @@
+//TEST_IGNORE_FILE:
+
+// This file implements the "library" code
+// that both the HLSL and GLSL shaders share.
+//
+// This code is written in Slang (more or less
+// just HLSL), and will be translated as needed
+// for each of the targets.
+
+float3 transformColor(float3 color)
+{
+ float3 result;
+
+ result.x = sin(20.0 * (color.x + color.y));
+ result.y = saturate(cos(color.z * 30.0));
+ result.z = sin(color.x * color.y * color.z * 100.0);
+
+ result = 0.5 * (result + 1);
+
+ return result;
+} \ No newline at end of file