[Piglit] [PATCH] gs: less demanding tests for triangle strips.

Paul Berry stereotype441 at gmail.com
Wed Aug 28 13:59:24 PDT 2013


Commit 2ef33fd introduced some fairly demanding tests to verify that
for each possible input primitive type, vertices are delivered to the
geometry shader in the proper order.

Some hardware may not be able to satisfy all of OpenGL's ordering
requirements for GL_TRIANGLE_STRIP and GL_TRIANGLE_STRIP_ADJACENCY (in
particular, Intel Ivy Bridge requires some workarounds, and I haven't
yet determined whether those workarounds are possible in all
circumstances).

In case the implementation can't get the ordering exactly right, we
still want to make sure that (a) triangle orientation is correct, and
(b) with GL_TRIANGLE_STRIP_ADJACENCY, adjacent vertices are correctly
ordered relative to the primary triangle vertices.
---
 .../triangle-strip-adj-orientation.shader_test     |  92 ++++++++++++++++
 .../geometry/triangle-strip-adj.shader_test        | 118 +++++++++++++++++++++
 .../triangle-strip-orientation.shader_test         |  60 +++++++++++
 3 files changed, 270 insertions(+)
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj-orientation.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj.shader_test
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/triangle-strip-orientation.shader_test

diff --git a/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj-orientation.shader_test b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj-orientation.shader_test
new file mode 100644
index 0000000..c4863a8
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj-orientation.shader_test
@@ -0,0 +1,92 @@
+# Check that triangles delivered to the geometry shader using
+# GL_TRIANGLE_STRIP_ADJACENCY have the correct orientation.
+#
+# This test works by rendering 4 triangles with adjacency in a strip
+# and using gl_FrontFacing to check that they all have the same
+# orientation.
+#
+# The layout of the vertices in space is chosen to match the drawing
+# in section 10.1.13 (Triangles with Adjacency) of the GL 4.4 spec,
+# namely:
+#
+#     6  10
+#     |\ |\
+#     | \| \
+#  2--3--7--11
+#   \ |\ |\ |\
+#    \| \| \| \
+#     1--5--9--12
+#      \ |\ |
+#       \| \|
+#        4  8
+#
+# Note that in this diagram, the first triangle is clockwise, so we
+# expect gl_FrontFacing to be false for all triangles.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+out vec4 vertex_to_gs;
+
+void main()
+{
+  vertex_to_gs = vertex;
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles_adjacency) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in vec4 vertex_to_gs[6];
+
+void main()
+{
+  for (int i = 0; i < 3; i++) {
+    gl_Position = vertex_to_gs[2*i];
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+void main()
+{
+  if (!gl_FrontFacing)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2
+-0.5 -0.25 #1
+-1.0  0.25 #2
+-0.5  0.25 #3
+ 0.0 -0.75 #4
+ 0.0 -0.25 #5
+-0.5  0.75 #6
+ 0.0  0.25 #7
+ 0.5 -0.75 #8
+ 0.5 -0.25 #9
+ 0.0  0.75 #10
+ 0.5  0.25 #11
+ 1.0 -0.25 #12
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+draw arrays GL_TRIANGLE_STRIP_ADJACENCY 0 12
+
+# Probe inside each triangle
+relative probe rgba (0.33, 0.46) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.42, 0.54) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.58, 0.46) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.67, 0.54) (0.0, 1.0, 0.0, 1.0)
diff --git a/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj.shader_test b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj.shader_test
new file mode 100644
index 0000000..e9bab12
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-adj.shader_test
@@ -0,0 +1,118 @@
+# Check that triangles delivered to the geometry shader using
+# GL_TRIANGLE_STRIP_ADJACENCY have correct adjacency information.
+#
+# This test works by rendering 4 triangles with adjacency in a strip
+# and examining the relationship between the 6 vertices to each
+# geometry shader invocation.
+#
+# The layout of the vertices in space is chosen to match the drawing
+# in section 10.1.13 (Triangles with Adjacency) of the GL 4.4 spec,
+# namely (vertices count from 1 to match the diagram in the spec):
+#
+#     6  10
+#     |\ |\
+#     | \| \
+#  2--3--7--11
+#   \ |\ |\ |\
+#    \| \| \| \
+#     1--5--9--12
+#      \ |\ |
+#       \| \|
+#        4  8
+#
+# A given geometry shader invocation should see a pattern like this
+# (vertices count from 0 to match array indices in the geometry shader):
+#
+#  1--2--3
+#   \ |\ |
+#    \| \|
+#     0--4
+#      \ |
+#       \|
+#        5
+#
+# Therefore, the following mathematical relationships should be satisfied:
+#
+# v2 - v1 = v3 - v2 = v4 - v0
+# v0 - v1 = v4 - v2 = v5 - v0
+# v0 - v2 = v4 - v3 = v5 - v4
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+out vec4 v;
+
+void main()
+{
+  v = vertex;
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles_adjacency) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in vec4 v[6];
+flat out int pass_to_fs;
+
+void main()
+{
+  bool pass = true;
+  if (distance(v[2] - v[1], v[3] - v[2]) > 1e-5) pass = false;
+  if (distance(v[3] - v[2], v[4] - v[0]) > 1e-5) pass = false;
+  if (distance(v[0] - v[1], v[4] - v[2]) > 1e-5) pass = false;
+  if (distance(v[4] - v[2], v[5] - v[0]) > 1e-5) pass = false;
+  if (distance(v[0] - v[2], v[4] - v[3]) > 1e-5) pass = false;
+  if (distance(v[4] - v[3], v[5] - v[4]) > 1e-5) pass = false;
+
+  for (int i = 0; i < 3; i++) {
+    gl_Position = v[2*i];
+    pass_to_fs = int(pass);
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+flat in int pass_to_fs;
+
+void main()
+{
+  if (pass_to_fs != 0)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2
+-0.5 -0.25 #1
+-1.0  0.25 #2
+-0.5  0.25 #3
+ 0.0 -0.75 #4
+ 0.0 -0.25 #5
+-0.5  0.75 #6
+ 0.0  0.25 #7
+ 0.5 -0.75 #8
+ 0.5 -0.25 #9
+ 0.0  0.75 #10
+ 0.5  0.25 #11
+ 1.0 -0.25 #12
+
+[test]
+clear color 0.0 0.0 0.0 0.0
+clear
+draw arrays GL_TRIANGLE_STRIP_ADJACENCY 0 12
+
+# Probe inside each triangle
+relative probe rgba (0.33, 0.46) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.42, 0.54) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.58, 0.46) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.67, 0.54) (0.0, 1.0, 0.0, 1.0)
diff --git a/tests/spec/glsl-1.50/execution/geometry/triangle-strip-orientation.shader_test b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-orientation.shader_test
new file mode 100644
index 0000000..5c9a459
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/triangle-strip-orientation.shader_test
@@ -0,0 +1,60 @@
+# Check that triangles delivered to the geometry shader using
+# GL_TRIANGLE_STRIP have the correct orientation.
+#
+# It works by rendering 4 triangles in a strip and using
+# gl_FrontFacing to check that they all have the same orientation.
+
+[require]
+GL >= 2.0
+GLSL >= 1.50
+
+[vertex shader]
+#version 150
+
+in vec4 vertex;
+out vec4 vertex_to_gs;
+
+void main()
+{
+  vertex_to_gs = vertex;
+}
+
+[geometry shader]
+#version 150
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+in vec4 vertex_to_gs[3];
+
+void main()
+{
+  for (int i = 0; i < 3; i++) {
+    gl_Position = vertex_to_gs[i];
+    EmitVertex();
+  }
+}
+
+[fragment shader]
+#version 150
+
+void main()
+{
+  if (gl_FrontFacing)
+    gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+  else
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2
+-1.0 -1.0
+ 1.0 -1.0
+-1.0  0.0
+ 1.0  0.0
+-1.0  1.0
+ 1.0  1.0
+
+[test]
+draw arrays GL_TRIANGLE_STRIP 0 6
+probe all rgba 0.0 1.0 0.0 1.0
-- 
1.8.4



More information about the Piglit mailing list