[Piglit] [PATCH] gs: Test that gl_VerticesIn is correct for all input primitive types.

Paul Berry stereotype441 at gmail.com
Wed Jul 3 11:03:46 PDT 2013


---
 tests/all.tests                                    |   1 +
 .../execution/CMakeLists.gl.txt                    |   1 +
 .../arb_geometry_shader4/execution/vertices-in.c   | 150 +++++++++++++++++++++
 3 files changed, 152 insertions(+)
 create mode 100644 tests/spec/arb_geometry_shader4/execution/vertices-in.c

diff --git a/tests/all.tests b/tests/all.tests
index 5ff88f8..780e1e4 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2338,6 +2338,7 @@ for draw in ['', 'indexed']:
 add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-input-type')
 add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-input-type-draw')
 add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-output-type')
+add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-vertices-in')
 for mode in ['1', 'tf 1', 'max', 'tf max']:
 	add_concurrent_test(arb_geometry_shader4, 'arb_geometry_shader4-program-parameter-vertices-out {0}'.format(mode))
 spec['ARB_geometry_shader4'] = arb_geometry_shader4
diff --git a/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt b/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
index f61cae2..292ae8f 100644
--- a/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
+++ b/tests/spec/arb_geometry_shader4/execution/CMakeLists.gl.txt
@@ -11,3 +11,4 @@ link_libraries (
 )
 
 piglit_add_executable (arb_geometry_shader4-ignore-adjacent-vertices ignore-adjacent-vertices.c)
+piglit_add_executable (arb_geometry_shader4-vertices-in vertices-in.c)
diff --git a/tests/spec/arb_geometry_shader4/execution/vertices-in.c b/tests/spec/arb_geometry_shader4/execution/vertices-in.c
new file mode 100644
index 0000000..1ced7fe
--- /dev/null
+++ b/tests/spec/arb_geometry_shader4/execution/vertices-in.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/** @file vertices-in.c
+ *
+ * Check that the built-in geometry shader constant gl_VerticesIn has
+ * the correct value for all input primitive types.
+ *
+ * The test uses transform feedback to extract the value of
+ * gl_VerticesIn out of the shader.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 30;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char *vs_text =
+	"#version 130\n"
+	"void main()\n"
+	"{\n"
+	"  gl_Position = vec4(0.0);\n"
+	"}\n";
+
+static const char *gs_text =
+	"#version 130\n"
+	"#extension GL_ARB_geometry_shader4: require\n"
+	"out int vertices_in;\n"
+	"void main()\n"
+	"{\n"
+	"  vertices_in = gl_VerticesIn;\n"
+	"  EmitVertex();\n"
+	"}\n";
+
+static const char *varyings[] = { "vertices_in" };
+
+struct test_vector {
+	const char *name;
+	GLenum prim_type;
+	GLint vertices_in;
+} test_vectors[] = {
+	{ "GL_POINTS",              GL_POINTS,              1},
+	{ "GL_LINES",               GL_LINES,               2},
+	{ "GL_LINES_ADJACENCY",     GL_LINES_ADJACENCY,     4},
+	{ "GL_TRIANGLES",           GL_TRIANGLES,           3},
+	{ "GL_TRIANGLES_ADJACENCY", GL_TRIANGLES_ADJACENCY, 6}
+};
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLuint vs, gs, prog, buf;
+	int i;
+	GLint *ptr;
+	bool pass = true;
+
+	/* Requirements */
+	piglit_require_GLSL_version(130);
+	piglit_require_extension("GL_ARB_geometry_shader4");
+	piglit_require_extension("GL_EXT_transform_feedback");
+
+	/* Compile shaders, and prepare for linking.  We don't link
+	 * yet because we're going to need to change the input
+	 * primitive type inside the "for" loop below.
+	 */
+	prog = glCreateProgram();
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+	glAttachShader(prog, vs);
+	gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, gs_text);
+	glAttachShader(prog, gs);
+	glProgramParameteriARB(prog, GL_GEOMETRY_OUTPUT_TYPE_ARB, GL_POINTS);
+	glProgramParameteriARB(prog, GL_GEOMETRY_VERTICES_OUT_ARB, 1);
+	glTransformFeedbackVaryings(prog, 1, varyings,
+				    GL_INTERLEAVED_ATTRIBS_EXT);
+
+	/* Set up the transform feedback buffer. */
+	glGenBuffers(1, &buf);
+	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, buf);
+	glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, sizeof(GLint), NULL,
+		     GL_STREAM_READ);
+
+	/* Use GL_RASTERIZER_DISCARD, since we are going to use
+	 * transform feedback for this test.
+	 */
+	glEnable(GL_RASTERIZER_DISCARD);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+
+	for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
+		printf("Testing %s:\n", test_vectors[i].name);
+		glProgramParameteriARB(prog, GL_GEOMETRY_INPUT_TYPE_ARB,
+				       test_vectors[i].prim_type);
+		glLinkProgram(prog);
+		if (!piglit_link_check_status(prog))
+			piglit_report_result(PIGLIT_FAIL);
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			piglit_report_result(PIGLIT_FAIL);
+		glUseProgram(prog);
+		glBeginTransformFeedback(GL_POINTS);
+		glDrawArrays(test_vectors[i].prim_type, 0,
+			     test_vectors[i].vertices_in);
+		glEndTransformFeedback();
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			piglit_report_result(PIGLIT_FAIL);
+		ptr = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT,
+				  GL_READ_ONLY);
+		printf("  Expected gl_VerticesIn = %d, got %d\n",
+		       test_vectors[i].vertices_in, *ptr);
+		if (test_vectors[i].vertices_in != *ptr)
+			pass = false;
+		glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT);
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			piglit_report_result(PIGLIT_FAIL);
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Should never be reached */
+	return PIGLIT_FAIL;
+}
-- 
1.8.3.2



More information about the Piglit mailing list