intel: Always gather stencil buffer in intel_map_renderbuffer_separate_s8z24()
authorChad Versace <chad.versace@linux.intel.com>
Thu, 17 Nov 2011 00:02:39 +0000 (16:02 -0800)
committerChad Versace <chad.versace@linux.intel.com>
Tue, 22 Nov 2011 00:58:29 +0000 (16:58 -0800)
The function gathered the stencil buffer into the depth buffer only when
the map mode contained the read bit. But we must do the gather even if the
map mode is write-only. If we do not, then, when the depth buffer's stencil
bits are scattered into the stencil buffer by intel_unmap_renderbuffer(),
some of the scattered stencil bits would be invalid.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
src/mesa/drivers/dri/intel/intel_fbo.c

index a724f1d97b3e85b99bb3b617eb9cdf063ac1e0d3..1bd16f06a38df3dbb912f5a54f65e291487cbe08 100644 (file)
@@ -321,11 +321,12 @@ intel_map_renderbuffer_separate_s8z24(struct gl_context *ctx,
    struct intel_context *intel = intel_context(ctx);
    struct intel_renderbuffer *irb = intel_renderbuffer(rb);
 
-   GLbitfield adjusted_mode;
-
    uint8_t *s8z24_map;
    int32_t s8z24_stride;
 
+   struct intel_renderbuffer *s8_irb;
+   uint8_t *s8_map;
+
    assert(rb->Name != 0);
    assert(rb->Format == MESA_FORMAT_S8_Z24);
    assert(irb->wrapped_depth != NULL);
@@ -337,42 +338,29 @@ intel_map_renderbuffer_separate_s8z24(struct gl_context *ctx,
    irb->map_w = w;
    irb->map_h = h;
 
-   if (mode & GL_MAP_READ_BIT) {
-      /* Since the caller may read the stencil bits, we must copy the stencil
-       * buffer's contents into the depth buffer. This necessitates that the
-       * depth buffer be mapped in write mode.
-       */
-      adjusted_mode = mode | GL_MAP_WRITE_BIT;
-   } else {
-      adjusted_mode = mode;
-   }
-
+   /* Map with write mode for the gather below. */
    intel_map_renderbuffer_gtt(ctx, irb->wrapped_depth,
-                              x, y, w, h, adjusted_mode,
+                              x, y, w, h, mode | GL_MAP_WRITE_BIT,
                               &s8z24_map, &s8z24_stride);
 
-   if (mode & GL_MAP_READ_BIT) {
-      struct intel_renderbuffer *s8_irb;
-      uint8_t *s8_map;
-
-      s8_irb = intel_renderbuffer(irb->wrapped_stencil);
-      s8_map = intel_region_map(intel, s8_irb->region, GL_MAP_READ_BIT);
-
-      for (uint32_t pix_y = 0; pix_y < h; ++pix_y) {
-        for (uint32_t pix_x = 0; pix_x < w; ++pix_x) {
-           ptrdiff_t s8_offset = intel_offset_S8(s8_irb->region->pitch,
-                                                 x + pix_x,
-                                                 y + pix_y);
-           ptrdiff_t s8z24_offset = pix_y * s8z24_stride
-                                  + pix_x * 4
-                                  + 3;
-           s8z24_map[s8z24_offset] = s8_map[s8_offset];
-        }
+   s8_irb = intel_renderbuffer(irb->wrapped_stencil);
+   s8_map = intel_region_map(intel, s8_irb->region, GL_MAP_READ_BIT);
+
+   /* Gather the stencil buffer into the depth buffer. */
+   for (uint32_t pix_y = 0; pix_y < h; ++pix_y) {
+      for (uint32_t pix_x = 0; pix_x < w; ++pix_x) {
+        ptrdiff_t s8_offset = intel_offset_S8(s8_irb->region->pitch,
+                                              x + pix_x,
+                                              y + pix_y);
+        ptrdiff_t s8z24_offset = pix_y * s8z24_stride
+                               + pix_x * 4
+                               + 3;
+        s8z24_map[s8z24_offset] = s8_map[s8_offset];
       }
-
-      intel_region_unmap(intel, s8_irb->region);
    }
 
+   intel_region_unmap(intel, s8_irb->region);
+
    *out_map = s8z24_map;
    *out_stride = s8z24_stride;
 }