From 7d3bfe403362b294cc2a1f2607d51dfcd447aafd Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 26 Jun 2017 09:32:40 -0700 Subject: Replace "auto-import" with `#import` Right now `#import` only differs from `#include` in that it takes a string literal for a file name instead of a raw identifier (to which `.slang` gets appended). The next step is to make `#import` respect preprocessor state, while `__import` doesn't. --- tests/render/auto-import.hlsl | 147 -------------------------------------- tests/render/auto-import.slang.h | 21 ------ tests/render/pound-import.hlsl | 147 ++++++++++++++++++++++++++++++++++++++ tests/render/pound-import.slang.h | 21 ++++++ 4 files changed, 168 insertions(+), 168 deletions(-) delete mode 100644 tests/render/auto-import.hlsl delete mode 100644 tests/render/auto-import.slang.h create mode 100644 tests/render/pound-import.hlsl create mode 100644 tests/render/pound-import.slang.h (limited to 'tests/render') diff --git a/tests/render/auto-import.hlsl b/tests/render/auto-import.hlsl deleted file mode 100644 index 588ebc612..000000000 --- a/tests/render/auto-import.hlsl +++ /dev/null @@ -1,147 +0,0 @@ -//TEST(smoke,render):COMPARE_HLSL_GLSL_RENDER: -xslang -auto-import-dir -xslang tests/render/ - -// This is a basic test case for cross-compilation behavior. -// -// We will define distinct HLSL and GLSL entry points, -// 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: -#include "auto-import.slang.h" - -#if defined(__HLSL__) - -cbuffer Uniforms -{ - float4x4 modelViewProjection; -}; - -struct AssembledVertex -{ - float3 position; - float3 color; -}; - -struct CoarseVertex -{ - float3 color; -}; - -struct Fragment -{ - float4 color; -}; - -// Vertex Shader - -struct VertexStageInput -{ - AssembledVertex assembledVertex : A; -}; - -struct VertexStageOutput -{ - CoarseVertex coarseVertex : CoarseVertex; - float4 sv_position : SV_Position; -}; - -VertexStageOutput vertexMain(VertexStageInput input) -{ - VertexStageOutput output; - - float3 position = input.assembledVertex.position; - float3 color = input.assembledVertex.color; - - output.coarseVertex.color = color; - output.sv_position = mul(modelViewProjection, float4(position, 1.0)); - - return output; - -} - -// Fragment Shader - -struct FragmentStageInput -{ - CoarseVertex coarseVertex : CoarseVertex; -}; - -struct FragmentStageOutput -{ - Fragment fragment : SV_Target; -}; - -FragmentStageOutput fragmentMain(FragmentStageInput input) -{ - FragmentStageOutput output; - - float3 color = input.coarseVertex.color; - - color = transformColor(color); - - output.fragment.color = float4(color, 1.0); - - return output; -} - -#elif defined(__GLSL__) - -#version 420 - -uniform Uniforms -{ - mat4x4 modelViewProjection; -}; - -#define ASSEMBLED_VERTEX(QUAL) \ - /* */ - -#define V2F(QUAL) \ - QUAL vec3 coarse_color; \ - /* */ - -// Vertex Shader - -#ifdef __GLSL_VERTEX__ - -layout(location = 0) -in vec3 assembled_position; - -layout(location = 1) -in vec3 assembled_color; - -V2F(out) - -void main() -{ - vec3 position = assembled_position; - vec3 color = assembled_color; - - coarse_color = color; -// gl_Position = modelViewProjection * vec4(position, 1.0); - gl_Position = vec4(position, 1.0) * modelViewProjection; -} - -#endif - -#ifdef __GLSL_FRAGMENT__ - -V2F(in) - -layout(location = 0) -out vec4 fragment_color; - -void main() -{ - vec3 color = coarse_color; - - color = transformColor(color); - - fragment_color = vec4(color, 1.0); -} - - -#endif - -#endif diff --git a/tests/render/auto-import.slang.h b/tests/render/auto-import.slang.h deleted file mode 100644 index d53005688..000000000 --- a/tests/render/auto-import.slang.h +++ /dev/null @@ -1,21 +0,0 @@ -//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 diff --git a/tests/render/pound-import.hlsl b/tests/render/pound-import.hlsl new file mode 100644 index 000000000..a9b625fb6 --- /dev/null +++ b/tests/render/pound-import.hlsl @@ -0,0 +1,147 @@ +//TEST(smoke,render):COMPARE_HLSL_GLSL_RENDER: + +// This is a basic test case for cross-compilation behavior. +// +// We will define distinct HLSL and GLSL entry points, +// 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 "pound-import.slang.h" + +#if defined(__HLSL__) + +cbuffer Uniforms +{ + float4x4 modelViewProjection; +}; + +struct AssembledVertex +{ + float3 position; + float3 color; +}; + +struct CoarseVertex +{ + float3 color; +}; + +struct Fragment +{ + float4 color; +}; + +// Vertex Shader + +struct VertexStageInput +{ + AssembledVertex assembledVertex : A; +}; + +struct VertexStageOutput +{ + CoarseVertex coarseVertex : CoarseVertex; + float4 sv_position : SV_Position; +}; + +VertexStageOutput vertexMain(VertexStageInput input) +{ + VertexStageOutput output; + + float3 position = input.assembledVertex.position; + float3 color = input.assembledVertex.color; + + output.coarseVertex.color = color; + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); + + return output; + +} + +// Fragment Shader + +struct FragmentStageInput +{ + CoarseVertex coarseVertex : CoarseVertex; +}; + +struct FragmentStageOutput +{ + Fragment fragment : SV_Target; +}; + +FragmentStageOutput fragmentMain(FragmentStageInput input) +{ + FragmentStageOutput output; + + float3 color = input.coarseVertex.color; + + color = transformColor(color); + + output.fragment.color = float4(color, 1.0); + + return output; +} + +#elif defined(__GLSL__) + +#version 420 + +uniform Uniforms +{ + mat4x4 modelViewProjection; +}; + +#define ASSEMBLED_VERTEX(QUAL) \ + /* */ + +#define V2F(QUAL) \ + QUAL vec3 coarse_color; \ + /* */ + +// Vertex Shader + +#ifdef __GLSL_VERTEX__ + +layout(location = 0) +in vec3 assembled_position; + +layout(location = 1) +in vec3 assembled_color; + +V2F(out) + +void main() +{ + vec3 position = assembled_position; + vec3 color = assembled_color; + + coarse_color = color; +// gl_Position = modelViewProjection * vec4(position, 1.0); + gl_Position = vec4(position, 1.0) * modelViewProjection; +} + +#endif + +#ifdef __GLSL_FRAGMENT__ + +V2F(in) + +layout(location = 0) +out vec4 fragment_color; + +void main() +{ + vec3 color = coarse_color; + + color = transformColor(color); + + fragment_color = vec4(color, 1.0); +} + + +#endif + +#endif diff --git a/tests/render/pound-import.slang.h b/tests/render/pound-import.slang.h new file mode 100644 index 000000000..d53005688 --- /dev/null +++ b/tests/render/pound-import.slang.h @@ -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 -- cgit v1.2.3