[Piglit] [PATCH 3/4] arb_tessellation_shader: test gl_PrimitiveID in instanced draws

Nicolai Hähnle nhaehnle at gmail.com
Wed May 3 09:52:22 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

These tests expose a couple of bugs related to gl_PrimitiveID in radeonsi
with tessellation enabled:

- garbage gl_PrimitiveID in fragment shader if no geometry shader is
  present
- gl_PrimitiveIDIn in geometry shaders is not reset at the start of an
  instance when instancing is used
- on SI (or possibly only Verde), gl_PrimitiveID in TCS and TES is not
  reset at the start of an instance when instancing is used
---
 .../execution/fs-primitiveid-instanced.shader_test | 79 +++++++++++++++++++
 .../execution/gs-primitiveid-instanced.shader_test | 87 ++++++++++++++++++++
 .../tcs-primitiveid-instanced.shader_test          | 92 ++++++++++++++++++++++
 .../tes-no-tcs-primitiveid-instanced.shader_test   | 66 ++++++++++++++++
 .../tes-primitiveid-instanced.shader_test          | 85 ++++++++++++++++++++
 5 files changed, 409 insertions(+)
 create mode 100644 tests/spec/arb_tessellation_shader/execution/fs-primitiveid-instanced.shader_test
 create mode 100644 tests/spec/arb_tessellation_shader/execution/gs-primitiveid-instanced.shader_test
 create mode 100644 tests/spec/arb_tessellation_shader/execution/tcs-primitiveid-instanced.shader_test
 create mode 100644 tests/spec/arb_tessellation_shader/execution/tes-no-tcs-primitiveid-instanced.shader_test
 create mode 100644 tests/spec/arb_tessellation_shader/execution/tes-primitiveid-instanced.shader_test

diff --git a/tests/spec/arb_tessellation_shader/execution/fs-primitiveid-instanced.shader_test b/tests/spec/arb_tessellation_shader/execution/fs-primitiveid-instanced.shader_test
new file mode 100644
index 0000000..be8b91e
--- /dev/null
+++ b/tests/spec/arb_tessellation_shader/execution/fs-primitiveid-instanced.shader_test
@@ -0,0 +1,79 @@
+# Test that the gl_PrimitiveID input in the FS is correctly set up and starts
+# at 0 for each instance in instanced draws.
+
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+#version 150
+
+out int vs_tcs_id;
+out int vs_tcs_instance;
+
+void main()
+{
+	vs_tcs_id = gl_VertexID;
+	vs_tcs_instance = gl_InstanceID;
+}
+
+[tessellation control shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(vertices = 1) out;
+in int vs_tcs_id[];
+in int vs_tcs_instance[];
+out vec2 tcs_tes_position[];
+
+void main()
+{
+	tcs_tes_position[gl_InvocationID].x = -1.0 + vs_tcs_id[gl_InvocationID];
+	tcs_tes_position[gl_InvocationID].y = -1.0 + vs_tcs_instance[gl_InvocationID];
+
+	gl_TessLevelInner[0] = 1.0;
+	gl_TessLevelInner[1] = 1.0;
+
+	gl_TessLevelOuter[0] = 1.0;
+	gl_TessLevelOuter[1] = 1.0;
+	gl_TessLevelOuter[2] = 1.0;
+	gl_TessLevelOuter[3] = 1.0;
+}
+
+[tessellation evaluation shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(quads, equal_spacing) in;
+
+in vec2 tcs_tes_position[];
+
+void main()
+{
+	gl_Position = vec4(tcs_tes_position[0].x + gl_TessCoord.x,
+			   tcs_tes_position[0].y + gl_TessCoord.y,
+			   0.0, 1.0);
+}
+
+[fragment shader]
+#version 150
+
+void main()
+{
+	gl_FragColor = vec4(0.0, 1.0, gl_PrimitiveID * 0.1, 1.0);
+}
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+
+patch parameter vertices 1
+draw arrays instanced GL_PATCHES 0 2 2
+
+# First instance
+relative probe rect rgba (0.0, 0.0, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.0, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
+
+# Second instance
+relative probe rect rgba (0.0, 0.5, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.5, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
diff --git a/tests/spec/arb_tessellation_shader/execution/gs-primitiveid-instanced.shader_test b/tests/spec/arb_tessellation_shader/execution/gs-primitiveid-instanced.shader_test
new file mode 100644
index 0000000..74d9c16
--- /dev/null
+++ b/tests/spec/arb_tessellation_shader/execution/gs-primitiveid-instanced.shader_test
@@ -0,0 +1,87 @@
+# Test that the gl_PrimitiveID input in the TES is correctly set up and starts
+# at 0 for each instance in instanced draws.
+
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+#version 150
+
+out int vs_tes_id;
+out int vs_tes_instance;
+
+void main()
+{
+	vs_tes_id = gl_VertexID;
+	vs_tes_instance = gl_InstanceID;
+}
+
+[tessellation evaluation shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(quads, equal_spacing) in;
+
+in int vs_tes_id[];
+in int vs_tes_instance[];
+
+void main()
+{
+	gl_Position = vec4(-1.0 + vs_tes_id[0] + gl_TessCoord.x,
+			   -1.0 + vs_tes_instance[0] + gl_TessCoord.y,
+			   0.0, 1.0);
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+out vec4 color;
+
+void main() {
+	vec4 tmp_color = vec4(0.0, 1.0, gl_PrimitiveIDIn * 0.1, 1.0);
+
+	color = tmp_color;
+	gl_Position = gl_in[0].gl_Position;
+	EmitVertex();
+
+	color = tmp_color;
+	gl_Position = gl_in[1].gl_Position;
+	EmitVertex();
+
+	color = tmp_color;
+	gl_Position = gl_in[2].gl_Position;
+	EmitVertex();
+}
+
+
+[fragment shader]
+#version 150
+
+in vec4 color;
+
+void main()
+{
+	gl_FragColor = color;
+}
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+
+patch parameter default level inner 1 1
+patch parameter default level outer 1 1 1 1
+
+patch parameter vertices 1
+draw arrays instanced GL_PATCHES 0 2 2
+
+# First instance
+relative probe rect rgba (0.0, 0.0, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.0, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
+
+# Second instance
+relative probe rect rgba (0.0, 0.5, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.5, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
diff --git a/tests/spec/arb_tessellation_shader/execution/tcs-primitiveid-instanced.shader_test b/tests/spec/arb_tessellation_shader/execution/tcs-primitiveid-instanced.shader_test
new file mode 100644
index 0000000..30f7d73
--- /dev/null
+++ b/tests/spec/arb_tessellation_shader/execution/tcs-primitiveid-instanced.shader_test
@@ -0,0 +1,92 @@
+# Test that the gl_PrimitiveID input in the TCS starts at 0 for each instance
+# in instanced draws.
+
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+#version 150
+
+out int vs_tcs_id;
+out int vs_tcs_instance;
+
+void main()
+{
+	vs_tcs_id = gl_VertexID;
+	vs_tcs_instance = gl_InstanceID;
+}
+
+[tessellation control shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(vertices = 1) out;
+in int vs_tcs_id[];
+in int vs_tcs_instance[];
+out vec4 tcs_tes_color[];
+out vec2 tcs_tes_position[];
+
+void main()
+{
+	tcs_tes_color[gl_InvocationID] = vec4(
+		0.5 + vs_tcs_id[gl_InvocationID] * 0.1,
+		0.5 + vs_tcs_instance[gl_InvocationID] * 0.1,
+		0.5 + gl_PrimitiveID * 0.1,
+		0.5 + gl_InvocationID * 0.1
+	);
+	tcs_tes_position[gl_InvocationID].x = -1.0 + vs_tcs_id[gl_InvocationID];
+	tcs_tes_position[gl_InvocationID].y = -1.0 + vs_tcs_instance[gl_InvocationID];
+
+	gl_TessLevelInner[0] = 1.0;
+	gl_TessLevelInner[1] = 1.0;
+
+	gl_TessLevelOuter[0] = 1.0;
+	gl_TessLevelOuter[1] = 1.0;
+	gl_TessLevelOuter[2] = 1.0;
+	gl_TessLevelOuter[3] = 1.0;
+}
+
+[tessellation evaluation shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(quads, equal_spacing) in;
+
+in vec4 tcs_tes_color[];
+in vec2 tcs_tes_position[];
+
+out vec4 color;
+
+void main()
+{
+	gl_Position = vec4(tcs_tes_position[0].x + gl_TessCoord.x,
+			   tcs_tes_position[0].y + gl_TessCoord.y,
+			   0.0, 1.0);
+	color = tcs_tes_color[0];
+}
+
+[fragment shader]
+#version 150
+
+in vec4 color;
+
+void main()
+{
+	gl_FragColor = color;
+}
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+
+patch parameter vertices 1
+draw arrays instanced GL_PATCHES 0 2 2
+
+# First instance
+relative probe rect rgba (0.0, 0.0, 0.5, 0.5) (0.5, 0.5, 0.5, 0.5)
+relative probe rect rgba (0.5, 0.0, 0.5, 0.5) (0.6, 0.5, 0.6, 0.5)
+
+# Second instance
+relative probe rect rgba (0.0, 0.5, 0.5, 0.5) (0.5, 0.6, 0.5, 0.5)
+relative probe rect rgba (0.5, 0.5, 0.5, 0.5) (0.6, 0.6, 0.6, 0.5)
diff --git a/tests/spec/arb_tessellation_shader/execution/tes-no-tcs-primitiveid-instanced.shader_test b/tests/spec/arb_tessellation_shader/execution/tes-no-tcs-primitiveid-instanced.shader_test
new file mode 100644
index 0000000..504f4e0
--- /dev/null
+++ b/tests/spec/arb_tessellation_shader/execution/tes-no-tcs-primitiveid-instanced.shader_test
@@ -0,0 +1,66 @@
+# Test that the gl_PrimitiveID input in the TES is correctly set up and starts
+# at 0 for each instance in instanced draws.
+
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+#version 150
+
+out int vs_tes_id;
+out int vs_tes_instance;
+
+void main()
+{
+	vs_tes_id = gl_VertexID;
+	vs_tes_instance = gl_InstanceID;
+}
+
+[tessellation evaluation shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(quads, equal_spacing) in;
+
+in int vs_tes_id[];
+in int vs_tes_instance[];
+
+out vec4 color;
+
+void main()
+{
+	gl_Position = vec4(-1.0 + vs_tes_id[0] + gl_TessCoord.x,
+			   -1.0 + vs_tes_instance[0] + gl_TessCoord.y,
+			   0.0, 1.0);
+
+	color = vec4(0.0, 1.0, gl_PrimitiveID * 0.1, 1.0);
+}
+
+[fragment shader]
+#version 150
+
+in vec4 color;
+
+void main()
+{
+	gl_FragColor = color;
+}
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+
+patch parameter default level inner 1 1
+patch parameter default level outer 1 1 1 1
+
+patch parameter vertices 1
+draw arrays instanced GL_PATCHES 0 2 2
+
+# First instance
+relative probe rect rgba (0.0, 0.0, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.0, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
+
+# Second instance
+relative probe rect rgba (0.0, 0.5, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.5, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
diff --git a/tests/spec/arb_tessellation_shader/execution/tes-primitiveid-instanced.shader_test b/tests/spec/arb_tessellation_shader/execution/tes-primitiveid-instanced.shader_test
new file mode 100644
index 0000000..e49977f
--- /dev/null
+++ b/tests/spec/arb_tessellation_shader/execution/tes-primitiveid-instanced.shader_test
@@ -0,0 +1,85 @@
+# Test that the gl_PrimitiveID input in the TES is correctly set up and starts
+# at 0 for each instance in instanced draws.
+
+[require]
+GLSL >= 1.50
+GL_ARB_tessellation_shader
+
+[vertex shader]
+#version 150
+
+out int vs_tcs_id;
+out int vs_tcs_instance;
+
+void main()
+{
+	vs_tcs_id = gl_VertexID;
+	vs_tcs_instance = gl_InstanceID;
+}
+
+[tessellation control shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(vertices = 1) out;
+in int vs_tcs_id[];
+in int vs_tcs_instance[];
+out vec2 tcs_tes_position[];
+
+void main()
+{
+	tcs_tes_position[gl_InvocationID].x = -1.0 + vs_tcs_id[gl_InvocationID];
+	tcs_tes_position[gl_InvocationID].y = -1.0 + vs_tcs_instance[gl_InvocationID];
+
+	gl_TessLevelInner[0] = 1.0;
+	gl_TessLevelInner[1] = 1.0;
+
+	gl_TessLevelOuter[0] = 1.0;
+	gl_TessLevelOuter[1] = 1.0;
+	gl_TessLevelOuter[2] = 1.0;
+	gl_TessLevelOuter[3] = 1.0;
+}
+
+[tessellation evaluation shader]
+#version 150
+#extension GL_ARB_tessellation_shader : require
+
+layout(quads, equal_spacing) in;
+
+in vec2 tcs_tes_position[];
+
+out vec4 color;
+
+void main()
+{
+	gl_Position = vec4(tcs_tes_position[0].x + gl_TessCoord.x,
+			   tcs_tes_position[0].y + gl_TessCoord.y,
+			   0.0, 1.0);
+
+	color = vec4(0.0, 1.0, gl_PrimitiveID * 0.1, 1.0);
+}
+
+[fragment shader]
+#version 150
+
+in vec4 color;
+
+void main()
+{
+	gl_FragColor = color;
+}
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+
+patch parameter vertices 1
+draw arrays instanced GL_PATCHES 0 2 2
+
+# First instance
+relative probe rect rgba (0.0, 0.0, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.0, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
+
+# Second instance
+relative probe rect rgba (0.0, 0.5, 0.5, 0.5) (0.0, 1.0, 0.0, 1.0)
+relative probe rect rgba (0.5, 0.5, 0.5, 0.5) (0.0, 1.0, 0.1, 1.0)
-- 
2.9.3



More information about the Piglit mailing list