[Piglit] [PATCH 1/3] Add amd_vertex_shader_layer layered-2d-texture-render test

Paul Berry stereotype441 at gmail.com
Tue Apr 30 16:22:09 PDT 2013


On 19 April 2013 17:09, Jordan Justen <jordan.l.justen at intel.com> wrote:

> This tests the AMD_vertex_shader_layer extension using a
> 2D array texture.
>
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  tests/all.tests                                    |    4 +
>  tests/spec/CMakeLists.txt                          |    1 +
>  .../spec/amd_vertex_shader_layer/CMakeLists.gl.txt |   13 +
>  tests/spec/amd_vertex_shader_layer/CMakeLists.txt  |    1 +
>  .../layered-2d-texture-render.c                    |  331
> ++++++++++++++++++++
>  5 files changed, 350 insertions(+)
>  create mode 100644 tests/spec/amd_vertex_shader_layer/CMakeLists.gl.txt
>  create mode 100644 tests/spec/amd_vertex_shader_layer/CMakeLists.txt
>  create mode 100644
> tests/spec/amd_vertex_shader_layer/layered-2d-texture-render.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 495de59..6c1298d 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -2146,6 +2146,10 @@ amd_seamless_cubemap_per_texture = Group()
>  spec['AMD_seamless_cubemap_per_texture'] =
> amd_seamless_cubemap_per_texture
>  add_plain_test(amd_seamless_cubemap_per_texture,
> 'amd_seamless_cubemap_per_texture')
>
> +amd_vertex_shader_layer = Group()
> +spec['AMD_vertex_shader_layer'] = amd_vertex_shader_layer
> +add_plain_test(amd_vertex_shader_layer,
> 'amd_vertex_shader_layer-layered-2d-texture-render')
> +
>  ext_fog_coord = Group()
>  spec['EXT_fog_coord'] = ext_fog_coord
>  add_plain_test(ext_fog_coord, 'ext_fog_coord-modes')
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index a1492cc..f901a20 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -16,6 +16,7 @@ add_subdirectory (arb_robustness)
>  add_subdirectory (arb_sampler_objects)
>  add_subdirectory (arb_seamless_cube_map)
>  add_subdirectory (amd_seamless_cubemap_per_texture)
> +add_subdirectory (amd_vertex_shader_layer)
>  add_subdirectory (arb_shader_texture_lod/execution)
>  add_subdirectory (arb_shader_objects)
>  add_subdirectory (arb_sync)
> diff --git a/tests/spec/amd_vertex_shader_layer/CMakeLists.gl.txt
> b/tests/spec/amd_vertex_shader_layer/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..cdfb4cd
> --- /dev/null
> +++ b/tests/spec/amd_vertex_shader_layer/CMakeLists.gl.txt
> @@ -0,0 +1,13 @@
> +include_directories(
> +       ${GLEXT_INCLUDE_DIR}
> +       ${OPENGL_INCLUDE_PATH}
> +)
> +
> +link_libraries (
> +       piglitutil_${piglit_target_api}
> +       ${OPENGL_gl_LIBRARY}
> +       ${OPENGL_glu_LIBRARY}
> +)
> +
> +piglit_add_executable (amd_vertex_shader_layer-layered-2d-texture-render
> layered-2d-texture-render.c)
> +
> diff --git a/tests/spec/amd_vertex_shader_layer/CMakeLists.txt
> b/tests/spec/amd_vertex_shader_layer/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/amd_vertex_shader_layer/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git
> a/tests/spec/amd_vertex_shader_layer/layered-2d-texture-render.c
> b/tests/spec/amd_vertex_shader_layer/layered-2d-texture-render.c
> new file mode 100644
> index 0000000..1e6a6ff
> --- /dev/null
> +++ b/tests/spec/amd_vertex_shader_layer/layered-2d-texture-render.c
> @@ -0,0 +1,331 @@
> +/*
> + * Copyright (c) 2013 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.
> + *
> + */
> +
> +/*
> + * Test 2D array texture rendering with gl_Layer (amd_vertex_shader_layer)
> + */
>

Would you mind adding a comment here that gives a basic outline of what the
test does, and how to interpret its output?  I'm having trouble following
it from reading the code, and since I don't have a device that supports
this extension I can't just run the test in the debugger to find out.


> +
> +#include "piglit-util-gl-common.h"
> +
> +#define PAD            5
> +#define SIZE           64
> +#define LAYERS         5
> +#define LOD            7
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +       config.supports_gl_core_version = 31;
> +       config.supports_gl_compat_version = 30;
>

Shouldn't this been config.supports_gl_compat_version = 31?  I think GL 3.1
is required because of your use of gl_InstanceID.


> +
> +       config.window_width = (((SIZE+PAD)*LAYERS)+PAD);
> +       config.window_height = (((SIZE+PAD)*2)+PAD);
> +       config.window_visual = PIGLIT_GL_VISUAL_DOUBLE |
> PIGLIT_GL_VISUAL_RGB;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static GLuint rectangle_vertices_bo;
> +
> +/* VS and FS to fill the 2D array texture */
> +static const char *fill_tex_vs =
> + "#version 140\n"
>
+ "#extension GL_AMD_vertex_shader_layer: enable\n"
> + "uniform int color_bias;\n"
> + "in vec2 vertex;\n"
> + "out vec3 color;\n"
> + "vec3 get_color(int num)\n"
> + "{\n"
> + " vec3 result = vec3(0.0);\n"
> + " if ((num & 4) != 0) result.r = 1.0;"
> + " if ((num & 2) != 0) result.g = 1.0;"
> + " if ((num & 1) != 0) result.b = 1.0;"
> + " return result;\n"
> + "}\n"
> + "void main()\n"
> + "{\n"
> + " gl_Position = vec4(vertex, vec2(0.0, 1.0));\n"
> + " gl_Layer = gl_InstanceID;\n"
> + " color = get_color(color_bias + gl_InstanceID);\n"
> + "}\n";
> +
> +static const char *fill_tex_fs =
> + "#version 140\n"
> + "in vec3 color;\n"
> + "void main()\n"
> + "{\n"
> + " gl_FragColor = vec4(color, 1.0);\n"
> + "}\n";
> +
> +/* VS and FS to use and test the 2D array texture */
> +static const char *use_tex_vs =
> + "#version 130\n"
> + "in vec2 vertex;\n"
> + "out vec2 coord;\n"
> + "void main()\n"
> + "{\n"
> + " gl_Position = vec4(vertex, vec2(0.0, 1.0));\n"
> + " coord = (vertex * 0.5) + 0.5;\n"
> + "}\n";
> +
> +static const char *use_tex_fs =
> + "#version 130\n"
> + "uniform sampler2DArray tex; \n"
> + "uniform int layer;\n"
> + "uniform int lod;\n"
> + "in vec2 coord;\n"
> + "void main()\n"
> + "{\n"
> + " gl_FragColor = textureLod(tex, vec3(coord, float(layer)), lod);\n"
> + "}\n";
> +
> +static GLuint fill_tex_program;
> +static GLuint use_tex_program;
> +
> +static int get_x(int layer)
> +{
> +       return ((SIZE + PAD) * layer) + PAD;
> +}
> +
> +static int get_y(int layer, int lod)
> +{
> +       int size = SIZE >> lod;
> +       return PAD + (((1 << lod) - 1) * 2 * size);
> +}
> +
> +static GLfloat* get_color(int num)
>
+{
> +       int color_index;
> +
> +       static GLfloat colors[][3] = {
> +               {0.0, 0.0, 0.0},
> +               {0.0, 0.0, 1.0},
> +               {0.0, 1.0, 0.0},
> +               {0.0, 1.0, 1.0},
> +               {1.0, 0.0, 0.0},
> +               {1.0, 0.0, 1.0},
> +               {1.0, 1.0, 0.0},
> +               {1.0, 1.0, 1.0},
> +       };
> +
> +       color_index = num % ARRAY_SIZE(colors);
> +       return colors[color_index];
> +}
> +
> +static bool
> +render_tex_layers(GLuint tex)
> +{
> +       int lod;
> +       GLint color_bias_loc;
> +       GLenum status;
> +       int color_index = 0;
> +       int size;
> +
> +       glUseProgram(fill_tex_program);
> +
> +       color_bias_loc = glGetUniformLocation(fill_tex_program,
> "color_bias");
> +
> +       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);
> +       glBindAttribLocation(fill_tex_program, 0, "vertex");
>
+       glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, 0);
> +       glEnableVertexAttribArray(0);
>

glBindAttribLocation has no effect if you've already linked the program.
Probably you're just getting lucky and it's working because the linker
assigned "vertex" to attrib 0 anyhow.

I'd recommend changing this to something like:

vertex_attr = glGetAttribLocation(fill_tex_program, "vertex");
glVertexAttribPointer(vertex_attr, 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(vertex_attr);

(don't forget to update the call to glDisableVertexAttribArray() below)


> +       for (lod = 0; lod < LOD; lod++) {
> +               size = SIZE >> lod;
> +               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> tex, lod);
> +               status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +               if (status != GL_FRAMEBUFFER_COMPLETE) {
> +                       fprintf(stderr, "fbo incomplete (status = %s)\n",
> +                               piglit_get_gl_enum_name(status));
> +                       return false;
> +               }
> +               glDrawBuffer(GL_COLOR_ATTACHMENT0);
> +               glViewport(0, 0, size, size);
> +               glUniform1i(color_bias_loc, color_index);
> +               glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, LAYERS);
> +               color_index += LAYERS;
> +               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> 0, lod);
>

Is it necessary for this last line to be in the loop?  It seems like it's
only going to have an effect the last time the loop runs.


> +       }
> +       glBindFramebuffer(GL_FRAMEBUFFER, 0);
> +       glDisableVertexAttribArray(0);
> +
> +       return true;
> +}
> +
> +static GLuint
> +build_texture(void)
> +{
> +       GLuint tex;
> +       int lod;
> +       int size;
> +
> +       glGenTextures(1, &tex);
> +       glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
> +       for (lod = 0; lod < LOD; lod++) {
> +               size = SIZE >> lod;
> +               glTexImage3D(GL_TEXTURE_2D_ARRAY, lod, GL_RGBA,
> +                            size, size, LAYERS, 0, GL_RGBA, GL_FLOAT,
> NULL);
> +       }
> +
> +       render_tex_layers(tex);
> +
> +       return tex;
> +}
> +
> +static void
> +draw_box(GLuint tex, int layer, int lod)
> +{
> +       GLint layer_loc, lod_loc;
> +       int x = get_x(layer);
> +       int y = get_y(layer, lod);
> +       int size = SIZE >> lod;
> +
> +       layer_loc = glGetUniformLocation(use_tex_program, "layer");
> +       lod_loc = glGetUniformLocation(use_tex_program, "lod");
> +
> +       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);
> +
> +       glBindAttribLocation(use_tex_program, 0, "vertex");
>
+       glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, 0);
> +       glEnableVertexAttribArray(0);
>

Similar problem with glBindAttribLocation() here.


> +
> +       glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
> +
> +       glViewport(x, y, size, size);
> +       glUniform1i(layer_loc, layer);
> +       glUniform1i(lod_loc, lod);
> +       glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
> +
> +       glDisableVertexAttribArray(0);
> +}
> +
> +static GLboolean
> +test_results(int layer, int lod)
> +{
> +       int x = get_x(layer);
> +       int y = get_y(layer, lod);
> +       GLfloat *color3f = get_color((lod * LAYERS) + layer);
>

I stumbled on this line because I couldn't remember if get_color() computed
the expected color or the actual rendered color.  How about if we rename
"color3f" to "expected_color3f"?


> +       GLboolean pass;
> +       int size = SIZE >> lod;
> +
> +       pass = piglit_probe_rect_rgb(x, y, size, size, color3f);
> +
> +       if (!pass) {
> +               printf("2D array failed at size %d, layer %d\n",
> +                      size, layer);
> +       }
> +
> +       return pass;
> +}
> +
> +static GLboolean
> +test_texture(GLuint tex)
> +{
> +       int layer, lod;
> +       GLint tex_loc;
> +       GLboolean pass = GL_TRUE;
> +       glUseProgram(use_tex_program);
> +       glActiveTexture(GL_TEXTURE0);
> +       tex_loc = glGetUniformLocation(use_tex_program, "tex");
> +       glUniform1i(tex_loc, 0);
> +
> +       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
> +                       GL_NEAREST_MIPMAP_NEAREST);
> +       glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
> +                       GL_NEAREST);
> +
> +       for (lod = 0; lod < LOD; lod++) {
> +               for (layer = 0; layer < LAYERS; layer++) {
> +                       draw_box(tex, layer, lod);
> +                       pass = test_results(layer, lod) && pass;
> +               }
> +       }
>

You might want to consider separating this into two loops, one to do all
the draw_box() calls and one to do all the test_results() calls.  That will
make it easier to run this test in the simulator, because all of the
drawing will go into a single batch buffer.


> +
> +       glUseProgram(0);
> +       return pass;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       GLboolean pass;
> +       GLuint vao, fbo;
> +       GLuint tex;
> +       static GLfloat verts[4][2] = {
> +               { 1.0, -1.0},
> +               {-1.0, -1.0},
> +               { 1.0,  1.0},
> +               {-1.0,  1.0},
> +       };
> +
> +       /* Clear background to gray */
> +       glClearColor(0.5, 0.5, 0.5, 1.0);
> +       glClear(GL_COLOR_BUFFER_BIT);
> +
> +       glGenFramebuffers(1, &fbo);
> +       glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> +       glGenVertexArrays(1, &vao);
> +       glBindVertexArray(vao);
> +       glGenBuffers(1, &rectangle_vertices_bo);
> +       glBindBuffer(GL_ARRAY_BUFFER, rectangle_vertices_bo);
> +       glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts,
> GL_STATIC_DRAW);
> +
> +       tex = build_texture();
> +       pass = test_texture(tex);
> +       glDeleteTextures(1, &tex);
> +
> +       piglit_present_results();
> +
> +       glDeleteBuffers(1, &rectangle_vertices_bo);
> +       glDeleteFramebuffers(1, &fbo);
> +       glDeleteVertexArrays(1, &vao);
> +
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       GLuint vs, fs;
> +
> +       /* For glFramebufferTexture we need either GL 3.2 or
> +        * GL_ARB_geometry_shader4.
> +        */
> +       if (piglit_get_gl_version() < 32) {
> +               piglit_require_extension("GL_ARB_geometry_shader4");
> +       }
>

Wow, I didn't realize that AMD_vertex_shader_layer didn't provide
glFramebufferTexture().  This extension is of startlingly limited use
without geometry shaders!


> +
> +       piglit_require_extension("GL_AMD_vertex_shader_layer");
> +
> +       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, fill_tex_vs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fill_tex_fs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +       fill_tex_program = piglit_link_simple_program(vs, fs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       vs = piglit_compile_shader_text(GL_VERTEX_SHADER, use_tex_vs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +       fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, use_tex_fs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +       use_tex_program = piglit_link_simple_program(vs, fs);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +}
> --
> 1.7.10.4
>
>
Of all my comments, the only one I think is critical is the
glBindAttribLocation() issue.  With that fixed, this test is:

Reviewed-by: Paul Berry <stereotype441 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20130430/87a811bc/attachment-0001.html>


More information about the Piglit mailing list