[Piglit] [PATCH 04/15] arb_direct_state_access: Test NamedFramebufferTexture[Layer].

Anuj Phogat anuj.phogat at gmail.com
Thu Apr 2 14:59:44 PDT 2015


On Thu, Mar 5, 2015 at 6:01 PM, Laura Ekstrand <laura at jlekstrand.net> wrote:
> ---
>  tests/all.py                                       |   1 +
>  .../spec/arb_direct_state_access/CMakeLists.gl.txt |   1 +
>  .../spec/arb_direct_state_access/framebufferblit.c | 326 +++++++++++++++++++++
>  3 files changed, 328 insertions(+)
>  create mode 100644 tests/spec/arb_direct_state_access/framebufferblit.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 8e45442..71b4498 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -4029,6 +4029,7 @@ spec['ARB_direct_state_access']['flushmappednamedbufferrange'] = PiglitGLTest(['
>  spec['ARB_direct_state_access']['getnamedbufferparameter'] = PiglitGLTest(['arb_direct_state_access-getnamedbufferparameter'], run_concurrent=True)
>  spec['ARB_direct_state_access']['getnamedbuffersubdata'] = PiglitGLTest(['arb_direct_state_access-getnamedbuffersubdata'], run_concurrent=True)
>  spec['ARB_direct_state_access']['namedframebufferrenderbuffer'] = PiglitGLTest(['arb_direct_state_access-namedframebufferrenderbuffer'], run_concurrent=True)
> +spec['ARB_direct_state_access']['framebufferblit'] = PiglitGLTest(['arb_direct_state_access-framebufferblit'], run_concurrent=True)
>
>  arb_shader_image_load_store = spec['ARB_shader_image_load_store']
>  arb_shader_image_load_store['atomicity'] = PiglitGLTest(['arb_shader_image_load_store-atomicity'], run_concurrent=True)
> diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> index 488ca18..727acc2 100644
> --- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> +++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> @@ -26,6 +26,7 @@ piglit_add_executable (arb_direct_state_access-flushmappednamedbufferrange flush
>  piglit_add_executable (arb_direct_state_access-getnamedbufferparameter getnamedbufferparameter.c)
>  piglit_add_executable (arb_direct_state_access-getnamedbuffersubdata getnamedbuffersubdata.c)
>  piglit_add_executable (arb_direct_state_access-namedframebufferrenderbuffer namedframebufferrenderbuffer.c)
> +piglit_add_executable (arb_direct_state_access-framebufferblit framebufferblit.c)
>  piglit_add_executable (arb_direct_state_access-dsa-textures dsa-textures.c dsa-utils.c)
>  piglit_add_executable (arb_direct_state_access-texturesubimage texturesubimage.c)
>  piglit_add_executable (arb_direct_state_access-bind-texture-unit bind-texture-unit.c)
> diff --git a/tests/spec/arb_direct_state_access/framebufferblit.c b/tests/spec/arb_direct_state_access/framebufferblit.c
> new file mode 100644
> index 0000000..e405dec
> --- /dev/null
> +++ b/tests/spec/arb_direct_state_access/framebufferblit.c
> @@ -0,0 +1,326 @@
> +/*
> + * Copyright © 2013, 2015 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 framebufferblit.c
> + *
> + * Section 4.3.2(Reading and Copying Pixels) From GL spec 3.2 core:
> + *   If the read framebuffer is layered (see section 4.4.7), pixel values are
> + * read from layer zero. If the draw framebuffer is layered, pixel values are
> + * written to layer zero. If both read and draw framebuffers are layered, the
> + * blit operation is still performed only on layer zero.
> + *
> + * Test Layout
> + * *-------*-------*    test1:
> + * |       |       |      Source tex is layered, destination tex is layered
> + * | test3 | test4 |    test2:
> + * |       |       |      Source tex is layered, destination tex is not layered
> + * *-------*-------*    test3:
> + * |       |       |      Source tex is not layered, destination tex is layered
> + * | test1 | test2 |    test4:
> + * |       |       |      Source tex is not layered, destination tex is not layered
> + * *-------*-------*
> + *
> + *    src dst           Each Test
> + *   *---*---*             Display source tex layers on left
> + *   |   |   | layer 1     Blit source tex to destination tex
> + *   *---*---*             Display resulting layers
> + *   |   |   | layer 2
> + *   *---*---*
> + *
> + * Based on tests/spec/gl-3.2/layered-rendering/blit.c
> + * This file tests this with direct state access.
> + */
> +
> +#include "piglit-util-gl.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
> +
> +/* Values Set in piglit init */
> +static const int texWidth  = 32;
> +static const int texHeight = 32;
> +static const int texDepth  = 2;
> +
> +static const float srcColors[2][3] = {
> +       {0.5, 0.4, 0.3}, {0, 1, 0}
> +};
> +
> +static const float dstColors[2][3] = {
> +       {0, 0, 1}, {0, 1, 1}
> +};
> +
> +/*
> + * Blit the passed texture to the screen. If texture is layered,
> + * loops through each layer and blit it to the screen. Otherwise scales
> + * the layer zero vertically with a factor of texDepth.
> + */
> +bool
> +display_texture(int x, int y, GLuint tex, int layers)
> +{
> +       GLuint tempFBO;
> +       GLenum fbStatus;
> +
> +       /* Gen temp fbo to work with */
> +       glCreateFramebuffers(1, &tempFBO);
> +
> +       if (layers == 1) {
> +               glNamedFramebufferTexture(tempFBO, GL_COLOR_ATTACHMENT0,
> +                                         tex, 0);
> +
> +               /* Blit layer to screen */
> +               glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
> +               glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO);
> +               glBlitFramebuffer(0, 0, texWidth, texHeight,
> +                                 x, y, x + texWidth, y + texDepth * texHeight,
> +                                 GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +       } else {
> +               int i;
> +
> +               /* loop through each layer */
> +               for (i = 0; i < layers; i++) {
> +                       /* Bind new layer to display */
> +                       glNamedFramebufferTextureLayer(tempFBO,
> +                                                      GL_COLOR_ATTACHMENT0,
> +                                                      tex, 0, i);
> +
> +                       glBindFramebuffer(GL_FRAMEBUFFER, tempFBO);
> +                       fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +                       if (fbStatus != GL_FRAMEBUFFER_COMPLETE) {
> +                               printf("Framebuffer Status: %s\n",
> +                                      piglit_get_gl_enum_name(fbStatus));
> +                               return false;
> +                       }
> +
> +                       /* Blit layer to screen */
> +                       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
> +                       glBindFramebuffer(GL_READ_FRAMEBUFFER, tempFBO);
> +                       glBlitFramebuffer(0, 0, texWidth, texHeight,
> +                                         x,
> +                                          y + i * texHeight,
> +                                         x + texWidth,
> +                                          y + (i + 1) * texHeight,
> +                                         GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +               }
> +       }
> +
> +       /* Cleanup temp fbo */
> +       glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
> +       glDeleteFramebuffers(1, &tempFBO);
> +
> +       return piglit_check_gl_error(GL_NO_ERROR);
> +}
> +
> +float *
> +gen_color_data(int layers, bool useSrcTex)
> +{
> +       int i, j;
> +       float *colorData = malloc(layers * texWidth * texHeight * 3 *
> +                               sizeof(float));
> +
> +       for (j = 0; j < layers; j++) {
> +               for (i = 0; i < texWidth * texHeight; i++) {
> +                       int offset = j * texWidth * texHeight * 3 + i * 3;
> +                       if (useSrcTex) {
> +                               colorData[offset + 0] = srcColors[j][0];
> +                               colorData[offset + 1] = srcColors[j][1];
> +                               colorData[offset + 2] = srcColors[j][2];
> +                       } else {
> +                               colorData[offset + 0] = dstColors[j][0];
> +                               colorData[offset + 1] = dstColors[j][1];
> +                               colorData[offset + 2] = dstColors[j][2];
> +                       }
> +               }
> +       }
> +
> +       return colorData;
> +}
> +
> +GLuint
> +create_bind_texture(GLenum textureType, bool useSrcTex)
> +{
> +       GLuint texture = 0;
> +       float *colorData = NULL;
> +
> +       piglit_check_gl_error(GL_NO_ERROR);
> +
> +       glCreateTextures(textureType, 1, &texture);
> +       glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> +       glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> +
> +       switch (textureType) {
> +       case GL_TEXTURE_2D:
> +               colorData = gen_color_data(1, useSrcTex);
> +               glTextureStorage2D(texture, 1, GL_RGB8, texWidth, texHeight);
> +               glTextureSubImage2D(texture, 0, 0, 0, texWidth, texHeight,
> +                                   GL_RGB, GL_FLOAT, colorData);
> +               break;
> +       case GL_TEXTURE_3D:
> +               colorData = gen_color_data(texDepth, useSrcTex);
> +               glTextureStorage3D(texture, 1, GL_RGB8, texWidth, texHeight,
> +                                  texDepth);
> +               glTextureSubImage3D(texture, 0, 0, 0, 0,
> +                                   texWidth, texHeight, texDepth,
> +                                   GL_RGB, GL_FLOAT, colorData);
> +               break;
> +       }
> +
> +       if (!piglit_check_gl_error(GL_NO_ERROR)) {
> +               glDeleteTextures(1, &texture);
> +               texture = 0;
> +       }
> +
> +       if (colorData != NULL)
> +               free(colorData);
> +
> +       return texture;
> +}
> +
> +bool
> +testFramebufferBlitLayered(int x, int y, bool srcLayered, bool dstLayered)
> +{
> +       bool pass = true;
> +       GLuint srcFBO, dstFBO;
> +       GLuint srcTex, dstTex;
> +       GLenum fbStatus;
> +
> +       /* Set up source fbo */
> +       glCreateFramebuffers(1, &srcFBO);
> +       piglit_check_gl_error(GL_NO_ERROR);
> +       if (srcLayered)
> +               srcTex = create_bind_texture(GL_TEXTURE_3D, true);
> +       else
> +               srcTex = create_bind_texture(GL_TEXTURE_2D, true);
> +       glNamedFramebufferTexture(srcFBO, GL_COLOR_ATTACHMENT0, srcTex, 0);
> +
> +       /* Check source framebuffer status */
> +       glBindFramebuffer(GL_FRAMEBUFFER, srcFBO);
> +       fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +       if (fbStatus != GL_FRAMEBUFFER_COMPLETE) {
> +               printf("testFramebufferBlitLayered srcFBO Status: %s\n",
> +                      piglit_get_gl_enum_name(fbStatus));
> +               return false;
> +       }
> +
> +       /* Set up dst fbo */
> +       glCreateFramebuffers(1, &dstFBO);
> +       if (dstLayered)
> +               dstTex = create_bind_texture(GL_TEXTURE_3D, false);
> +       else
> +               dstTex = create_bind_texture(GL_TEXTURE_2D, false);
> +       glNamedFramebufferTexture(dstFBO, GL_COLOR_ATTACHMENT0, dstTex, 0);
> +
> +       /* Check destination framebuffer status */
> +       glBindFramebuffer(GL_FRAMEBUFFER, dstFBO);
> +       fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
> +       if (fbStatus != GL_FRAMEBUFFER_COMPLETE) {
> +               printf("testFramebufferBlitLayered dstFBO Status: %s\n",
> +                      piglit_get_gl_enum_name(fbStatus));
> +               return false;
> +       }
> +
> +       /* Check for if any errors have occured */
> +       if (!piglit_check_gl_error(GL_NO_ERROR)) {
> +               printf("Error setting up framebuffers for test.\n");
> +               return false;
> +       }
> +
> +       /* Blit from source to destination framebuffers */
> +       glBindFramebuffer(GL_READ_FRAMEBUFFER, srcFBO);
> +       glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dstFBO);
> +       glBlitFramebuffer(0, 0, texWidth, texHeight,
> +                         0, 0, texWidth, texHeight,
> +                         GL_COLOR_BUFFER_BIT, GL_LINEAR);
> +
> +       /* Display the results */
> +       display_texture(x, y, srcTex, srcLayered ? texDepth : 1);
> +       display_texture(x + texWidth, y, dstTex, dstLayered ? texDepth : 1);
> +
> +       /* Check for pass condition */
> +       if (dstLayered) {
> +               pass = piglit_probe_rect_rgb(x + texWidth, y,
> +                                texWidth, texHeight, srcColors[0]) && pass;
> +               pass = piglit_probe_rect_rgb(x + texWidth, y + texHeight,
> +                                texWidth, texHeight, dstColors[1]) && pass;
> +       } else {
> +               pass = piglit_probe_rect_rgb(x + texWidth, y, texWidth,
> +                                texDepth * texHeight, srcColors[0]) && pass;
> +       }
> +
> +       /* Clean up */
> +       glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
> +       glDeleteFramebuffers(1, &srcFBO);
> +       glDeleteFramebuffers(1, &dstFBO);
> +       glDeleteTextures(1, &srcTex);
> +       glDeleteTextures(1, &dstTex);
> +
> +       /* Check for if any errors have occured */
> +       if (!piglit_check_gl_error(GL_NO_ERROR)) {
> +               printf("Error setting up framebuffers for test.\n");
> +               return false;
> +       }
> +
> +       return pass;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       piglit_require_extension("GL_ARB_direct_state_access");
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       bool pass = true;
> +
> +       glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
> +       glClearColor(1,1,1,1);
> +       glClear(GL_COLOR_BUFFER_BIT);
> +
> +       /* Source is layered, destination is layered */
> +       pass = testFramebufferBlitLayered(0, 0, true, true) && pass;
> +
> +       /* Source is layered, destination is not layered */
> +       pass = testFramebufferBlitLayered(2 * texWidth, 0, true, false) && pass;
> +
> +       /* Source not is layered, destination is layered */
> +       pass = testFramebufferBlitLayered(0, texDepth * texHeight, false,
> +                                        true) && pass;
> +
> +       /* Source not is layered, destination is not layered */
> +       pass = testFramebufferBlitLayered(2 * texWidth, texDepth * texHeight,
> +                                        false, false) && pass;
> +
> +       /* Check for if any errors have occured */
> +       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +       piglit_present_results();
> +
> +       return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> --
> 2.1.0
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit

Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the Piglit mailing list