[Piglit] [PATCH] glsl-1.40: Add a test for vertex shaders that don't write gl_Position.
Eric Anholt
eric at anholt.net
Mon Mar 19 23:05:52 PDT 2012
Transform feedback is used to get a testable output, and it's this
possibility of using vertex shader execution without rasterization
that led to the change in the spec.
---
tests/all.tests | 1 +
tests/spec/CMakeLists.txt | 1 +
tests/spec/glsl-1.40/CMakeLists.gl.txt | 18 +++++
tests/spec/glsl-1.40/CMakeLists.txt | 1 +
tests/spec/glsl-1.40/tf-no-position.c | 126 ++++++++++++++++++++++++++++++++
5 files changed, 147 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/glsl-1.40/CMakeLists.gl.txt
create mode 100644 tests/spec/glsl-1.40/CMakeLists.txt
create mode 100644 tests/spec/glsl-1.40/tf-no-position.c
diff --git a/tests/all.tests b/tests/all.tests
index 77a0f6a..f446c7b 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -989,6 +989,7 @@ add_shader_test_dir(spec['glsl-1.40'],
os.path.join(testsDir, 'spec', 'glsl-1.40'),
recursive=True)
spec['glsl-1.40']['execution']['textureSize'] = Group()
+spec['glsl-1.40']['execution']['tf-no-position'] = concurrent_test('glsl-1.40-tf-no-position')
textureSize_samplers_140 = textureSize_samplers_130 + ['sampler2DRect', 'isampler2DRect', 'sampler2DRectShadow', 'samplerBuffer', 'isamplerBuffer', 'usamplerBuffer']
for stage in ['vs', 'fs']:
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 93f0681..29dcf0f 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -37,6 +37,7 @@ add_subdirectory (arb_copy_buffer)
add_subdirectory (glsl-1.10)
add_subdirectory (glsl-1.20)
add_subdirectory (glsl-1.30)
+add_subdirectory (glsl-1.40)
add_subdirectory (gl-2.0)
add_subdirectory (gl-2.1)
add_subdirectory (gl-3.0)
diff --git a/tests/spec/glsl-1.40/CMakeLists.gl.txt b/tests/spec/glsl-1.40/CMakeLists.gl.txt
new file mode 100644
index 0000000..0d57dbc
--- /dev/null
+++ b/tests/spec/glsl-1.40/CMakeLists.gl.txt
@@ -0,0 +1,18 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+ ${GLUT_INCLUDE_DIR}
+ ${piglit_SOURCE_DIR}/tests/spec/arb_color_buffer_float
+ ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+ piglitutil
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+ ${GLUT_glut_LIBRARY}
+)
+
+add_executable (glsl-1.40-tf-no-position tf-no-position.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/glsl-1.40/CMakeLists.txt b/tests/spec/glsl-1.40/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/glsl-1.40/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/glsl-1.40/tf-no-position.c b/tests/spec/glsl-1.40/tf-no-position.c
new file mode 100644
index 0000000..821f524
--- /dev/null
+++ b/tests/spec/glsl-1.40/tf-no-position.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2012 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 tf-no-position.c
+ *
+ * Verify that we can render without specifying a gl_Position, by
+ * using EXT_transform_feedback to get results.
+ */
+
+#include "piglit-util.h"
+
+#define BUFFER_SIZE 4
+
+int piglit_width = 10;
+int piglit_height = 10;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
+
+static const char *vs_source =
+ "#version 140\n"
+ "in uint i;\n"
+ "flat out uint o;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " o = i;\n"
+ "}\n";
+
+enum piglit_result piglit_display(void)
+{
+ return PIGLIT_FAIL; /* UNREACHED */
+}
+
+void piglit_init(int argc, char **argv)
+{
+ GLuint vs;
+ GLuint *readback;
+ GLuint buffer[BUFFER_SIZE];
+ GLuint expected[BUFFER_SIZE];
+ int i;
+ bool pass = true;
+ GLint input_index;
+ GLuint prog;
+ GLuint xfb_buf;
+ GLuint verts[4] = { 0, 1, 2, 3 };
+ const char *varying = "o";
+
+ piglit_require_GLSL_version(140);
+ piglit_require_gl_version(30);
+ piglit_require_transform_feedback();
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+ if (!vs)
+ piglit_report_result(PIGLIT_FAIL);
+
+ prog = piglit_CreateProgram();
+ piglit_AttachShader(prog, vs);
+ piglit_TransformFeedbackVaryings(prog, 1, &varying,
+ GL_INTERLEAVED_ATTRIBS);
+ piglit_LinkProgram(prog);
+ if (!piglit_link_check_status(prog))
+ piglit_report_result(PIGLIT_FAIL);
+ glGenBuffers(1, &xfb_buf);
+ if (!piglit_check_gl_error(0))
+ piglit_report_result(PIGLIT_FAIL);
+
+ input_index = glGetAttribLocation(prog, "i");
+
+ piglit_UseProgram(prog);
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glVertexAttribIPointer(input_index, 1, GL_UNSIGNED_INT,
+ sizeof(GLuint), &verts);
+ glEnableVertexAttribArray(input_index);
+ pass = piglit_check_gl_error(0) && pass;
+
+ glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, xfb_buf);
+ memset(buffer, 0xd0, sizeof(buffer));
+ glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(buffer), buffer,
+ GL_STREAM_READ);
+ piglit_BindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, xfb_buf,
+ 0,
+ sizeof(buffer));
+ piglit_BeginTransformFeedback(GL_POINTS);
+ glDrawArrays(GL_POINTS, 0, ARRAY_SIZE(verts));
+ piglit_EndTransformFeedback();
+
+ readback = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY);
+
+ /* Check output */
+ for (i = 0; i < BUFFER_SIZE; ++i) {
+ if (verts[i] != readback[i]) {
+ printf("readback[%u]: %u, expected: %u\n", i,
+ readback[i], expected[i]);
+ pass = false;
+ }
+ }
+
+ /* Note that rasterization occurred, but the results were
+ * undefined due to gl_Position not being written. We do want
+ * to have rasterization occur (as opposed to just transform
+ * feedback) just to make sure the GPU didn't wedge or
+ * anything.
+ */
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
1.7.9.1
More information about the Piglit
mailing list