common: Fix PBOs for 1D_ARRAY.
authorLaura Ekstrand <laura@jlekstrand.net>
Thu, 19 Feb 2015 01:17:38 +0000 (17:17 -0800)
committerLaura Ekstrand <laura@jlekstrand.net>
Wed, 25 Feb 2015 01:33:44 +0000 (17:33 -0800)
Corrects the way that _mesa_meta_pbo_TexSubImage and
_mesa_meta_pbo_GetTexSubImage handle 1D_ARRAY textures.  Fixes a failure in
the Piglit arb_direct_state_access/gettextureimage-targets test.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
Tested-by: Laura Ekstrand <laura@jlekstrand.net>
Cc: "10.4, 10.5" <mesa-stable@lists.freedesktop.org>
src/mesa/drivers/common/meta_tex_subimage.c

index b659426243dba4e2ed4935a7442188bfef197b5f..ffbbacd8fd892ffcf99f1991838cd58373bdb4c8 100644 (file)
@@ -137,7 +137,7 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
    struct gl_texture_image *pbo_tex_image;
    GLenum status;
    bool success = false;
-   int z;
+   int z, iters;
 
    /* XXX: This should probably be passed in from somewhere */
    const char *where = "_mesa_meta_pbo_TexSubImage";
@@ -190,12 +190,6 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
    _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, fbos[0]);
    _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[1]);
 
-   if (tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
-      assert(depth == 1);
-      depth = height;
-      height = 1;
-   }
-
    _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                              pbo_tex_image, 0);
    /* If this passes on the first layer it should pass on the others */
@@ -219,7 +213,10 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
                                   GL_COLOR_BUFFER_BIT, GL_NEAREST))
       goto fail;
 
-   for (z = 1; z < depth; z++) {
+   iters = tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY ?
+           height : depth;
+
+   for (z = 1; z < iters; z++) {
       _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                 pbo_tex_image, z);
       _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
@@ -227,11 +224,18 @@ _mesa_meta_pbo_TexSubImage(struct gl_context *ctx, GLuint dims,
 
       _mesa_update_state(ctx);
 
-      _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
-                                 0, z * height, width, (z + 1) * height,
-                                 xoffset, yoffset,
-                                 xoffset + width, yoffset + height,
-                                 GL_COLOR_BUFFER_BIT, GL_NEAREST);
+      if (tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY)
+         _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
+                                    0, z, width, z + 1,
+                                    xoffset, yoffset,
+                                    xoffset + width, yoffset + 1,
+                                    GL_COLOR_BUFFER_BIT, GL_NEAREST);
+      else
+         _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
+                                    0, z * height, width, (z + 1) * height,
+                                    xoffset, yoffset,
+                                    xoffset + width, yoffset + height,
+                                    GL_COLOR_BUFFER_BIT, GL_NEAREST);
    }
 
    success = true;
@@ -258,7 +262,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
    struct gl_texture_image *pbo_tex_image;
    GLenum status;
    bool success = false;
-   int z;
+   int z, iters;
 
    /* XXX: This should probably be passed in from somewhere */
    const char *where = "_mesa_meta_pbo_GetTexSubImage";
@@ -305,12 +309,6 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
 
    _mesa_GenFramebuffers(2, fbos);
 
-   if (tex_image && tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
-      assert(depth == 1);
-      depth = height;
-      height = 1;
-   }
-
    /* If we were given a texture, bind it to the read framebuffer.  If not,
     * we're doing a ReadPixels and we should just use whatever framebuffer
     * the client has bound.
@@ -344,7 +342,12 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
                                   GL_COLOR_BUFFER_BIT, GL_NEAREST))
       goto fail;
 
-   for (z = 1; z < depth; z++) {
+   if (tex_image && tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY)
+      iters = height;
+   else
+      iters = depth;
+
+   for (z = 1; z < iters; z++) {
       _mesa_meta_bind_fbo_image(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                 tex_image, zoffset + z);
       _mesa_meta_bind_fbo_image(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
@@ -352,11 +355,18 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
 
       _mesa_update_state(ctx);
 
-      _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
-                                 xoffset, yoffset,
-                                 xoffset + width, yoffset + height,
-                                 0, z * height, width, (z + 1) * height,
-                                 GL_COLOR_BUFFER_BIT, GL_NEAREST);
+      if (tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY)
+         _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
+                                    xoffset, yoffset,
+                                    xoffset + width, yoffset + 1,
+                                    0, z, width, z + 1,
+                                    GL_COLOR_BUFFER_BIT, GL_NEAREST);
+      else
+         _mesa_meta_BlitFramebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer,
+                                    xoffset, yoffset,
+                                    xoffset + width, yoffset + height,
+                                    0, z * height, width, (z + 1) * height,
+                                    GL_COLOR_BUFFER_BIT, GL_NEAREST);
    }
 
    success = true;