summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-10 11:31:16 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-11 09:38:28 -0700
commitd86748d3e0767c01d9be6def86df63febb82c2eb (patch)
tree1ba432b042edcd38c1ba40d6cbc57cea55737bd5 /tests
parent7d2c2f1bf75ed89bc97f35d5b095356db9b2b725 (diff)
Don't emitting an imported declaration unless it is used.
This helps avoid the problem where we emit a function that does a `discard` and thus get a GLSL compilation failure in a vertex shader (that doesn't even call the function).
Diffstat (limited to 'tests')
-rw-r--r--tests/render/unused-discard.hlsl151
-rw-r--r--tests/render/unused-discard.slang27
2 files changed, 178 insertions, 0 deletions
diff --git a/tests/render/unused-discard.hlsl b/tests/render/unused-discard.hlsl
new file mode 100644
index 000000000..dad2f78e3
--- /dev/null
+++ b/tests/render/unused-discard.hlsl
@@ -0,0 +1,151 @@
+//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 unused_discard;
+
+#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);
+
+ doConditionalDiscard(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) \
+ layout(location = 0) 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);
+
+ doConditionalDiscard(color);
+
+ fragment_color = vec4(color, 1.0);
+}
+
+
+#endif
+
+#endif
diff --git a/tests/render/unused-discard.slang b/tests/render/unused-discard.slang
new file mode 100644
index 000000000..034735840
--- /dev/null
+++ b/tests/render/unused-discard.slang
@@ -0,0 +1,27 @@
+//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;
+}
+
+void doConditionalDiscard(float3 color)
+{
+ if(color.x < 0.5)
+ discard;
+}