[Piglit] [PATCH 1/2 v2] getteximage-targets: Refactor and cleanup with generalized texture targets

Chia-I Wu olvaffe at gmail.com
Sat Mar 22 00:30:31 PDT 2014


On Sat, Mar 22, 2014 at 3:26 PM, Chia-I Wu <olvaffe at gmail.com> wrote:

> On Sat, Mar 22, 2014 at 5:03 AM, Jon Ashburn <jon at lunarg.com> wrote:
>
>> ---
>>  tests/texturing/getteximage-targets.c | 225
>> +++++++++++++++++++---------------
>>  1 file changed, 127 insertions(+), 98 deletions(-)
>>
>> diff --git a/tests/texturing/getteximage-targets.c
>> b/tests/texturing/getteximage-targets.c
>> index 383ee03..1b626db 100644
>> --- a/tests/texturing/getteximage-targets.c
>> +++ b/tests/texturing/getteximage-targets.c
>> @@ -41,29 +41,34 @@ piglit_display(void)
>>
>>  #define IMAGE_WIDTH 32
>>  #define IMAGE_HEIGHT 32
>> -#define IMAGE_SIZE (IMAGE_WIDTH*IMAGE_HEIGHT*4)
>> +#define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT * 4)
>>
>> -static void init_layer_data(GLubyte *layer_data, int num_layers)
>> +static void
>> +init_layer_data(GLubyte *layer_data, int num_layers)
>>  {
>>         int x, y, z, i, j;
>>
>>         for (z = 0; z < num_layers; z++) {
>> -               GLubyte *data = layer_data + IMAGE_SIZE*z;
>> +               GLubyte *data = layer_data + IMAGE_SIZE * z;
>>
>>                 for (x = 0; x < IMAGE_WIDTH; x += 4) {
>>                         for (y = 0; y < IMAGE_HEIGHT; y += 4) {
>> -                               int r = (x+1) * 255 / (IMAGE_WIDTH - 1);
>> -                               int g = (y+1) * 255 / (IMAGE_HEIGHT - 1);
>> -                               int b = (z+1) * 255 / (num_layers-1);
>> +                               int r = (x + 1) * 255 / (IMAGE_WIDTH - 1);
>> +                               int g = (y + 1) * 255 / (IMAGE_HEIGHT -
>> 1);
>> +                               int b = (z + 1) * 255 / (num_layers - 1);
>>                                 int a = x ^ y ^ z;
>>
>>                                 /* each 4x4 block constains only one
>> color (for S3TC) */
>>                                 for (i = 0; i < 4; i++) {
>>                                         for (j = 0; j < 4; j++) {
>> -                                               data[((y+j)*IMAGE_WIDTH +
>> x+i)*4 + 0] = r;
>> -                                               data[((y+j)*IMAGE_WIDTH +
>> x+i)*4 + 1] = g;
>> -                                               data[((y+j)*IMAGE_WIDTH +
>> x+i)*4 + 2] = b;
>> -                                               data[((y+j)*IMAGE_WIDTH +
>> x+i)*4 + 3] = a;
>> +                                               data[((y + j) *
>> IMAGE_WIDTH + x
>> +                                                     + i) * 4 + 0] = r;
>> +                                               data[((y + j) *
>> IMAGE_WIDTH + x
>> +                                                     + i) * 4 + 1] = g;
>> +                                               data[((y + j) *
>> IMAGE_WIDTH + x
>> +                                                     + i) * 4 + 2] = b;
>> +                                               data[((y + j) *
>> IMAGE_WIDTH + x
>> +                                                     + i) * 4 + 3] = a;
>>                                         }
>>                                 }
>>                         }
>> @@ -71,7 +76,8 @@ static void init_layer_data(GLubyte *layer_data, int
>> num_layers)
>>         }
>>  }
>>
>> -static void compare_layer(int layer, int num_elements, int tolerance,
>> +static bool
>> +compare_layer(int layer, int num_elements, int tolerance,
>>                           GLubyte *data, GLubyte *expected)
>>  {
>>         int i;
>> @@ -84,17 +90,115 @@ static void compare_layer(int layer, int
>> num_elements, int tolerance,
>>                                (i / 4) / IMAGE_WIDTH, (i / 4) %
>> IMAGE_HEIGHT, i % 4);
>>                         printf("    expected: %i\n", expected[i]);
>>                         printf("    got: %i\n", data[i]);
>> -                       piglit_report_result(PIGLIT_FAIL);
>> +                       return false;
>>                 }
>>         }
>> +       return true;
>>  }
>>
>> -void piglit_init(int argc, char **argv)
>> +static bool
>> +getTexImage(GLenum target, GLubyte data[][IMAGE_SIZE],
>> +           GLenum internalformat, int tolerance)
>>  {
>> -       int i, tolerance = 0, num_layers;
>> +       int i, j;
>> +       int num_layers=1, num_faces=1, layer_size;
>> +       GLubyte data2[18][IMAGE_SIZE];
>> +       bool pass = true;
>> +
>> +
>> +       memset(data2, 123, sizeof(data2));
>>
> This can be moved to just before the loops below.
>
>> +
>> +       switch (target) {
>> +       case GL_TEXTURE_1D:
>> +               glTexImage1D(GL_TEXTURE_1D, 0, internalformat,
>> IMAGE_WIDTH, 0,
>> +                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> +               layer_size = IMAGE_WIDTH * 4;
>> +               break;
>> +
>> +       case GL_TEXTURE_2D:
>> +       case GL_TEXTURE_RECTANGLE:
>> +               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH,
>> +                            IMAGE_HEIGHT, 0,
>> +                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> +               layer_size = IMAGE_SIZE;
>> +               break;
>> +
>> +       case GL_TEXTURE_3D:
>> +               num_layers = 16;
>> +               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,
>> +                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> GL_RGBA,
>> +                            GL_UNSIGNED_BYTE, data);
>> +               layer_size = IMAGE_SIZE;
>> +               break;
>> +
>> +       case GL_TEXTURE_CUBE_MAP:
>> +               num_faces = 6;
>> +               for (i = 0; i < num_faces; i++) {
>> +                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
>> 0,
>> +                                    internalformat, IMAGE_WIDTH,
>> IMAGE_HEIGHT,
>> +                                    0, GL_RGBA,
>> +                                    GL_UNSIGNED_BYTE, data[i]);
>> +               }
>> +               target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
>> +               layer_size = IMAGE_SIZE;
>> +               break;
>> +
>> +       case GL_TEXTURE_1D_ARRAY:
>> +               num_layers = 7;
>> +               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat,
>> +                            IMAGE_WIDTH, num_layers, 0,
>> +                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> +               // test as a single layer 2D image
>> +               layer_size = IMAGE_WIDTH * 4 * num_layers;
>> +               num_layers = 1;
>> +               break;
>> +
>> +       case GL_TEXTURE_2D_ARRAY:
>> +               num_layers = 7;
>> +               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,
>> +                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> +                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> +               layer_size = IMAGE_SIZE;
>> +               break;
>> +
>> +       case GL_TEXTURE_CUBE_MAP_ARRAY:
>> +               num_layers = 6 * 3;
>> +               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,
>> +                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> GL_RGBA,
>> +                            GL_UNSIGNED_BYTE, data);
>> +               layer_size = IMAGE_SIZE;
>> +               break;
>> +
>> +       default:
>> +               puts("Invalid texture target.");
>> +               return false;
>> +
>> +       }
>>
> memset(data2, ...) here.  Add
>
>   assert(num_layers * num_faces * layer_size <= sizeof(data2))
>
> in case some future changes require a larger data2.
>
> In the second patch, you can allocate the buffer here instead of in the
> outer loop.
>
> +       for (i = 0; i < num_faces; i++) {
>> +               GLubyte *dataGet=NULL;
>> +               glGetTexImage(target + i, 0, GL_RGBA, GL_UNSIGNED_BYTE,
>> data2[i]);
>> +               dataGet = data2[i];
>> +               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
>> +
>> +               for (j = 0; j < num_layers; j++) {
>> +                       pass = compare_layer(j + i, layer_size,
>> tolerance, dataGet,
>> +                                            data[j + i]) && pass;
>> +                       dataGet += layer_size;
>> +               }
>> +       }
>>
> I think it is better to covert the loops to
>
>   for (i = 0; i < num_faces; i++) {
>     glGetTexImage(...);
>   }
>   for (i = 0; i < num_layers; i++) {
>     compare_layer(...);
>   }
>
> since data2 is large enough.  That is, num_faces tells you how many
> glGetTexImage() calls are needed, and num_layers tells you how many
> compare_layer() calls are needed.  You will need to set num_layers to 6
> when target is GL_TEXTURE_CUBE_MAP.
>
> When PBO path is added, you can make the size of the buffer be (num_layers
> * num_faces * layer_size), and map it once after all the glGetTexImage()
> calls are made.  Since the PBO buffer is one-dimensional, it seems better
> to make data2 one-dimensional too.
>
You won't need the num_faces term if you make the suggested change to the
nested loops.  Sorry.

>
>
> +
>> +       return pass;
>> +}
>> +
>> +void
>> +piglit_init(int argc, char **argv)
>> +{
>> +       int i;
>>         GLenum target = GL_TEXTURE_2D;
>> +       bool pass = true;
>>         GLenum internalformat = GL_RGBA8;
>> -       GLubyte data[18][IMAGE_SIZE], data2[18][IMAGE_SIZE];
>> +       GLubyte data[18][IMAGE_SIZE];
>> +       int tolerance = 0;
>>
>>         for (i = 1; i < argc; i++) {
>>                 if (strcmp(argv[i], "1D") == 0) {
>> @@ -133,89 +237,14 @@ void piglit_init(int argc, char **argv)
>>         }
>>
>>         init_layer_data(data[0], 18);
>> -       memset(data2, 123, sizeof(data2));
>>
>>         printf("Testing %s\n", piglit_get_gl_enum_name(target));
>> -
>> -       switch (target) {
>> -       case GL_TEXTURE_1D:
>> -               glTexImage1D(GL_TEXTURE_1D, 0, internalformat,
>> IMAGE_WIDTH, 0,
>> -                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA,
>> GL_UNSIGNED_BYTE, data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               compare_layer(0, 128, tolerance, data2[0], data[0]);
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_2D:
>> -       case GL_TEXTURE_RECTANGLE:
>> -               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH,
>> IMAGE_HEIGHT, 0,
>> -                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE,
>> data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               compare_layer(0, IMAGE_SIZE, tolerance, data2[0],
>> data[0]);
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_3D:
>> -               num_layers = 16;
>> -               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,
>> -                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> GL_RGBA,
>> -                            GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(GL_TEXTURE_3D, 0,
>> -                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               for (i = 0; i < num_layers; i++) {
>> -                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i],
>> data[i]);
>> -               }
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_CUBE_MAP:
>> -               for (i = 0; i < 6; i++) {
>> -                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
>> 0,
>> -                                    internalformat, IMAGE_WIDTH,
>> IMAGE_HEIGHT, 0, GL_RGBA,
>> -                                    GL_UNSIGNED_BYTE, data[i]);
>> -               }
>> -               for (i = 0; i < 6; i++) {
>> -                       glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
>> 0,
>> -                                     GL_RGBA, GL_UNSIGNED_BYTE,
>> data2[i]);
>> -                       piglit_check_gl_error(GL_NO_ERROR);
>> -                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i],
>> data[i]);
>> -               }
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_1D_ARRAY:
>> -               num_layers = 7;
>> -               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat,
>> IMAGE_WIDTH, num_layers, 0,
>> -                            GL_RGBA, GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA,
>> GL_UNSIGNED_BYTE, data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               compare_layer(0, IMAGE_WIDTH*4*num_layers, tolerance,
>> data2[0], data[0]);
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_2D_ARRAY:
>> -               num_layers = 7;
>> -               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,
>> -                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> GL_RGBA, GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(GL_TEXTURE_2D_ARRAY, 0,
>> -                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               for (i = 0; i < num_layers; i++) {
>> -                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i],
>> data[i]);
>> -               }
>> -               piglit_report_result(PIGLIT_PASS);
>> -
>> -       case GL_TEXTURE_CUBE_MAP_ARRAY:
>> -               num_layers = 6*3;
>> -               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,
>> -                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,
>> GL_RGBA, GL_UNSIGNED_BYTE, data);
>> -               glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
>> -                             GL_RGBA, GL_UNSIGNED_BYTE, data2);
>> -               piglit_check_gl_error(GL_NO_ERROR);
>> -               for (i = 0; i < num_layers; i++) {
>> -                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i],
>> data[i]);
>> -               }
>> -               piglit_report_result(PIGLIT_PASS);
>> -       }
>> -
>> -       puts("Invalid texture target.");
>> -       piglit_report_result(PIGLIT_FAIL);
>> +       pass = getTexImage(target, data, internalformat, tolerance) &&
>> +                               pass;
>> +
>> +       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
>> +       if (pass)
>> +               piglit_report_result(PIGLIT_PASS);
>> +       else
>> +               piglit_report_result(PIGLIT_FAIL);
>>  }
>> --
>> 1.8.1.2
>>
>>
>
>
> --
> olv at LunarG.com
>



-- 
olv at LunarG.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140322/d3eaedec/attachment-0001.html>


More information about the Piglit mailing list