<div dir="ltr">On 19 April 2013 17:09, Jordan Justen <span dir="ltr"><<a href="mailto:jordan.l.justen@intel.com" target="_blank">jordan.l.justen@intel.com</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">This test renders to multiple slices of a 2D array texture<br>
by using a geometry shader and the gl_Layer variable.<br>
<br>
Signed-off-by: Jordan Justen <<a href="mailto:jordan.l.justen@intel.com">jordan.l.justen@intel.com</a>><br></blockquote><div><br></div><div>There's an awful lot of duplicate code between this test and the one introduced in patch 1/3.  Can we move the common code into a shared source file?<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                               |    4 +<br>
 tests/spec/CMakeLists.txt                     |    1 +<br>
 tests/spec/gl-3.2/CMakeLists.gl.txt           |   13 +<br>
 tests/spec/gl-3.2/CMakeLists.txt              |    1 +<br>
 tests/spec/gl-3.2/layered-2d-texture-render.c |  339 +++++++++++++++++++++++++<br>
 5 files changed, 358 insertions(+)<br>
 create mode 100644 tests/spec/gl-3.2/CMakeLists.gl.txt<br>
 create mode 100644 tests/spec/gl-3.2/CMakeLists.txt<br>
 create mode 100644 tests/spec/gl-3.2/layered-2d-texture-render.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 6c1298d..75f79c3 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -707,6 +707,10 @@ for subtest in ['generated', 'written', 'flush']:<br>
         cmdline = 'primitive-restart-xfb {0}'.format(subtest)<br>
         gl31[cmdline] = concurrent_test('gl-3.1-' + cmdline)<br>
<br>
+gl32 = Group()<br>
+spec['!OpenGL 3.2'] = gl32<br>
+gl32['layered-2d-texture-render'] = concurrent_test('gl-3.2-layered-2d-texture-render')<br>
+<br>
 # Group spec/glsl-es-1.00<br>
 spec['glsl-es-1.00'] = Group()<br>
 import_glsl_parser_tests(spec['glsl-es-1.00'],<br>
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt<br>
index f901a20..d2dda8a 100644<br>
--- a/tests/spec/CMakeLists.txt<br>
+++ b/tests/spec/CMakeLists.txt<br>
@@ -59,6 +59,7 @@ add_subdirectory (gl-2.0)<br>
 add_subdirectory (gl-2.1)<br>
 add_subdirectory (gl-3.0)<br>
 add_subdirectory (gl-3.1)<br>
+add_subdirectory (gl-3.2)<br>
 add_subdirectory (gles-2.0)<br>
 add_subdirectory (gles-3.0)<br>
 add_subdirectory (glx_arb_create_context)<br>
diff --git a/tests/spec/gl-3.2/CMakeLists.gl.txt b/tests/spec/gl-3.2/CMakeLists.gl.txt<br>
new file mode 100644<br>
index 0000000..ac9e3d2<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/CMakeLists.gl.txt<br>
@@ -0,0 +1,13 @@<br>
+include_directories(<br>
+       ${GLEXT_INCLUDE_DIR}<br>
+       ${OPENGL_INCLUDE_PATH}<br>
+)<br>
+<br>
+link_libraries (<br>
+       piglitutil_${piglit_target_api}<br>
+       ${OPENGL_gl_LIBRARY}<br>
+       ${OPENGL_glu_LIBRARY}<br>
+)<br>
+<br>
+piglit_add_executable (gl-3.2-layered-2d-texture-render layered-2d-texture-render.c)<br>
+<br>
diff --git a/tests/spec/gl-3.2/CMakeLists.txt b/tests/spec/gl-3.2/CMakeLists.txt<br>
new file mode 100644<br>
index 0000000..144a306<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/CMakeLists.txt<br>
@@ -0,0 +1 @@<br>
+piglit_include_target_api()<br>
diff --git a/tests/spec/gl-3.2/layered-2d-texture-render.c b/tests/spec/gl-3.2/layered-2d-texture-render.c<br>
new file mode 100644<br>
index 0000000..0f77dc4<br>
--- /dev/null<br>
+++ b/tests/spec/gl-3.2/layered-2d-texture-render.c<br>
@@ -0,0 +1,339 @@<br>
+/*<br>
+ * Copyright (c) 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>
+/*<br>
+ * Test 2D array texture rendering with gl_Layer<br>
+ */<br>
+<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+#define PAD            5<br>
+#define SIZE           64<br>
+#define LAYERS         5<br>
+#define LOD            7<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+       config.supports_gl_core_version = 32;<br>
+       config.supports_gl_compat_version = 0;<br>
+<br>
+       config.window_width = (((SIZE+PAD)*LAYERS)+PAD);<br>
+       config.window_height = (((SIZE+PAD)*2)+PAD);<br>
+       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+static GLuint rectangle_vertices_bo;<br>
+<br>
+/* VS, GS and FS to fill the 2D array texture */<br>
+static const char *fill_tex_vs =<br>
+ "#version 150\n"<br>
+ "in vec2 vertex;\n"<br>
+ "out vec4 vertex_to_gs;\n"<br>
+ "out int layer;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " layer = gl_InstanceID;\n"<br>
+ " vertex_to_gs = vec4(vertex, vec2(0.0, 1.0));\n"<br>
+ "}\n";<br>
+<br>
+static const char *fill_tex_gs =<br>
+ "#version 150\n"<br>
+ "uniform int color_bias;\n"<br>
+ "in vec4 vertex_to_gs[3];\n"<br>
+ "in int layer[3];\n"<br>
+ "out vec3 color;\n"<br>
+ "layout (triangle_strip, max_vertices=3) out;\n"<br>
+ "vec3 get_color(int num)\n"<br>
+ "{\n"<br>
+ " vec3 result = vec3(0.0);\n"<br>
+ " if ((num & 4) != 0) result.r = 1.0;"<br>
+ " if ((num & 2) != 0) result.g = 1.0;"<br>
+ " if ((num & 1) != 0) result.b = 1.0;"<br>
+ " return result;\n"<br>
+ "}\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " for (int i = 0; i < 3; i++) {\n"<br>
+ "  gl_Position = vertex_to_gs[i];\n"<br>
+ "  gl_Layer = layer[i];\n"<br>
+ "  color = get_color(color_bias + layer[i]);\n"<br>
+ "  EmitVertex();\n"<br>
+ " }"<br>
+ "}\n";<br>
+<br>
+static const char *fill_tex_fs =<br>
+ "#version 150\n"<br>
+ "in vec3 color;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_FragColor = vec4(color, 1.0);\n"<br>
+ "}\n";<br>
+<br>
+/* VS and FS to use and test the 2D array texture */<br>
+static const char *use_tex_vs =<br>
+ "#version 130\n"<br>
+ "in vec2 vertex;\n"<br>
+ "out vec2 coord;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_Position = vec4(vertex, vec2(0.0, 1.0));\n"<br>
+ " coord = (vertex * 0.5) + 0.5;\n"<br>
+ "}\n";<br>
+<br>
+static const char *use_tex_fs =<br>
+ "#version 130\n"<br>
+ "uniform sampler2DArray tex; \n"<br>
+ "uniform int layer;\n"<br>
+ "uniform int lod;\n"<br>
+ "in vec2 coord;\n"<br>
+ "void main()\n"<br>
+ "{\n"<br>
+ " gl_FragColor = textureLod(tex, vec3(coord, float(layer)), lod);\n"<br>
+ "}\n";<br>
+<br>
+static GLuint fill_tex_program;<br>
+static GLuint use_tex_program;<br>
+<br>
+static int get_x(int layer)<br>
+{<br>
+       return ((SIZE + PAD) * layer) + PAD;<br>
+}<br>
+<br>
+static int get_y(int layer, int lod)<br>
+{<br>
+       int size = SIZE >> lod;<br>
+       return PAD + (((1 << lod) - 1) * 2 * size);<br>
+}<br>
+<br>
+static GLfloat* get_color(int num)<br>
+{<br>
+       int color_index;<br>
+<br>
+       static GLfloat colors[][3] = {<br>
+               {0.0, 0.0, 0.0},<br>
+               {0.0, 0.0, 1.0},<br>
+               {0.0, 1.0, 0.0},<br>
+               {0.0, 1.0, 1.0},<br>
+               {1.0, 0.0, 0.0},<br>
+               {1.0, 0.0, 1.0},<br>
+               {1.0, 1.0, 0.0},<br>
+               {1.0, 1.0, 1.0},<br>
+       };<br>
+<br>
+       color_index = num % ARRAY_SIZE(colors);<br>
+       return colors[color_index];<br>
+}<br>
+<br>
+static bool<br>
+render_tex_layers(GLuint tex)<br>
+{<br>
+       int lod;<br>
+       GLint color_bias_loc;<br>
+       GLenum status;<br>
+       int color_index = 0;<br>
+       int size;<br>
+<br>
+       glUseProgram(fill_tex_program);<br>
+<br>
+       color_bias_loc = glGetUniformLocation(fill_tex_program, "color_bias");<br>
+<br>
+       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);<br>
+       glBindAttribLocation(fill_tex_program, 0, "vertex");<br>
+       glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, 0);<br>
+       glEnableVertexAttribArray(0);<br>
+       for (lod = 0; lod < LOD; lod++) {<br>
+               size = SIZE >> lod;<br>
+               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, lod);<br>
+               status = glCheckFramebufferStatus(GL_FRAMEBUFFER);<br>
+               if (status != GL_FRAMEBUFFER_COMPLETE) {<br>
+                       fprintf(stderr, "fbo incomplete (status = %s)\n",<br>
+                               piglit_get_gl_enum_name(status));<br>
+                       return false;<br>
+               }<br>
+               glDrawBuffer(GL_COLOR_ATTACHMENT0);<br>
+               glViewport(0, 0, size, size);<br>
+               glUniform1i(color_bias_loc, color_index);<br>
+               glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, LAYERS);<br>
+               color_index += LAYERS;<br>
+               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, lod);<br>
+       }<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
+       glDisableVertexAttribArray(0);<br>
+<br>
+       return true;<br>
+}<br>
+<br>
+static GLuint<br>
+build_texture(void)<br>
+{<br>
+       GLuint tex;<br>
+       int lod;<br>
+       int size;<br>
+<br>
+       glGenTextures(1, &tex);<br>
+       glBindTexture(GL_TEXTURE_2D_ARRAY, tex);<br>
+       for (lod = 0; lod < LOD; lod++) {<br>
+               size = SIZE >> lod;<br>
+               glTexImage3D(GL_TEXTURE_2D_ARRAY, lod, GL_RGBA,<br>
+                            size, size, LAYERS, 0, GL_RGBA, GL_FLOAT, NULL);<br>
+       }<br>
+<br>
+       render_tex_layers(tex);<br>
+<br>
+       return tex;<br>
+}<br>
+<br>
+static void<br>
+draw_box(GLuint tex, int layer, int lod)<br>
+{<br>
+       GLint layer_loc, lod_loc;<br>
+       int x = get_x(layer);<br>
+       int y = get_y(layer, lod);<br>
+       int size = SIZE >> lod;<br>
+<br>
+       layer_loc = glGetUniformLocation(use_tex_program, "layer");<br>
+       lod_loc = glGetUniformLocation(use_tex_program, "lod");<br>
+<br>
+       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);<br>
+<br>
+       glBindAttribLocation(use_tex_program, 0, "vertex");<br>
+       glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, 0);<br>
+       glEnableVertexAttribArray(0);<br>
+<br>
+       glBindTexture(GL_TEXTURE_2D_ARRAY, tex);<br>
+<br>
+       glViewport(x, y, size, size);<br>
+       glUniform1i(layer_loc, layer);<br>
+       glUniform1i(lod_loc, lod);<br>
+       glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);<br>
+<br>
+       glDisableVertexAttribArray(0);<br>
+}<br>
+<br>
+static GLboolean<br>
+test_results(int layer, int lod)<br>
+{<br>
+       int x = get_x(layer);<br>
+       int y = get_y(layer, lod);<br>
+       GLfloat *color3f = get_color((lod * LAYERS) + layer);<br>
+       GLboolean pass;<br>
+       int size = SIZE >> lod;<br>
+<br>
+       pass = piglit_probe_rect_rgb(x, y, size, size, color3f);<br>
+<br>
+       if (!pass) {<br>
+               printf("2D array failed at size %d, layer %d\n",<br>
+                      size, layer);<br>
+       }<br>
+<br>
+       return pass;<br>
+}<br>
+<br>
+static GLboolean<br>
+test_texture(GLuint tex)<br>
+{<br>
+       int layer, lod;<br>
+       GLint tex_loc;<br>
+       GLboolean pass = GL_TRUE;<br>
+       glUseProgram(use_tex_program);<br>
+       glActiveTexture(GL_TEXTURE0);<br>
+       tex_loc = glGetUniformLocation(use_tex_program, "tex");<br>
+       glUniform1i(tex_loc, 0);<br>
+<br>
+       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,<br>
+                       GL_NEAREST_MIPMAP_NEAREST);<br>
+       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,<br>
+                       GL_NEAREST);<br>
+<br>
+       for (lod = 0; lod < LOD; lod++) {<br>
+               for (layer = 0; layer < LAYERS; layer++) {<br>
+                       draw_box(tex, layer, lod);<br>
+                       pass = test_results(layer, lod) && pass;<br>
+               }<br>
+       }<br>
+<br>
+       glUseProgram(0);<br>
+       return pass;<br>
+}<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+       GLboolean pass;<br>
+       GLuint vao, fbo;<br>
+       GLuint tex;<br>
+       static GLfloat verts[4][2] = {<br>
+               { 1.0, -1.0},<br>
+               {-1.0, -1.0},<br>
+               { 1.0,  1.0},<br>
+               {-1.0,  1.0},<br>
+       };<br>
+<br>
+       /* Clear background to gray */<br>
+       glClearColor(0.5, 0.5, 0.5, 1.0);<br>
+       glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+       glGenFramebuffers(1, &fbo);<br>
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
+       glGenVertexArrays(1, &vao);<br>
+       glBindVertexArray(vao);<br>
+       glGenBuffers(1, &rectangle_vertices_bo);<br>
+       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);<br>
+       glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);<br>
+<br>
+       tex = build_texture();<br>
+       pass = test_texture(tex);<br>
+       glDeleteTextures(1, &tex);<br>
+<br>
+       piglit_present_results();<br>
+<br>
+       glDeleteBuffers(1, &rectangle_vertices_bo);<br>
+       glDeleteFramebuffers(1, &fbo);<br>
+       glDeleteVertexArrays(1, &vao);<br>
+<br>
+       return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       GLuint vs, gs, fs;<br>
+<br>
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, fill_tex_vs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER, fill_tex_gs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fill_tex_fs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       fill_tex_program = piglit_link_simple_gs_program(vs, gs, fs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+<br>
+       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, use_tex_vs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, use_tex_fs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+       use_tex_program = piglit_link_simple_program(vs, fs);<br>
+       piglit_check_gl_error(GL_NO_ERROR);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.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>