[Piglit] [PATCH 2/3] GL 3.2: Test gl_Layer when unassigned or no geometry shader

Paul Berry stereotype441 at gmail.com
Wed Sep 4 09:29:09 PDT 2013


On 3 September 2013 15:52, Jacob Penner <jkpenner91 at gmail.com> wrote:

> ---
>  tests/all.tests                                    |   1 +
>  .../gl-3.2/layered-rendering/CMakeLists.gl.txt     |   1 +
>  tests/spec/gl-3.2/layered-rendering/gl-layer.c     | 243
> +++++++++++++++++++++
>  3 files changed, 245 insertions(+)
>  create mode 100644 tests/spec/gl-3.2/layered-rendering/gl-layer.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 877253d..59fb0e2 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -752,6 +752,7 @@ spec['!OpenGL 3.2/layered-rendering/blit'] =
> concurrent_test('gl-3.2-layered-ren
>  spec['!OpenGL 3.2/layered-rendering/clear-color'] =
> concurrent_test('gl-3.2-layered-rendering-clear-color')
>  spec['!OpenGL 3.2/layered-rendering/framebuffertexture-buffer-textures']
> =
> concurrent_test('gl-3.2-layered-rendering-framebuffertexture-buffer-textures')
>  spec['!OpenGL 3.2/layered-rendering/readpixels'] =
> concurrent_test('gl-3.2-layered-rendering-readpixels')
> +spec['!OpenGL 3.2/layered-rendering/gl-layer'] =
> concurrent_test('gl-3.2-layered-rendering-gl-layer')
>
>  spec['!OpenGL 3.3/minmax'] = concurrent_test('gl-3.3-minmax')
>  spec['!OpenGL 3.3/required-renderbuffer-attachment-formats'] =
> concurrent_test('gl-3.0-required-renderbuffer-attachment-formats 33')
> diff --git a/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt
> b/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt
> index 2a66253..9a26b34 100644
> --- a/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt
> +++ b/tests/spec/gl-3.2/layered-rendering/CMakeLists.gl.txt
> @@ -13,4 +13,5 @@ piglit_add_executable (gl-3.2-layered-rendering-blit
> blit.c)
>  piglit_add_executable (gl-3.2-layered-rendering-clear-color clear-color.c)
>  piglit_add_executable
> (gl-3.2-layered-rendering-framebuffertexture-buffer-textures
> framebuffertexture-buffer-textures.c)
>  piglit_add_executable (gl-3.2-layered-rendering-readpixels readpixels.c)
> +piglit_add_executable (gl-3.2-layered-rendering-gl-layer gl-layer.c)
>  # vim: ft=cmake:
> diff --git a/tests/spec/gl-3.2/layered-rendering/gl-layer.c
> b/tests/spec/gl-3.2/layered-rendering/gl-layer.c
> new file mode 100644
> index 0000000..fe557b2
> --- /dev/null
> +++ b/tests/spec/gl-3.2/layered-rendering/gl-layer.c
> @@ -0,0 +1,243 @@
> +/*
> + * Copyright © 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.
> + */
> +
> +/** @file gl-layer.c
> + *
> + * Section 4.4.7(Framebuffer Objects) From GL spec 3.2 core:
> + *
> + * When rendering to a layered framebuffer, each fragment generated by
> + * the GL is assigned a layer number. The layer number for a fragment
> + * is zero if
> + *
> + *      - geometry shaders are disabled, or
> + *
> + *      - The current geometry shader does not statically assign a
> + * value to the built-in output variable gl_Layer.
> + *
> + *
> + * Test
> + *    Draw a rect onto a layered texture with two different programs. One
> + *  program will contain a geometry shader that doesn't assign a value to
> + *  gl_Layer, while the other program will not contain a geometry shader.
> + *
> + * End Result
> + *    The first layer of both textures used while have their values be
> green or
> + *  (0, 1, 0), and the remaining layers will be not set.
> + */
> +
> + #include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +       config.supports_gl_compat_version = 32;
> +       config.supports_gl_core_version = 32;
> +
> +       config.window_visual = PIGLIT_GL_VISUAL_RGB |
> PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +const char *vs_source = {
> +       "#version 150\n"
> +       "in vec4 piglit_vertex;\n"
> +       "out vec4 vert;\n"
> +       "void main() {\n"
> +       "       gl_Position = piglit_vertex;\n"
> +       "       vert = piglit_vertex;\n"
> +       "}\n"
> +};
> +
> +const char *gs_source = {
> +       "#version 150\n"
> +       "layout(triangles) in;\n"
> +       "layout(triangles, max_vertices = 3) out;\n"
> +       "in vec4 vert[3];\n"
> +       "\n"
> +       "void main()\n"
> +       "{\n"
> +       "       for(int i = 0; i < 3; i++) {\n"
> +       "               gl_Position = vert[i];\n"
> +       "               EmitVertex();\n"
> +       "       }\n"
> +       "}\n"
> +};
> +
> +const char *fs_source = {
> +       "#version 150\n"
> +       "void main() {\n"
> +       "       gl_FragColor = vec4(0, 1, 0, 1);\n"
> +       "}\n"
> +};
> +
> +GLint build_program(const char *vs_source, const char *gs_source,
> +                   const char *fs_source)
> +{
> +       GLuint vs = 0, gs = 0, fs = 0, prog;
> +
> +       if(vs_source)
> +               vs = piglit_compile_shader_text(GL_VERTEX_SHADER,
> vs_source);
> +       if(gs_source)
> +               gs = piglit_compile_shader_text(GL_GEOMETRY_SHADER,
> gs_source);
> +       if(fs_source)
> +               fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
> fs_source);
> +
> +       piglit_require_GLSL();
> +
> +       prog = glCreateProgram();
> +
> +       if (vs)
> +               glAttachShader(prog, vs);
> +       if (gs)
> +               glAttachShader(prog, gs);
> +       if (fs)
> +               glAttachShader(prog, fs);
> +
> +       glLinkProgram(prog);
> +
> +       if(!piglit_link_check_status(prog)) {
> +               glDeleteProgram(prog);
> +               prog = 0;
> +       }
> +
> +       if(!prog)
> +               piglit_report_result(PIGLIT_FAIL);
> +
> +       if(fs)
> +               glDeleteShader(fs);
> +       if(gs)
> +               glDeleteShader(gs);
> +       if(vs)
> +               glDeleteShader(vs);
> +
> +       return prog;
> +}
>

This function seems a lot more general-purpose than what we need for this
particular test (in particular, in this test, gs is the only string that
will ever be null).

If you want to make a separate patch that puts this function (suitably
renamed) into tests/util/piglit-shader.c, I'd be happy with it as is (in
fact, I'd be delighted--there are other geometry shader tests that could
use this function, and it would be nice to share some code).


> +
> +bool
> +probe_texture_layered_rbg(GLuint texture, int x, int y, int z,
> +                         int w, int h, int d, float *expected)
>

I think you mean "probe_texture_layered_rgb".


> +{
> +       int k;
> +       GLuint fbo;
> +
> +       glGenFramebuffers(1, &fbo);
> +       glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> +
> +       for(k = 0; k < d; k++ ) {
> +               glFramebufferTextureLayer(GL_FRAMEBUFFER,
> GL_COLOR_ATTACHMENT0,
> +                                         texture, 0, z + k);
> +
> +               if(!piglit_probe_rect_rgb(0, 0, w, h, &expected[k*3])) {
> +                       printf("Layer: %i\n", z + k);
> +                       return false;
> +               }
> +       }
> +
> +       return true;
> +}
> +
> +
> +static GLuint fbo[2];
> +static GLint program[2];
> +static GLuint texture[2];
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       int i;
> +       GLuint fboStatus;
> +
> +       program[0] = build_program(vs_source, gs_source, fs_source);
> +       program[1] = build_program(vs_source,      NULL, fs_source);
> +
> +       glGenFramebuffers(2, fbo);
> +       glGenTextures(2, texture);
> +
> +       for( i = 0; i < 2; i++) {
> +               glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
> +
> +               glBindTexture(GL_TEXTURE_2D_ARRAY, texture[i]);
> +               glTexParameteri(GL_TEXTURE_2D_ARRAY,
> GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> +               glTexParameteri(GL_TEXTURE_2D_ARRAY,
> GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> +               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S,
> GL_REPEAT);
> +               glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T,
> GL_REPEAT);
> +               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB, 10,
> +                            10, 2, 0, GL_RGB, GL_FLOAT, NULL);
> +
> +               glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> +                                    texture[i], 0);
> +
> +               fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +               if(fboStatus != GL_FRAMEBUFFER_COMPLETE) {
> +                       printf("Framebuffer Status: %s\n",
> +                              piglit_get_gl_enum_name(fboStatus));
> +                       piglit_report_result(PIGLIT_FAIL);
> +               }
> +       }
> +
> +       if(!piglit_check_gl_error(GL_NO_ERROR)) {
> +               piglit_report_result(PIGLIT_FAIL);
> +       }
> +}
>

Since the test doesn't actually do any rendering to the screen, there's no
need to separate piglit_init() and piglit_display().  I have a minor
preference to just merge them into one function, as you did in patch 1.
But I don't have terribly strong feelings about that.


> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       int i;
> +       bool pass = true;
> +       float expected[] = {
> +               0.0, 1.0, 0.0,
> +               0.0, 0.0, 0.0
> +       };
> +
> +       for( i = 0; i < 2; i++) {
> +               glUseProgram(program[i]);
> +               glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
> +
> +               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +               piglit_draw_rect(-1, -1, 2, 2);
> +
> +               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +               pass = probe_texture_layered_rbg(texture[i], 0, 0, 0,
> +                                                10, 10, 2, expected) &&
> pass;
> +       }
> +
> +       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[0]);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
> +       glBlitFramebuffer(0, 0, 10, 10,
> +                         0, 0, piglit_width/2, piglit_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[1]);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
> +       glBlitFramebuffer(0, 0, 10, 10,
> +                         piglit_width/2, 0, piglit_width, piglit_height,
> +                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +
> +       piglit_present_results();
> +
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> --
> 1.8.3.1
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20130904/edb221fd/attachment.html>


More information about the Piglit mailing list