<div dir="ltr">On 1 October 2013 18:22, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><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>
Separate shader objects can either connect outputs to inputs by matching<br>
names (rendezvous by name) or by assigning explicit locations via the<br>
layout(location=...) (rendezvous by location).  This is a simple test<br>
that a vertex shader with a different name than the fragment shader<br>
input can by matched by the location.<br>
<br>
v2: Fix some dumb bugs in the test.  Use multiple values to ensure we're<br>
not matching using rendezvous-by-dumb-luck.<br>
<br>
v3:<br>
* Fix a bug in the ordering of cross product parameters.  Noticed by<br>
  Paul.<br>
* Add another test case where the fragment shader variables are listed<br>
  in a different order.  Add some explanitory text with rationalization<br>
  for the tests chosen.<br>
* Dynamically set the #version line depending on driver support.  This<br>
  works around some bugs in the NVIDIA driver noticed by Paul.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 tests/all.tests                                    |   1 +<br>
 .../arb_separate_shader_objects/CMakeLists.gl.txt  |   1 +<br>
 .../rendezvous_by_location.c                       | 202 +++++++++++++++++++++<br>
 3 files changed, 204 insertions(+)<br>
 create mode 100644 tests/spec/arb_separate_shader_objects/rendezvous_by_location.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index e0cdc8b..33556af 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1277,6 +1277,7 @@ arb_separate_shader_objects['IsProgramPipeline'] = concurrent_test('arb_separate<br>
 arb_separate_shader_objects['UseProgramStages - non-separable program'] = concurrent_test('arb_separate_shader_object-UseProgramStages-non-separable')<br>
 arb_separate_shader_objects['Mix BindProgramPipeline and UseProgram'] = concurrent_test('arb_separate_shader_object-mix_pipeline_useprogram')<br>
 arb_separate_shader_objects['ProgramUniform coverage'] = concurrent_test('arb_separate_shader_object-ProgramUniform-coverage')<br>
+arb_separate_shader_objects['Rendezvous by location'] = plain_test('arb_separate_shader_object-rendezvous_by_location -fbo')<br>
 arb_separate_shader_objects['ValidateProgramPipeline'] = concurrent_test('arb_separate_shader_object-ValidateProgramPipeline')<br>
<br>
 # Group ARB_sampler_objects<br>
diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
index 0ed3e2f..32a28ba 100644<br>
--- a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
@@ -13,5 +13,6 @@ piglit_add_executable (arb_separate_shader_object-GetProgramPipelineiv GetProgra<br>
 piglit_add_executable (arb_separate_shader_object-IsProgramPipeline IsProgramPipeline.c)<br>
 piglit_add_executable (arb_separate_shader_object-mix_pipeline_useprogram mix_pipeline_useprogram.c)<br>
 piglit_add_executable (arb_separate_shader_object-ProgramUniform-coverage ProgramUniform-coverage.c)<br>
+piglit_add_executable (arb_separate_shader_object-rendezvous_by_location rendezvous_by_location.c)<br>
 piglit_add_executable (arb_separate_shader_object-UseProgramStages-non-separable UseProgramStages-non-separable.c)<br>
 piglit_add_executable (arb_separate_shader_object-ValidateProgramPipeline ValidateProgramPipeline.c)<br>
diff --git a/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c b/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c<br>
new file mode 100644<br>
index 0000000..4193ea5<br>
--- /dev/null<br>
+++ b/tests/spec/arb_separate_shader_objects/rendezvous_by_location.c<br>
@@ -0,0 +1,202 @@<br>
+/*<br>
+ * Copyright © 2013 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 rendezvous_by_location.c<br>
+ * Simple test for separate shader objects that use rendezvous-by-location.<br>
+ *<br>
+ * There are two ways one might expect rendezvous-by-location to fail.  One<br>
+ * predicatble failure mode is for variables between two program objects to be<br>
+ * linked in the order they appear in the shader text.  Another predicatble<br>
+ * failure mode is for variables between two program objects to be linked by<br>
+ * name.<br>
+ *<br>
+ * This test tries both modes using a single fragement shader program.  This<br>
+ * program outputs two varibles, a and b, with locations specified.  Two<br>
+ * fragment shader programs are created, each having input variables a and b,<br>
+ * with locations specified.  In the first case, a and b are listed in the<br>
+ * same order as in the vertex shader, but the locations are reversed (vertex<br>
+ * shader output a has the location of fragment shader input b).  In the<br>
+ * second case, a and b are list in the reverse order as in the vertex shader.<br>
+ * However, the assigned locations are the same as in the other fragment<br>
+ * shader.<br>
+ */<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_compat_version = 10;<br>
+       config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLuint pipeline_same_declaration_order;<br>
+static GLuint pipeline_same_location_order;<br>
+<br>
+static const char *vs_code_template =<br>
+       "#version %d\n"<br>
+       "#extension GL_ARB_separate_shader_objects: require\n"<br>
+       "#extension GL_ARB_explicit_attrib_location: require\n"<br>
+       "\n"<br>
+       "layout(location = 0) in vec4 piglit_vertex;\n"<br>
+       "\n"<br>
+       "layout(location = 2) out vec3 a;\n"<br>
+       "layout(location = 3) out vec3 b;\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "    gl_Position = piglit_vertex;\n"<br>
+       "    a = vec3(0, 0, 1);\n"<br>
+       "    b = vec3(1, 0, 0);\n"<br>
+       "}\n"<br>
+       ;<br>
+<br>
+static const char *fs_code_same_declaration_order_template =<br>
+       "#version %d\n"<br>
+       "#extension GL_ARB_separate_shader_objects: require\n"<br>
+       "#extension GL_ARB_explicit_attrib_location: enable\n"<br>
+       "\n"<br>
+       "#if __VERSION__ >= 130\n"<br>
+       "layout(location = 0) out vec4 out_color;\n"<br>
+       "#else\n"<br>
+       "#define out_color gl_FragColor\n"<br>
+       "#endif\n"<br>
+       "\n"<br>
+       "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n"<br>
+       "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "    out_color = vec4(cross(b, a), 1);\n"<br>
+       "}\n"<br>
+       ;<br>
+<br>
+static const char *fs_code_same_location_order_template =<br>
+       "#version %d\n"<br>
+       "#extension GL_ARB_separate_shader_objects: require\n"<br>
+       "#extension GL_ARB_explicit_attrib_location: enable\n"<br>
+       "\n"<br>
+       "#if __VERSION__ >= 130\n"<br>
+       "layout(location = 0) out vec4 out_color;\n"<br>
+       "#else\n"<br>
+       "#define out_color gl_FragColor\n"<br>
+       "#endif\n"<br>
+       "\n"<br>
+       "layout(location = 2) in vec3 b; /* should get vec3(0, 0, 1) */\n"<br>
+       "layout(location = 3) in vec3 a; /* should get vec3(1, 0, 0) */\n"<br>
+       "\n"<br>
+       "void main()\n"<br>
+       "{\n"<br>
+       "    out_color = vec4(cross(b, a), 1);\n"<br>
+       "}\n"<br>
+       ;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       static const float expected[] = {<br>
+               0.0f, 1.0f, 0.0f, 1.0f<br>
+       };<br>
+       bool pass;<br>
+<br>
+       glClearColor(0.1f, 0.1f, 0.1f, 0.1f);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       glBindProgramPipeline(pipeline_same_declaration_order);<br>
+       piglit_draw_rect(-1, -1, 1, 2);<br>
+<br>
+       glBindProgramPipeline(pipeline_same_location_order);<br>
+       piglit_draw_rect(0, -1, 1, 2);<br>
+       pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,<br>
+                                     expected);<br>
+<br>
+       piglit_present_results();<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+void piglit_init(int argc, char **argv)<br>
+{<br>
+       unsigned glsl_version;<br>
+       GLuint vs_prog;<br>
+       GLuint fs_prog_same_declaration_order;<br>
+       GLuint fs_prog_same_location_order;<br>
+       bool es;<br>
+       int glsl_major;<br>
+       int glsl_minor;<br>
+       char *source;<br>
+<br>
+       piglit_require_vertex_shader();<br>
+       piglit_require_fragment_shader();<br>
+       piglit_require_extension("GL_ARB_separate_shader_objects");<br>
+       piglit_require_extension("GL_ARB_explicit_attrib_location");<br>
+<br>
+       /* Some NVIDIA drivers have issues with layout qualifiers, 'in'<br>
+        * keywords, and 'out' keywords in "lower" GLSL versions.  If the<br>
+        * driver supports GLSL >= 1.40, use 1.40.  Otherwise, pick the<br>
+        * highest version that the driver supports.<br>
+        */<br>
+       piglit_get_glsl_version(&es, &glsl_major, &glsl_minor);<br>
+       glsl_version = ((glsl_major * 100) + glsl_minor) >= 140<br>
+               ? 140 : ((glsl_major * 100) + glsl_minor);<br>
+<br>
+       asprintf(&source, vs_code_template, glsl_version);<br>
+       vs_prog = glCreateShaderProgramv(GL_VERTEX_SHADER, 1,<br>
+                                        (const GLchar *const *) &source);<br>
+       piglit_link_check_status(vs_prog);<br>
+       free(source);<br>
+<br>
+       asprintf(&source, fs_code_same_declaration_order_template, glsl_version);<br>
+       fs_prog_same_declaration_order =<br>
+               glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,<br>
+                                      (const GLchar *const *) &source);<br>
+       piglit_link_check_status(fs_prog_same_declaration_order);<br>
+       free(source);<br>
+<br>
+       asprintf(&source, fs_code_same_location_order_template, glsl_version);<br>
+       fs_prog_same_location_order =<br>
+               glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,<br>
+                                      (const GLchar *const *) &source);<br>
+       piglit_link_check_status(fs_prog_same_location_order);<br>
+       free(source);<br>
+<br>
+       glGenProgramPipelines(1, &pipeline_same_declaration_order);<br>
+       glUseProgramStages(pipeline_same_declaration_order,<br>
+                          GL_VERTEX_SHADER_BIT,<br>
+                          vs_prog);<br>
+       glUseProgramStages(pipeline_same_declaration_order,<br>
+                          GL_FRAGMENT_SHADER_BIT,<br>
+                          fs_prog_same_declaration_order);<br>
+       piglit_program_pipeline_check_status(pipeline_same_declaration_order);<br>
+<br>
+       glGenProgramPipelines(1, &pipeline_same_location_order);<br>
+       glUseProgramStages(pipeline_same_location_order,<br>
+                          GL_VERTEX_SHADER_BIT,<br>
+                          vs_prog);<br>
+       glUseProgramStages(pipeline_same_location_order,<br>
+                          GL_FRAGMENT_SHADER_BIT,<br>
+                          fs_prog_same_location_order);<br>
+       piglit_program_pipeline_check_status(pipeline_same_location_order);<br>
+<br>
+       if (!piglit_check_gl_error(0))<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.4<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div>