gallium: Fixes for clobbering stencil values in combined depth/stencil textures.
authorMichel Dänzer <daenzer@vmware.com>
Tue, 7 Jul 2009 12:49:52 +0000 (14:49 +0200)
committerMichel Dänzer <daenzer@vmware.com>
Tue, 7 Jul 2009 12:49:52 +0000 (14:49 +0200)
Also fix one case where a 32 bit depth value was incorrectly converted to a
combined depth/stencil value.

src/gallium/auxiliary/util/u_tile.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_texture.c

index 9747a55cbfa778a39cc1bd5f6300163985a015df..a0c8ed88f744c358560bf58c97ac4ded8a9703f9 100644 (file)
@@ -1202,6 +1202,19 @@ pipe_put_tile_z(struct pipe_transfer *pt,
       }
       break;
    case PIPE_FORMAT_S8Z24_UNORM:
+      {
+         uint *pDest = (uint *) (map + y * pt->stride + x*4);
+         assert(pt->usage == PIPE_TRANSFER_READ_WRITE);
+         for (i = 0; i < h; i++) {
+            for (j = 0; j < w; j++) {
+               /* convert 32-bit Z to 24-bit Z, preserve stencil */
+               pDest[j] = (pDest[j] & 0xff000000) | ptrc[j] >> 8;
+            }
+            pDest += pt->stride/4;
+            ptrc += srcStride;
+         }
+      }
+      break;
    case PIPE_FORMAT_X8Z24_UNORM:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
@@ -1216,13 +1229,26 @@ pipe_put_tile_z(struct pipe_transfer *pt,
       }
       break;
    case PIPE_FORMAT_Z24S8_UNORM:
+      {
+         uint *pDest = (uint *) (map + y * pt->stride + x*4);
+         assert(pt->usage == PIPE_TRANSFER_READ_WRITE);
+         for (i = 0; i < h; i++) {
+            for (j = 0; j < w; j++) {
+               /* convert 32-bit Z to 24-bit Z, preserve stencil */
+               pDest[j] = (pDest[j] & 0xff) | (ptrc[j] & 0xffffff00);
+            }
+            pDest += pt->stride/4;
+            ptrc += srcStride;
+         }
+      }
+      break;
    case PIPE_FORMAT_Z24X8_UNORM:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z (0 stencil) */
-               pDest[j] = ptrc[j] << 8;
+               pDest[j] = ptrc[j] & 0xffffff00;
             }
             pDest += pt->stride/4;
             ptrc += srcStride;
index 2027b713ce001800460b1fc53216a490bda2ec4a..8b5094a04f3762aeb4503328f93f8026c8d092d1 100644 (file)
@@ -1037,10 +1037,16 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy,
          st_cond_flush_get_tex_transfer(st, rbRead->texture, 0, 0, 0,
                                        PIPE_TRANSFER_READ, srcx, srcy, width,
                                        height);
+      struct pipe_transfer *ptTex;
+      enum pipe_transfer_usage transfer_usage;
 
-      struct pipe_transfer *ptTex =
-         st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, PIPE_TRANSFER_WRITE,
-                                       0, 0, width, height);
+      if (type == GL_DEPTH && pf_is_depth_and_stencil(pt->format))
+         transfer_usage = PIPE_TRANSFER_READ_WRITE;
+      else
+         transfer_usage = PIPE_TRANSFER_WRITE;
+
+      ptTex = st_cond_flush_get_tex_transfer(st, pt, 0, 0, 0, transfer_usage,
+                                             0, 0, width, height);
 
       if (type == GL_COLOR) {
          /* alternate path using get/put_tile() */
index 0a72784ce0626f4510d8632005741c75676f61b5..909189f9d3973dab0014b1e7f601f743559fdd55 100644 (file)
@@ -529,6 +529,7 @@ st_TexImage(GLcontext * ctx,
    GLint texelBytes, sizeInBytes;
    GLuint dstRowStride;
    struct gl_pixelstore_attrib unpackNB;
+   enum pipe_transfer_usage transfer_usage;
 
    DBG("%s target %s level %d %dx%dx%d border %d\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(target), level, width, height, depth, border);
@@ -680,8 +681,14 @@ st_TexImage(GLcontext * ctx,
    }
 
    if (stImage->pt) {
+      if (format == GL_DEPTH_COMPONENT &&
+          pf_is_depth_and_stencil(stImage->pt->format))
+         transfer_usage = PIPE_TRANSFER_READ_WRITE;
+      else
+         transfer_usage = PIPE_TRANSFER_WRITE;
+
       texImage->Data = st_texture_image_map(ctx->st, stImage, 0,
-                                            PIPE_TRANSFER_WRITE, 0, 0,
+                                            transfer_usage, 0, 0,
                                             stImage->base.Width,
                                             stImage->base.Height);
       if(stImage->transfer)
@@ -742,7 +749,7 @@ st_TexImage(GLcontext * ctx,
            st_texture_image_unmap(ctx->st, stImage);
             /* map next slice of 3D texture */
            texImage->Data = st_texture_image_map(ctx->st, stImage, i + 1,
-                                                  PIPE_TRANSFER_WRITE, 0, 0,
+                                                  transfer_usage, 0, 0,
                                                   stImage->base.Width,
                                                   stImage->base.Height);
            src += srcImageStride;
@@ -1041,6 +1048,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
       _mesa_image_image_stride(packing, width, height, format, type);
    GLint i;
    const GLubyte *src;
+   enum pipe_transfer_usage transfer_usage;
 
    DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
        _mesa_lookup_enum_by_nr(target),
@@ -1072,10 +1080,16 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
     * from uploading the buffer under us.
     */
    if (stImage->pt) {
+      if (format == GL_DEPTH_COMPONENT &&
+          pf_is_depth_and_stencil(stImage->pt->format))
+         transfer_usage = PIPE_TRANSFER_READ_WRITE;
+      else
+         transfer_usage = PIPE_TRANSFER_WRITE;
+
       st_teximage_flush_before_map(ctx->st, stImage->pt, 0, level,
-                                  PIPE_TRANSFER_WRITE);
+                                  transfer_usage);
       texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, 
-                                            PIPE_TRANSFER_WRITE,
+                                            transfer_usage,
                                             xoffset, yoffset,
                                             width, height);
    }
@@ -1106,7 +1120,7 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
          /* map next slice of 3D texture */
         texImage->Data = st_texture_image_map(ctx->st, stImage,
                                                zoffset + i + 1,
-                                               PIPE_TRANSFER_WRITE,
+                                               transfer_usage,
                                                xoffset, yoffset,
                                                width, height);
         src += srcImageStride;
@@ -1274,6 +1288,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
    struct pipe_screen *screen = pipe->screen;
    struct pipe_transfer *src_trans;
    GLvoid *texDest;
+   enum pipe_transfer_usage transfer_usage;
 
    assert(width <= MAX_WIDTH);
 
@@ -1288,10 +1303,16 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
                                               srcX, srcY,
                                               width, height);
 
+   if (baseFormat == GL_DEPTH_COMPONENT &&
+       pf_is_depth_and_stencil(stImage->pt->format))
+      transfer_usage = PIPE_TRANSFER_READ_WRITE;
+   else
+      transfer_usage = PIPE_TRANSFER_WRITE;
+
    st_teximage_flush_before_map(ctx->st, stImage->pt, 0, 0,
-                               PIPE_TRANSFER_WRITE);
+                               transfer_usage);
 
-   texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE,
+   texDest = st_texture_image_map(ctx->st, stImage, 0, transfer_usage,
                                   destX, destY, width, height);
 
    if (baseFormat == GL_DEPTH_COMPONENT ||