[Piglit] [PATCH v2] Transform feedback: Modify tessellation test to verify primitive count.

Paul Berry stereotype441 at gmail.com
Wed Jan 11 11:22:55 PST 2012


This patch modifies the transform feedback tessellation test to check
that the queries GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN and
GL_PRIMITIVES_GENERATED count the correct number of primitives for all
primitive types.  Previously, we were only testing correct behavior of
GL_TRANSFORM_FEEDBACK_PRIMITIVES and GL_PRIMITIVES_GENERATED in the
"position" test, which always draws triangles.

Verified that these tests still pass on the nVidia proprietary Linux
driver.

v2: Add GL_PRIMITIVES_GENERATED too.
---
 tests/spec/ext_transform_feedback/tessellation.c |   40 +++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/tests/spec/ext_transform_feedback/tessellation.c b/tests/spec/ext_transform_feedback/tessellation.c
index e527a9d..c85b241 100644
--- a/tests/spec/ext_transform_feedback/tessellation.c
+++ b/tests/spec/ext_transform_feedback/tessellation.c
@@ -129,6 +129,7 @@ static GLenum draw_mode;
 static GLenum xfb_mode;
 static unsigned num_input_vertices;
 static unsigned expected_num_output_vertices;
+static unsigned expected_num_output_primitives;
 static float (*vertex_positions)[2];
 static GLboolean monochrome;
 static GLboolean use_flat_color;
@@ -139,6 +140,8 @@ static GLboolean is_deprecated_draw_mode;
 static GLuint normal_prog;
 static GLuint xfb_prog;
 static GLuint xfb_buf;
+static GLuint xfb_generated_query;
+static GLuint xfb_written_query;
 static float vertex_colors[][4] = {
 	{ 0.00, 0.00, 0.00, 0.00 },
 	{ 1.00, 0.25, 0.25, 1.00 },
@@ -313,6 +316,8 @@ initialize_shader_and_xfb()
 		piglit_report_result(PIGLIT_FAIL);
 	}
 	glGenBuffers(1, &xfb_buf);
+	glGenQueries(1, &xfb_generated_query);
+	glGenQueries(1, &xfb_written_query);
 	glFrontFace(GL_CW);
 	if (!piglit_check_gl_error(0))
 		piglit_report_result(PIGLIT_FAIL);
@@ -429,10 +434,16 @@ draw(GLuint prog, bool use_xfb, float y_offset, GLenum mode,
 		piglit_BindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0,
 				      xfb_buf);
 		piglit_BeginTransformFeedback(xfb_mode);
+		glBeginQuery(GL_PRIMITIVES_GENERATED, xfb_generated_query);
+		glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
+			     xfb_written_query);
 	}
 	glDrawArrays(mode, 0, num_vertices);
-	if (use_xfb)
+	if (use_xfb) {
 		piglit_EndTransformFeedback();
+		glEndQuery(GL_PRIMITIVES_GENERATED);
+		glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
+	}
 	if (!piglit_check_gl_error(0))
 		piglit_report_result(PIGLIT_FAIL);
 }
@@ -472,6 +483,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_POINTS;
 		num_input_vertices = 4;
 		expected_num_output_vertices = 4;
+		expected_num_output_primitives = 4;
 		vertex_positions = points_vertices;
 	} else if (strcmp(argv[1], "lines") == 0) {
 		draw_mode = GL_LINES;
@@ -479,6 +491,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_LINES;
 		num_input_vertices = 4;
 		expected_num_output_vertices = 4;
+		expected_num_output_primitives = 2;
 		vertex_positions = lines_vertices;
 	} else if (strcmp(argv[1], "line_loop") == 0) {
 		draw_mode = GL_LINE_LOOP;
@@ -486,6 +499,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_LINES;
 		num_input_vertices = 4;
 		expected_num_output_vertices = 8;
+		expected_num_output_primitives = 4;
 		vertex_positions = line_loop_vertices;
 	} else if (strcmp(argv[1], "line_strip") == 0) {
 		draw_mode = GL_LINE_STRIP;
@@ -493,6 +507,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_LINES;
 		num_input_vertices = 4;
 		expected_num_output_vertices = 6;
+		expected_num_output_primitives = 3;
 		vertex_positions = line_strip_vertices;
 	} else if (strcmp(argv[1], "triangles") == 0) {
 		draw_mode = GL_TRIANGLES;
@@ -500,6 +515,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 6;
 		expected_num_output_vertices = 6;
+		expected_num_output_primitives = 2;
 		vertex_positions = triangles_vertices;
 	} else if (strcmp(argv[1], "triangle_strip") == 0) {
 		draw_mode = GL_TRIANGLE_STRIP;
@@ -507,6 +523,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 5;
 		expected_num_output_vertices = 9;
+		expected_num_output_primitives = 3;
 		vertex_positions = triangle_strip_vertices;
 	} else if (strcmp(argv[1], "triangle_fan") == 0) {
 		draw_mode = GL_TRIANGLE_FAN;
@@ -514,6 +531,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 5;
 		expected_num_output_vertices = 9;
+		expected_num_output_primitives = 3;
 		vertex_positions = triangle_fan_vertices;
 	} else if (strcmp(argv[1], "quads") == 0) {
 		draw_mode = GL_QUADS;
@@ -521,6 +539,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 8;
 		expected_num_output_vertices = 12;
+		expected_num_output_primitives = 4;
 		vertex_positions = quads_vertices;
 	} else if (strcmp(argv[1], "quad_strip") == 0) {
 		draw_mode = GL_QUAD_STRIP;
@@ -528,6 +547,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 6;
 		expected_num_output_vertices = 12;
+		expected_num_output_primitives = 4;
 		vertex_positions = quad_strip_vertices;
 	} else if (strcmp(argv[1], "polygon") == 0) {
 		draw_mode = GL_POLYGON;
@@ -535,6 +555,7 @@ piglit_init(int argc, char **argv)
 		xfb_mode = GL_TRIANGLES;
 		num_input_vertices = 5;
 		expected_num_output_vertices = 9;
+		expected_num_output_primitives = 3;
 		vertex_positions = polygon_vertices;
 	} else {
 		print_usage_and_exit(argv[0]);
@@ -581,6 +602,8 @@ enum piglit_result piglit_display(void)
 	unsigned num_output_vertices;
 	GLboolean pass = GL_TRUE;
 	GLboolean warn = GL_FALSE;
+	GLuint num_generated_primitives;
+	GLuint num_written_primitives;
 
 	initialize_vertex_shader_inputs();
 
@@ -601,6 +624,21 @@ enum piglit_result piglit_display(void)
 		       expected_num_output_vertices, num_output_vertices);
 		pass = GL_FALSE;
 	}
+	glGetQueryObjectuiv(xfb_generated_query, GL_QUERY_RESULT,
+			    &num_generated_primitives);
+	if (num_generated_primitives != expected_num_output_primitives) {
+		printf("Expected %u primitives generated, but got %u\n",
+		       expected_num_output_primitives,
+		       num_generated_primitives);
+		pass = GL_FALSE;
+	}
+	glGetQueryObjectuiv(xfb_written_query, GL_QUERY_RESULT,
+			    &num_written_primitives);
+	if (num_written_primitives != expected_num_output_primitives) {
+		printf("Expected %u primitives written, but got %u\n",
+		       expected_num_output_primitives, num_written_primitives);
+		pass = GL_FALSE;
+	}
 
 	memcpy(verts, readback, sizeof(verts));
 	glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);
-- 
1.7.6.5



More information about the Piglit mailing list