<div dir="ltr">On Sat, Mar 22, 2014 at 3:26 PM, Chia-I Wu <span dir="ltr"><<a href="mailto:olvaffe@gmail.com" target="_blank">olvaffe@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5">On Sat, Mar 22, 2014 at 5:03 AM, Jon Ashburn <span dir="ltr"><<a href="mailto:jon@lunarg.com" target="_blank">jon@lunarg.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
 tests/texturing/getteximage-targets.c | 225 +++++++++++++++++++---------------<br>
 1 file changed, 127 insertions(+), 98 deletions(-)<br>
<br>
diff --git a/tests/texturing/getteximage-targets.c b/tests/texturing/getteximage-targets.c<br>
index 383ee03..1b626db 100644<br>
--- a/tests/texturing/getteximage-targets.c<br>
+++ b/tests/texturing/getteximage-targets.c<br>
@@ -41,29 +41,34 @@ piglit_display(void)<br>
<br>
 #define IMAGE_WIDTH 32<br>
 #define IMAGE_HEIGHT 32<br>
-#define IMAGE_SIZE (IMAGE_WIDTH*IMAGE_HEIGHT*4)<br>
+#define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT * 4)<br>
<br>
-static void init_layer_data(GLubyte *layer_data, int num_layers)<br>
+static void<br>
+init_layer_data(GLubyte *layer_data, int num_layers)<br>
 {<br>
        int x, y, z, i, j;<br>
<br>
        for (z = 0; z < num_layers; z++) {<br>
-               GLubyte *data = layer_data + IMAGE_SIZE*z;<br>
+               GLubyte *data = layer_data + IMAGE_SIZE * z;<br>
<br>
                for (x = 0; x < IMAGE_WIDTH; x += 4) {<br>
                        for (y = 0; y < IMAGE_HEIGHT; y += 4) {<br>
-                               int r = (x+1) * 255 / (IMAGE_WIDTH - 1);<br>
-                               int g = (y+1) * 255 / (IMAGE_HEIGHT - 1);<br>
-                               int b = (z+1) * 255 / (num_layers-1);<br>
+                               int r = (x + 1) * 255 / (IMAGE_WIDTH - 1);<br>
+                               int g = (y + 1) * 255 / (IMAGE_HEIGHT - 1);<br>
+                               int b = (z + 1) * 255 / (num_layers - 1);<br>
                                int a = x ^ y ^ z;<br>
<br>
                                /* each 4x4 block constains only one color (for S3TC) */<br>
                                for (i = 0; i < 4; i++) {<br>
                                        for (j = 0; j < 4; j++) {<br>
-                                               data[((y+j)*IMAGE_WIDTH + x+i)*4 + 0] = r;<br>
-                                               data[((y+j)*IMAGE_WIDTH + x+i)*4 + 1] = g;<br>
-                                               data[((y+j)*IMAGE_WIDTH + x+i)*4 + 2] = b;<br>
-                                               data[((y+j)*IMAGE_WIDTH + x+i)*4 + 3] = a;<br>
+                                               data[((y + j) * IMAGE_WIDTH + x<br>
+                                                     + i) * 4 + 0] = r;<br>
+                                               data[((y + j) * IMAGE_WIDTH + x<br>
+                                                     + i) * 4 + 1] = g;<br>
+                                               data[((y + j) * IMAGE_WIDTH + x<br>
+                                                     + i) * 4 + 2] = b;<br>
+                                               data[((y + j) * IMAGE_WIDTH + x<br>
+                                                     + i) * 4 + 3] = a;<br>
                                        }<br>
                                }<br>
                        }<br>
@@ -71,7 +76,8 @@ static void init_layer_data(GLubyte *layer_data, int num_layers)<br>
        }<br>
 }<br>
<br>
-static void compare_layer(int layer, int num_elements, int tolerance,<br>
+static bool<br>
+compare_layer(int layer, int num_elements, int tolerance,<br>
                          GLubyte *data, GLubyte *expected)<br>
 {<br>
        int i;<br>
@@ -84,17 +90,115 @@ static void compare_layer(int layer, int num_elements, int tolerance,<br>
                               (i / 4) / IMAGE_WIDTH, (i / 4) % IMAGE_HEIGHT, i % 4);<br>
                        printf("    expected: %i\n", expected[i]);<br>
                        printf("    got: %i\n", data[i]);<br>
-                       piglit_report_result(PIGLIT_FAIL);<br>
+                       return false;<br>
                }<br>
        }<br>
+       return true;<br>
 }<br>
<br>
-void piglit_init(int argc, char **argv)<br>
+static bool<br>
+getTexImage(GLenum target, GLubyte data[][IMAGE_SIZE],<br>
+           GLenum internalformat, int tolerance)<br>
 {<br>
-       int i, tolerance = 0, num_layers;<br>
+       int i, j;<br>
+       int num_layers=1, num_faces=1, layer_size;<br>
+       GLubyte data2[18][IMAGE_SIZE];<br>
+       bool pass = true;<br>
+<br>
+<br>
+       memset(data2, 123, sizeof(data2));<br></blockquote></div></div><div>This can be moved to just before the loops below. <br></div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


+<br>
+       switch (target) {<br>
+       case GL_TEXTURE_1D:<br>
+               glTexImage1D(GL_TEXTURE_1D, 0, internalformat, IMAGE_WIDTH, 0,<br>
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
+               layer_size = IMAGE_WIDTH * 4;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_2D:<br>
+       case GL_TEXTURE_RECTANGLE:<br>
+               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH,<br>
+                            IMAGE_HEIGHT, 0,<br>
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
+               layer_size = IMAGE_SIZE;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_3D:<br>
+               num_layers = 16;<br>
+               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,<br>
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,<br>
+                            GL_UNSIGNED_BYTE, data);<br>
+               layer_size = IMAGE_SIZE;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_CUBE_MAP:<br>
+               num_faces = 6;<br>
+               for (i = 0; i < num_faces; i++) {<br>
+                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,<br>
+                                    internalformat, IMAGE_WIDTH, IMAGE_HEIGHT,<br>
+                                    0, GL_RGBA,<br>
+                                    GL_UNSIGNED_BYTE, data[i]);<br>
+               }<br>
+               target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;<br>
+               layer_size = IMAGE_SIZE;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_1D_ARRAY:<br>
+               num_layers = 7;<br>
+               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat,<br>
+                            IMAGE_WIDTH, num_layers, 0,<br>
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
+               // test as a single layer 2D image<br>
+               layer_size = IMAGE_WIDTH * 4 * num_layers;<br>
+               num_layers = 1;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_2D_ARRAY:<br>
+               num_layers = 7;<br>
+               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,<br>
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0,<br>
+                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
+               layer_size = IMAGE_SIZE;<br>
+               break;<br>
+<br>
+       case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
+               num_layers = 6 * 3;<br>
+               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,<br>
+                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,<br>
+                            GL_UNSIGNED_BYTE, data);<br>
+               layer_size = IMAGE_SIZE;<br>
+               break;<br>
+<br>
+       default:<br>
+               puts("Invalid texture target.");<br>
+               return false;<br>
+<br>
+       }<br></blockquote></div></div><div>memset(data2, ...) here.  Add<br><br></div>  assert(num_layers * num_faces * layer_size <= sizeof(data2))<br><div> <br></div><div>in case some future changes require a larger data2.<br>
</div>
<div><br></div><div>In the second patch, you can allocate the buffer here instead of in the outer loop.<br><br></div><div class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


+       for (i = 0; i < num_faces; i++) {<br>
+               GLubyte *dataGet=NULL;<br>
+               glGetTexImage(target + i, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2[i]);<br>
+               dataGet = data2[i];<br>
+               pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
+<br>
+               for (j = 0; j < num_layers; j++) {<br>
+                       pass = compare_layer(j + i, layer_size, tolerance, dataGet,<br>
+                                            data[j + i]) && pass;<br>
+                       dataGet += layer_size;<br>
+               }<br>
+       }<br></blockquote></div>I think it is better to covert the loops to<br><br></div><div class=""><div class="gmail_quote">  for (i = 0; i < num_faces; i++) {<br></div></div><div class="gmail_quote">    glGetTexImage(...);<br>
  }<br></div><div class="">
<div class="gmail_quote">  for (i = 0; i < num_layers; i++) {<br></div></div><div class="gmail_quote">    compare_layer(...);<br></div><div class="gmail_quote">  }    <br></div><div class="gmail_quote"><br></div><div class="gmail_quote">

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.</div>

<div class="gmail_quote"><br></div><div class="gmail_quote">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.<br>
</div></div></div></blockquote><div>You won't need the num_faces term if you make the suggested change to the nested loops.  Sorry.<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<br><br></div><div><div class="h5"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
+       return pass;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+       int i;<br>
        GLenum target = GL_TEXTURE_2D;<br>
+       bool pass = true;<br>
        GLenum internalformat = GL_RGBA8;<br>
-       GLubyte data[18][IMAGE_SIZE], data2[18][IMAGE_SIZE];<br>
+       GLubyte data[18][IMAGE_SIZE];<br>
+       int tolerance = 0;<br>
<br>
        for (i = 1; i < argc; i++) {<br>
                if (strcmp(argv[i], "1D") == 0) {<br>
@@ -133,89 +237,14 @@ void piglit_init(int argc, char **argv)<br>
        }<br>
<br>
        init_layer_data(data[0], 18);<br>
-       memset(data2, 123, sizeof(data2));<br>
<br>
        printf("Testing %s\n", piglit_get_gl_enum_name(target));<br>
-<br>
-       switch (target) {<br>
-       case GL_TEXTURE_1D:<br>
-               glTexImage1D(GL_TEXTURE_1D, 0, internalformat, IMAGE_WIDTH, 0,<br>
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               compare_layer(0, 128, tolerance, data2[0], data[0]);<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_2D:<br>
-       case GL_TEXTURE_RECTANGLE:<br>
-               glTexImage2D(target, 0, internalformat, IMAGE_WIDTH, IMAGE_HEIGHT, 0,<br>
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               compare_layer(0, IMAGE_SIZE, tolerance, data2[0], data[0]);<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_3D:<br>
-               num_layers = 16;<br>
-               glTexImage3D(GL_TEXTURE_3D, 0, internalformat,<br>
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA,<br>
-                            GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(GL_TEXTURE_3D, 0,<br>
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               for (i = 0; i < num_layers; i++) {<br>
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], data[i]);<br>
-               }<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_CUBE_MAP:<br>
-               for (i = 0; i < 6; i++) {<br>
-                       glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,<br>
-                                    internalformat, IMAGE_WIDTH, IMAGE_HEIGHT, 0, GL_RGBA,<br>
-                                    GL_UNSIGNED_BYTE, data[i]);<br>
-               }<br>
-               for (i = 0; i < 6; i++) {<br>
-                       glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,<br>
-                                     GL_RGBA, GL_UNSIGNED_BYTE, data2[i]);<br>
-                       piglit_check_gl_error(GL_NO_ERROR);<br>
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], data[i]);<br>
-               }<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_1D_ARRAY:<br>
-               num_layers = 7;<br>
-               glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat, IMAGE_WIDTH, num_layers, 0,<br>
-                            GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               compare_layer(0, IMAGE_WIDTH*4*num_layers, tolerance, data2[0], data[0]);<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_2D_ARRAY:<br>
-               num_layers = 7;<br>
-               glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,<br>
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(GL_TEXTURE_2D_ARRAY, 0,<br>
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               for (i = 0; i < num_layers; i++) {<br>
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], data[i]);<br>
-               }<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-<br>
-       case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
-               num_layers = 6*3;<br>
-               glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,<br>
-                            IMAGE_WIDTH, IMAGE_HEIGHT, num_layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);<br>
-               glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,<br>
-                             GL_RGBA, GL_UNSIGNED_BYTE, data2);<br>
-               piglit_check_gl_error(GL_NO_ERROR);<br>
-               for (i = 0; i < num_layers; i++) {<br>
-                       compare_layer(i, IMAGE_SIZE, tolerance, data2[i], data[i]);<br>
-               }<br>
-               piglit_report_result(PIGLIT_PASS);<br>
-       }<br>
-<br>
-       puts("Invalid texture target.");<br>
-       piglit_report_result(PIGLIT_FAIL);<br>
+       pass = getTexImage(target, data, internalformat, tolerance) &&<br>
+                               pass;<br>
+<br>
+       pass = piglit_check_gl_error(GL_NO_ERROR) && pass;<br>
+       if (pass)<br>
+               piglit_report_result(PIGLIT_PASS);<br>
+       else<br>
+               piglit_report_result(PIGLIT_FAIL);<br>
 }<br>
<span><font color="#888888">--<br>
1.8.1.2<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>olv@LunarG.com
</font></span></div></div>
</blockquote></div><br><br clear="all"><br>-- <br>olv@LunarG.com
</div></div>