[Piglit] [PATCH] initial ARB_texture_rgb10_a2ui test

Dave Airlie airlied at gmail.com
Sun Nov 27 10:28:36 PST 2011


On Sun, Nov 27, 2011 at 5:22 PM, Dave Airlie <airlied at gmail.com> wrote:
> From: Dave Airlie <airlied at redhat.com>
>
> This test tries to upload the texture in RGBA/BGRA and 10_10_10_2/2_10_10_10_REV
> type/format combinations.

Actually I could really do with someone running this on nvidia, I got
fglrx to execute and fail on the RGBA/10_10_10_2 version,

This test is also bit badly written when I re-read it in my inbox :-)

Dave.

>
> it seems to fail on fglrx, but not sure if thats my fault or fglrx.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  tests/spec/CMakeLists.txt                          |    1 +
>  .../spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt  |   17 ++
>  tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt   |    1 +
>  .../arb_texture_rgb10_a2ui/texture-rgb10a2ui.c     |  287 ++++++++++++++++++++
>  4 files changed, 306 insertions(+), 0 deletions(-)
>  create mode 100644 tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
>  create mode 100644 tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
>  create mode 100644 tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
>
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index 863d583..778fec8 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -37,3 +37,4 @@ add_subdirectory (ext_texture_integer)
>  add_subdirectory (arb_draw_buffers)
>  add_subdirectory (oes_draw_texture)
>  add_subdirectory (arb_blend_func_extended)
> +add_subdirectory (arb_texture_rgb10_a2ui)
> diff --git a/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..683c075
> --- /dev/null
> +++ b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.gl.txt
> @@ -0,0 +1,17 @@
> +include_directories(
> +       ${GLEXT_INCLUDE_DIR}
> +       ${OPENGL_INCLUDE_PATH}
> +       ${GLUT_INCLUDE_DIR}
> +       ${piglit_SOURCE_DIR}/tests/util
> +)
> +
> +link_libraries (
> +       piglitutil
> +       ${OPENGL_gl_LIBRARY}
> +       ${OPENGL_glu_LIBRARY}
> +       ${GLUT_glut_LIBRARY}
> +)
> +
> +add_executable (arb_texture_rgb10_a2ui-texture texture-rgb10a2ui.c)
> +
> +# vim: ft=cmake:
> diff --git a/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/arb_texture_rgb10_a2ui/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c b/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
> new file mode 100644
> index 0000000..fc9d6a5
> --- /dev/null
> +++ b/tests/spec/arb_texture_rgb10_a2ui/texture-rgb10a2ui.c
> @@ -0,0 +1,287 @@
> +/*
> + * Copyright (c) 2011 Dave Airlie
> + *
> + * 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
> + * on the rights to use, copy, modify, merge, publish, distribute, sub
> + * license, 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
> + * NON-INFRINGEMENT.  IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
> + * 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
> + * Tests GL_ARB_texture_rgb10_a2ui formats/upload paths.
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 100, piglit_height = 100;
> +int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
> +
> +static const char *TestName = "texture-integer";
> +
> +static GLint TexWidth = 16, TexHeight = 16;
> +static GLuint Texture;
> +
> +static GLint BiasUniform = -1, TexUniform = -1;
> +
> +struct format_info
> +{
> +       const char *Name;
> +       GLenum IntFormat, BaseFormat;
> +       GLuint BitsPerChannel;
> +       GLboolean nonrev;
> +};
> +
> +static const struct format_info Formats[] = {
> +       { "GL_RGB10_A2UI", GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, 10,  GL_FALSE  },
> +       { "GL_RGB10_A2UI (rev)", GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, 10,  GL_TRUE },
> +       { "GL_RGB10_A2UI (bgra)", GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, 10,  GL_FALSE  },
> +       { "GL_RGB10_A2UI (bgra-rev)", GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, 10,  GL_TRUE  },
> +};
> +
> +static const char *FragShaderText =
> +       "#version 130\n"
> +       "uniform vec4 bias; \n"
> +       "uniform isampler2D tex; \n"
> +       "void main() \n"
> +       "{ \n"
> +       "   vec4 t = vec4(texture(tex, gl_TexCoord[0].xy)); \n"
> +       "   gl_FragColor = t + bias; \n"
> +       "} \n";
> +
> +static GLuint FragShader, Program;
> +
> +static void
> +fill_array(int comps, int texels, void *buf, int baseformat,
> +          int nonrev, const int val[4])
> +{
> +       int i;
> +
> +       switch (baseformat) {
> +       case GL_RGBA_INTEGER_EXT:
> +               if (!nonrev) {
> +                       GLuint *b = (GLuint *)buf;
> +                       for (i = 0; i < texels; i++) {
> +                               b[i] = (val[0] & 0x3ff) << 0 |
> +                                       (val[1] & 0x3ff) << 10 |
> +                                       (val[2] & 0x3ff) << 20 |
> +                                       (val[3] & 0x3) << 30;
> +                       }
> +               } else {
> +                       GLuint *b = (GLuint *)buf;
> +                       for (i = 0; i < texels; i++) {
> +                               b[i] = (val[3] & 0x3) << 0 |
> +                                       (val[0] & 0x3ff) << 22 |
> +                                       (val[1] & 0x3ff) << 12 |
> +                                       (val[2] & 0x3ff) << 2;
> +                       }
> +               }
> +               break;
> +       case GL_BGRA_INTEGER_EXT:
> +               if (!nonrev) {
> +                       GLuint *b = (GLuint *)buf;
> +                       for (i = 0; i < texels; i++) {
> +                               b[i] = (val[0] & 0x3ff) << 20 |
> +                                       (val[1] & 0x3ff) << 10 |
> +                                       (val[2] & 0x3ff) << 0 |
> +                                       (val[3] & 0x3) << 30;
> +                       }
> +               } else {
> +                       GLuint *b = (GLuint *)buf;
> +                       for (i = 0; i < texels; i++) {
> +                               b[i] = (val[3] & 0x3) << 0 |
> +                                       (val[0] & 0x3ff) << 2 |
> +                                       (val[1] & 0x3ff) << 12 |
> +                                       (val[2] & 0x3ff) << 22;
> +                       }
> +               }
> +               break;
> +
> +       }
> +}
> +
> +
> +static GLenum
> +get_datatype(const struct format_info *info)
> +{
> +       return info->nonrev ? GL_UNSIGNED_INT_10_10_10_2 :
> +               GL_UNSIGNED_INT_2_10_10_10_REV;
> +}
> +
> +
> +static GLboolean
> +check_error(const char *file, int line)
> +{
> +       GLenum err = glGetError();
> +       if (err) {
> +               fprintf(stderr, "%s: error 0x%x at %s:%d\n",
> +                       TestName, err, file, line);
> +               return GL_TRUE;
> +       }
> +       return GL_FALSE;
> +}
> +
> +
> +/** \return GL_TRUE for pass, GL_FALSE for fail */
> +static GLboolean
> +test_format(const struct format_info *info)
> +{
> +       const int max = 1023;
> +       const int comps = 4;
> +       const int texels = TexWidth * TexHeight;
> +       const GLenum type = get_datatype(info);
> +       const int w = piglit_width / 10;
> +       const int h = piglit_height / 10;
> +       const float error = 2.0 / 255.0; /* XXX fix */
> +       GLfloat expected[4];
> +       void *buf;
> +       int value[4];
> +       GLfloat result[4], bias[4];
> +       GLint f;
> +
> +       /* don't use random values, just pick some */
> +       value[0] = 355 % max;
> +       value[1] = 768 % max;
> +       value[2] = 423 % max;
> +       value[3] = 1;
> +
> +       /* alloc, fill texture image */
> +       buf = malloc(texels * 4);
> +       fill_array(comps, texels, buf, info->BaseFormat, info->nonrev, value);
> +
> +       glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
> +                    info->BaseFormat, type, buf);
> +
> +       if (check_error(__FILE__, __LINE__))
> +               return GL_FALSE;
> +
> +       glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
> +                                &f);
> +       /*
> +         assert(f == info->IntFormat);
> +       */
> +
> +       /* setup expected polygon color */
> +       expected[0] = 0.25;
> +       expected[1] = 0.50;
> +       expected[2] = 0.75;
> +       expected[3] = 1.00;
> +
> +       /* compute, set test bias */
> +       bias[0] = expected[0] - value[0];
> +       bias[1] = expected[1] - value[1];
> +       bias[2] = expected[2] - value[2];
> +       bias[3] = expected[3] - value[3];
> +       glUniform4fv(BiasUniform, 1, bias);
> +
> +       /* draw */
> +       glClearColor(0, 1, 1, 0);
> +       glClear(GL_COLOR_BUFFER_BIT);
> +       glBegin(GL_POLYGON);
> +       glTexCoord2f(0, 0);   glVertex2f(0, 0);
> +       glTexCoord2f(1, 0);   glVertex2f(w, 0);
> +       glTexCoord2f(1, 1);   glVertex2f(w, h);
> +       glTexCoord2f(0, 1);   glVertex2f(0, h);
> +       glEnd();
> +
> +       if (check_error(__FILE__, __LINE__))
> +               return GL_FALSE;
> +
> +       /* test */
> +       glReadPixels(w/2, h/2, 1, 1, GL_RGBA, GL_FLOAT, result);
> +
> +       if (check_error(__FILE__, __LINE__))
> +               return GL_FALSE;
> +
> +       if (fabsf(result[0] - expected[0]) > error ||
> +           fabsf(result[1] - expected[1]) > error ||
> +           fabsf(result[2] - expected[2]) > error ||
> +           fabsf(result[3] - expected[3]) > error) {
> +               fprintf(stderr, "%s: failure with format %s:\n",
> +                       TestName, info->Name);
> +               fprintf(stderr, "  texture color = %d, %d, %d, %d\n",
> +                       value[0], value[1], value[2], value[3]);
> +               fprintf(stderr, "  expected color = %g, %g, %g, %g\n",
> +                       expected[0], expected[1], expected[2], expected[3]);
> +               fprintf(stderr, "  result color = %g, %g, %g, %g\n",
> +                       result[0], result[1], result[2], result[3]);
> +               return GL_FALSE;
> +       }
> +
> +       piglit_present_results();
> +
> +       free(buf);
> +
> +       return GL_TRUE;
> +}
> +
> +
> +static GLboolean
> +test_general_formats(void)
> +{
> +       int f, i;
> +
> +       for (f = 0; f < ARRAY_SIZE(Formats); f++) {
> +               for (i = 0; i < 5; i++) {
> +                       if (!test_format(&Formats[f]))
> +                               return GL_FALSE;
> +               }
> +       }
> +       return GL_TRUE;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +       if (!test_general_formats())
> +               return PIGLIT_FAIL;
> +
> +       return PIGLIT_PASS;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +       piglit_require_extension("GL_ARB_texture_rgb10_a2ui");
> +       piglit_require_GLSL_version(130);
> +
> +       FragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
> +                                               FragShaderText);
> +       assert(FragShader);
> +
> +       Program = piglit_link_simple_program(0, FragShader);
> +
> +       glUseProgram(Program);
> +
> +       BiasUniform = glGetUniformLocation(Program, "bias");
> +       TexUniform = glGetUniformLocation(Program, "tex");
> +
> +       glUniform1i(TexUniform, 0);  /* tex unit zero */
> +
> +       (void) check_error(__FILE__, __LINE__);
> +
> +       glGenTextures(1, &Texture);
> +       glBindTexture(GL_TEXTURE_2D, Texture);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> +       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> +
> +       (void) check_error(__FILE__, __LINE__);
> +
> +       piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +}
> --
> 1.7.7.3
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>


More information about the Piglit mailing list