<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>
Verify that the right shaders are used in the right combinations several<br>
ways.<br>
<br>
* The vertex shader has information baked-in that determines the X position<br>
of the block on the screen.<br>
<br>
* The fragment shader has information baked-in that determines how the<br>
block is colored. This is combined with data passed from the vertex<br>
shader.<br>
<br>
Since data is passed from the vertex shader to the fragment shader, the<br>
test can use either rendezvous-by-name (default) or rendezvous-by-location<br>
(with --by-location command line parameter).<br>
<br>
This test passes in both modes on NVIDIA (304.64 on GTX 260).<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 | 2 +<br>
.../arb_separate_shader_objects/400-combinations.c | 377 +++++++++++++++++++++<br>
.../arb_separate_shader_objects/CMakeLists.gl.txt | 1 +<br>
3 files changed, 380 insertions(+)<br>
create mode 100644 tests/spec/arb_separate_shader_objects/400-combinations.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 33556af..1e79514 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -1279,6 +1279,8 @@ arb_separate_shader_objects['Mix BindProgramPipeline and UseProgram'] = concurre<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>
+arb_separate_shader_objects['400 combinations by location'] = plain_test('arb_separate_shader_object-400-combinations -fbo --by-location')<br>
+arb_separate_shader_objects['400 combinations by name'] = plain_test('arb_separate_shader_object-400-combinations -fbo')<br>
<br>
# Group ARB_sampler_objects<br>
arb_sampler_objects = Group()<br>
diff --git a/tests/spec/arb_separate_shader_objects/400-combinations.c b/tests/spec/arb_separate_shader_objects/400-combinations.c<br>
new file mode 100644<br>
index 0000000..8593b6e<br>
--- /dev/null<br>
+++ b/tests/spec/arb_separate_shader_objects/400-combinations.c<br>
@@ -0,0 +1,377 @@<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 400-combinations.c<br>
+ * Combine 20 vertex shaders and 20 fragment shaders in various ways.<br>
+ *<br>
+ * Verify that the right shaders are used in the right combinations several<br>
+ * ways.<br>
+ *<br>
+ * * The vertex shader has information baked-in that determines the X position<br>
+ * of the block on the screen.<br>
+ *<br>
+ * * The fragment shader has information baked-in that determines how the<br>
+ * block is colored. This is combined with data passed from the vertex<br>
+ * shader.<br>
+ *<br>
+ * Since data is passed from the vertex shader to the fragment shader, the<br>
+ * test can use either rendezvous-by-name (default) or rendezvous-by-location<br>
+ * (with --by-location command line parameter).<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.supports_gl_core_version = 31;<br>
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;<br></blockquote><div><br></div><div>I'd feel more comfortable if we added:<br><br>config.window_width = (tile_size + border_size) * ARRAY_SIZE(vs_programs);<br>
</div><div>config.window_height = (tile_size + border_size) * ARRAY_SIZE(fs_programs);<br><br></div><div>That way (a) the fact that this test requires a sufficiently large window is explicit, and (b) if we try to run this test with a different default piglit window size (as we often do when running piglit with a hardware simulator) it won't fail.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+/**<br>
+ * Size of each square that will be drawn.<br>
+ */<br>
+static const unsigned tile_size = 5;<br>
+<br>
+/**<br>
+ * Size of the gap between the squares.<br>
+ */<br>
+static const unsigned border_size = 2;<br>
+<br>
+static GLuint vs_programs[20];<br>
+static GLuint fs_programs[20];<br>
+<br>
+static GLuint pipe;<br>
+<br>
+static GLuint vao = 0;<br>
+static GLuint bo = 0;<br>
+<br>
+struct combination {<br>
+ unsigned char row;<br>
+ unsigned char col;<br>
+};<br>
+<br>
+static struct combination combinations[ARRAY_SIZE(vs_programs)<br>
+ * ARRAY_SIZE(fs_programs)];<br>
+<br>
+static const char *vs_code =<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>
+ "layout(location = 1) in vec3 vertex_color;\n"<br>
+ "\n"<br>
+ "%s out vec3 %s;\n"<br>
+ "\n"<br>
+ "const vec4 offset = vec4(%d, 0, 0, 0);\n"<br>
+ "\n"<br>
+ "uniform mat4 transform;\n"<br>
+ "\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_Position = transform * (piglit_vertex + offset);\n"<br>
+ " %s = vertex_color;\n"<br>
+ "}\n"<br>
+ ;<br>
+<br>
+static const char *fs_code =<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>
+ "%s in vec3 %s;\n"<br>
+ "\n"<br>
+ "const vec3 color_offset = vec3(%d, %d, %d);\n"<br>
+ "\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " out_color = vec4(%s + color_offset, 1.);\n"<br>
+ "}\n"<br>
+ ;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+ unsigned i;<br>
+ unsigned j;<br>
+<br>
+ static const float expected[] = {<br>
+ 0.0f, 1.0f, 0.0f, 1.0f<br>
+ };<br>
+<br>
+ /* This is stored in row-major order. Note the GL_TRUE parameter to<br>
+ * the glProgramUniformMatrix4fv call below.<br>
+ */<br>
+ const float transform[16] = {<br>
+ 2.f / piglit_width, 0.0f, 0.0f, -1.0f,<br>
+ 0.0f, 2.f / piglit_height, 0.0f, -1.0f,<br>
+ 0.0f, 0.0f, 0.0f, 0.0f,<br>
+ 0.0f, 0.0f, 0.0f, 1.0f,<br>
+ };<br>
+<br>
+ bool pass = true;<br>
+<br>
+ glClearColor(.5f, .5f, .5f, 1.f);<br>
+ glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(vs_programs); i++) {<br>
+ const GLint loc =<br>
+ glGetUniformLocation(vs_programs[i], "transform");<br>
+<br>
+ glProgramUniformMatrix4fv(vs_programs[i], loc, 1, GL_TRUE,<br>
+ transform);<br>
+ }<br>
+<br>
+ glBindProgramPipeline(pipe);<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(combinations); i++) {<br>
+ const unsigned row = combinations[i].row;<br>
+ const unsigned col = combinations[i].col;<br>
+<br>
+ glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT,<br>
+ vs_programs[col]);<br>
+ glUseProgramStages(pipe, GL_FRAGMENT_SHADER_BIT,<br>
+ fs_programs[row]);<br>
+ glDrawArrays(GL_TRIANGLE_FAN, row * 4, 4);<br>
+ }<br>
+<br>
+ glBindProgramPipeline(0);<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(vs_programs); i++) {<br>
+ for (j = 0; j < ARRAY_SIZE(fs_programs); j++) {<br>
+ const unsigned x = (i * tile_size)<br>
+ + ((i + 1) * border_size);<br>
+ const unsigned y = (j * tile_size)<br>
+ + ((j + 1) * border_size);<br>
+<br>
+ pass = piglit_probe_rect_rgba(x, y,<br>
+ tile_size, tile_size,<br>
+ expected)<br>
+ && pass;<br>
+ }<br>
+ }<br>
+<br>
+ piglit_present_results();<br>
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+#define RED(x) ((int) (x / 2))<br>
+#define GREEN(x) (-(int) x)<br>
+#define BLUE(x) ((int) (x * 7))<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+ unsigned glsl_version;<br>
+ unsigned i;<br>
+ unsigned j;<br>
+ unsigned idx;<br>
+ bool es;<br>
+ int glsl_major;<br>
+ int glsl_minor;<br>
+ const char *location;<br>
+ const char *vertex_name;<br>
+ const char *fragment_name;<br>
+<br>
+ struct vertex {<br>
+ float x;<br>
+ float y;<br>
+ float r;<br>
+ float g;<br>
+ float b;<br>
+ } *vert;<br>
+<br>
+ piglit_require_extension("GL_ARB_separate_shader_objects");<br>
+ piglit_require_extension("GL_ARB_explicit_attrib_location");<br>
+<br>
+ if (argc > 1 && strcmp(argv[1], "--by-location") == 0) {<br>
+ location = "layout(location = 3)";<br>
+ vertex_name = "a";<br>
+ fragment_name = "b";<br>
+ } else {<br>
+ location = "";<br>
+ vertex_name = "in_color";<br>
+ fragment_name = "in_color";<br>
+ }<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>
+ /* Generate the vertex shader programs. Each vertex shader is<br>
+ * hardcoded to select a specific column on the display.<br>
+ */<br>
+ printf("Generating vertex shaders...\n");<br>
+ for (i = 0; i < ARRAY_SIZE(vs_programs); i++) {<br>
+ const unsigned base_x = (i * tile_size)<br>
+ + ((i + 1) * border_size);<br>
+<br>
+ char *source = NULL;<br>
+<br>
+ asprintf(&source, vs_code,<br>
+ glsl_version,<br>
+ location,<br>
+ vertex_name,<br>
+ base_x,<br>
+ vertex_name);<br>
+<br>
+ vs_programs[i] =<br>
+ glCreateShaderProgramv(GL_VERTEX_SHADER, 1,<br>
+ (const GLchar *const *) &source);<br>
+ piglit_link_check_status(vs_programs[i]);<br>
+<br>
+ if (i == 0)<br>
+ puts(source);<br>
+<br>
+ free(source);<br>
+ }<br>
+<br>
+ printf("Generating fragment shaders...\n");<br>
+ for (i = 0; i < ARRAY_SIZE(fs_programs); i++) {<br>
+ char *source = NULL;<br>
+<br>
+ asprintf(&source, fs_code,<br>
+ glsl_version,<br>
+ location,<br>
+ fragment_name,<br>
+ RED(i), GREEN(i), BLUE(i),<br>
+ fragment_name);<br>
+<br>
+ fs_programs[i] =<br>
+ glCreateShaderProgramv(GL_FRAGMENT_SHADER, 1,<br>
+ (const GLchar *const *) &source);<br>
+ piglit_link_check_status(fs_programs[i]);<br>
+<br>
+ if (i == 3)<br>
+ puts(source);<br>
+<br>
+ free(source);<br>
+ }<br>
+<br>
+ glGenProgramPipelines(1, &pipe);<br>
+<br>
+ /* Generate vertex data for the tests. The row of each block is<br>
+ * determined by the vertex data. The color data for the block comes<br>
+ * from the vertex data and the data baked into the fragment shader.<br>
+ */<br>
+ if (piglit_get_gl_version() >= 30<br>
+ || piglit_is_extension_supported("GL_ARB_vertex_array_object")) {<br>
+ glGenVertexArrays(1, &vao);<br>
+ glBindVertexArray(vao);<br>
+ }<br>
+<br>
+ glGenBuffers(1, &bo);<br>
+ glBindBuffer(GL_ARRAY_BUFFER, bo);<br>
+ glBufferData(GL_ARRAY_BUFFER,<br>
+ sizeof(vert[0]) * 4 * ARRAY_SIZE(fs_programs),<br>
+ NULL, GL_STATIC_DRAW);<br>
+<br>
+ vert = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);<br>
+<br>
+ for (i = 0; i < ARRAY_SIZE(fs_programs); i++) {<br>
+ const unsigned base_y = (i * tile_size)<br>
+ + ((i + 1) * border_size);<br>
+<br>
+ vert[(i * 4) + 0].x = 0.f;<br>
+ vert[(i * 4) + 0].y = (float) base_y;<br>
+ vert[(i * 4) + 0].r = (float) -RED(i);<br>
+ vert[(i * 4) + 0].g = (float) 1 - GREEN(i);<br>
+ vert[(i * 4) + 0].b = (float) -BLUE(i);<br>
+<br>
+ vert[(i * 4) + 1].x = (float) tile_size;<br>
+ vert[(i * 4) + 1].y = (float) base_y;<br>
+ vert[(i * 4) + 1].r = (float) -RED(i);<br>
+ vert[(i * 4) + 1].g = (float) 1 - GREEN(i);<br>
+ vert[(i * 4) + 1].b = (float) -BLUE(i);<br>
+<br>
+ vert[(i * 4) + 2].x = (float) tile_size;<br>
+ vert[(i * 4) + 2].y = (float) (base_y + tile_size);<br>
+ vert[(i * 4) + 2].r = (float) -RED(i);<br>
+ vert[(i * 4) + 2].g = (float) 1 - GREEN(i);<br>
+ vert[(i * 4) + 2].b = (float) -BLUE(i);<br>
+<br>
+ vert[(i * 4) + 3].x = 0.f;<br>
+ vert[(i * 4) + 3].y = (float) (base_y + tile_size);<br>
+ vert[(i * 4) + 3].r = (float) -RED(i);<br>
+ vert[(i * 4) + 3].g = (float) 1 - GREEN(i);<br>
+ vert[(i * 4) + 3].b = (float) -BLUE(i);<br>
+ }<br>
+<br>
+ glUnmapBuffer(GL_ARRAY_BUFFER);<br>
+<br>
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(vert[0]),<br>
+ (void *)(intptr_t) offsetof(struct vertex, x));<br>
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vert[0]),<br>
+ (void *)(intptr_t) offsetof(struct vertex, r));<br>
+ glEnableVertexAttribArray(0);<br>
+ glEnableVertexAttribArray(1);<br>
+<br>
+ /* Generate the set of combinations of vertex shader programs and<br>
+ * fragment shader programs that will be used together. This is all<br>
+ * the possible combinations. The next step is to shuffle list so<br>
+ * that there's (hopefully) no pattern to the access combination... to<br>
+ * uncover driver bugs.<br>
+ */<br>
+ idx = 0;<br>
+ for (i = 0; i < ARRAY_SIZE(vs_programs); i++) {<br>
+ for (j = 0; j < ARRAY_SIZE(fs_programs); j++) {<br>
+ combinations[idx].row = j;<br>
+ combinations[idx].col = i;<br>
+ idx++;<br>
+ }<br>
+ }<br>
+<br>
+ for (i = 0; i < (5 * ARRAY_SIZE(combinations)); i++) {<br>
+ /* Pick a random element from the array.<br>
+ */<br>
+ const unsigned src = rand() % ARRAY_SIZE(combinations);<br>
+<br>
+ /* Pick a random element from the array that is not the same<br>
+ * as the previous element. This is done by picking a second<br>
+ * number on the range [1, ARRAY_SIZE(combinations) - 2] and<br>
+ * adding it (using modular addition) to the first.<br>
+ */<br>
+ const unsigned delta =<br>
+ (rand() % (ARRAY_SIZE(combinations) - 1)) + 1;<br>
+ const unsigned dst = (src + delta) % ARRAY_SIZE(combinations);<br>
+<br>
+ /* Exchange the two selected elements.<br>
+ */<br>
+ const struct combination temp = combinations[dst];<br>
+ combinations[dst] = combinations[src];<br>
+ combinations[src] = temp;<br>
+ }<br></blockquote><div> <br></div><div>A less ad-hoc algorithm for shuffling an array is:<br><br></div><div>for (i = ARRAY_SIZE(combinations); i > 1; i--) {<br></div><div> j = rand() % i;<br></div><div> if (j != i - 1)<br>
</div><div> swap elements j and i - 1<br>}<br><br></div><div>Neglecting deficiencies in rand(), this algorithm produces all possible permutations with equal probability.<br><br><br></div><div>With the above two changes, this patch is:<br>
<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>
diff --git a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
index 32a28ba..2e2e1b8 100644<br>
--- a/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_separate_shader_objects/CMakeLists.gl.txt<br>
@@ -9,6 +9,7 @@ link_libraries (<br>
${OPENGL_glu_LIBRARY}<br>
)<br>
<br>
+piglit_add_executable (arb_separate_shader_object-400-combinations 400-combinations.c)<br>
piglit_add_executable (arb_separate_shader_object-GetProgramPipelineiv GetProgramPipelineiv.c)<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>
<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>