On 4 November 2011 16:34, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
This test passes on AMD's closed-source driver. It fails on NVIDIA's<br>
closed-source driver because after the second glLinkProgram call,<br>
glGetFragDataLocation always returns -1.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
---<br>
tests/all.tests | 1 +<br>
tests/spec/gl-3.0/api/CMakeLists.gl.txt | 1 +<br>
tests/spec/gl-3.0/api/getfragdatalocation.c | 172 +++++++++++++++++++++++++++<br>
3 files changed, 174 insertions(+), 0 deletions(-)<br>
create mode 100644 tests/spec/gl-3.0/api/getfragdatalocation.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 9641281..0f712bd 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -795,6 +795,7 @@ add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')<br>
add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')<br>
add_concurrent_test(gl30, 'clearbuffer-depth')<br>
add_concurrent_test(gl30, 'clearbuffer-stencil')<br>
+add_concurrent_test(gl30, 'getfragdatalocation')<br>
<br>
# Group spec/glsl-1.00<br>
spec['glsl-1.00'] = Group()<br>
diff --git a/tests/spec/gl-3.0/api/CMakeLists.gl.txt b/tests/spec/gl-3.0/api/CMakeLists.gl.txt<br>
index 51fbce4..f1b7a45 100644<br>
--- a/tests/spec/gl-3.0/api/CMakeLists.gl.txt<br>
+++ b/tests/spec/gl-3.0/api/CMakeLists.gl.txt<br>
@@ -19,5 +19,6 @@ add_executable (clearbuffer-depth-stencil clearbuffer-common.c clearbuffer-depth<br>
add_executable (clearbuffer-invalid-drawbuffer clearbuffer-invalid-drawbuffer.c)<br>
add_executable (clearbuffer-invalid-buffer clearbuffer-invalid-buffer.c)<br>
add_executable (clearbuffer-stencil clearbuffer-common.c clearbuffer-stencil.c)<br>
+add_executable (getfragdatalocation getfragdatalocation.c)<br>
<br>
# vim: ft=cmake:<br>
diff --git a/tests/spec/gl-3.0/api/getfragdatalocation.c b/tests/spec/gl-3.0/api/getfragdatalocation.c<br>
new file mode 100644<br>
index 0000000..b091238<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.0/api/getfragdatalocation.c<br>
@@ -0,0 +1,172 @@<br>
+/* Copyright © 2011 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ */<br>
+<br>
+/**<br>
+ * \file getfragdatalocation.c<br>
+ *<br>
+ * \author Ian Romanick<br>
+ */<br>
+#include "piglit-util.h"<br>
+<br>
+int piglit_width = 100, piglit_height = 100;<br>
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;<br>
+<br>
+static const char *vs_text =<br>
+ "#version 130\n"<br>
+ "in vec4 vertex;\n"<br>
+ "void main() { gl_Position = vertex; }\n"<br>
+ ;<br>
+<br>
+static const char *fs_text =<br>
+ "#version 130\n"<br>
+ "out vec4 v;\n"<br>
+ "out vec4 a[2];\n"<br>
+ "void main() {\n"<br>
+ " v = vec4(0.0);\n"<br>
+ " a[0] = vec4(1.0);\n"<br>
+ " a[1] = vec4(2.0);\n"<br>
+ "}\n"<br>
+ ;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+ return PIGLIT_FAIL;<br>
+}<br>
+<br>
+void piglit_init(int argc, char **argv)<br>
+{<br>
+ GLint max_draw_buffers;<br>
+ GLuint prog;<br>
+ GLuint vs;<br>
+ GLuint fs;<br>
+ GLint loc;<br>
+<br>
+ piglit_require_gl_version(30);<br>
+<br>
+ /* This test needs some number of draw buffers, so make sure the<br>
+ * implementation isn't broken. This enables the test to generate a<br>
+ * useful failure message.<br>
+ */<br>
+ glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers);<br>
+ if (max_draw_buffers < 8) {<br>
+ fprintf(stderr,<br>
+ "OpenGL 3.0 requires GL_MAX_DRAW_BUFFERS >= 8. "<br>
+ "Only got %d!\n",<br>
+ max_draw_buffers);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ prog = glCreateProgram();<br>
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);<br>
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);<br>
+ glAttachShader(prog, vs);<br>
+ glAttachShader(prog, fs);<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ /* Page 237 (page 253 of the PDF) of the OpenGL 3.0 spec says:<br>
+ *<br>
+ * "If program has not been successfully linked, the error INVALID<br>
+ * OPERATION is generated. If name is not a varying out variable,<br>
+ * or if an error occurs, -1 will be returned."<br>
+ */<br>
+ printf("Querying location before linking...\n");<br>
+ loc = glGetFragDataLocation(prog, "v");<br>
+ piglit_check_gl_error(GL_INVALID_OPERATION, PIGLIT_FAIL);<br>
+<br>
+ if (loc != -1) {<br>
+ fprintf(stderr, "Expected location = -1, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ glLinkProgram(prog);<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (!piglit_link_check_status(prog)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ printf("Querying location of nonexistent variable...\n");<br>
+ loc = glGetFragDataLocation(prog, "waldo");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (loc != -1) {<br>
+ fprintf(stderr, "Expected location = -1, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ /* Page 236 (page 252 of the PDF) of the OpenGL 3.0 spec says:<br>
+ *<br>
+ * "BindFragDataLocation has no effect until the program is<br>
+ * linked. In particular, it doesn’t modify the bindings of<br>
+ * varying out variables in a program that has already been<br>
+ * linked."<br>
+ */<br>
+ glBindFragDataLocation(prog, 0, "v");<br>
+ glBindFragDataLocation(prog, 1, "a");<br>
+ glLinkProgram(prog);<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (!piglit_link_check_status(prog)) {<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ printf("Querying locations after binding and linking...\n");<br>
+ loc = glGetFragDataLocation(prog, "v");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (loc != 0) {<br>
+ fprintf(stderr, "Expected location = 0, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ loc = glGetFragDataLocation(prog, "a");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (loc != 1) {<br>
+ fprintf(stderr, "Expected location = 1, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ printf("Querying locations after just binding...\n");<br>
+ glBindFragDataLocation(prog, 2, "v");<br>
+ glBindFragDataLocation(prog, 0, "a");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ loc = glGetFragDataLocation(prog, "v");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (loc != 0) {<br>
+ fprintf(stderr, "Expected location = 0, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ loc = glGetFragDataLocation(prog, "a");<br>
+ piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);<br>
+<br>
+ if (loc != 1) {<br>
+ fprintf(stderr, "Expected location = 1, got %d\n", loc);<br>
+ piglit_report_result(PIGLIT_FAIL);<br>
+ }<br>
+<br>
+ piglit_report_result(PIGLIT_PASS);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.6.4</font></span><br></blockquote><div><br><br>The spec mentions one other behavior that would probably be worth testing, either in this test or elsewhere (emphasis mine):<br><br>"BindFragDataLocation may be issued before any shader objects are attached to a program object. Hence it is allowed to bind any name (except a name starting with gl_) to a color number, including a name that is never used as a varying out variable in any fragment shader object. *<b>Assigned bindings for variables that do not exist are ignored</b>*."<br>
<br>Other than that, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div></div>