[Mesa-dev] [PATCH 12/13] i965/miptree: Create the r8stencil_mt immediately

Nanley Chery nanleychery at gmail.com
Tue Jun 12 19:22:04 UTC 2018


The current behavior masked two bugs where the flag was not set to true
 after modifying the stencil texture. One case was a regression
introduced with commit bdbb527a65fc729e7a9319ae67de60d03d06c3fd and
another was a bug in the depthstencil mapping code. These have since
been fixed.

To prevent such bugs from being masked in the future, create the
texturing miptree immediately.

Note that the r8stencil_mt is now created with
ISL_SURF_USAGE_RENDER_TARGET_BIT. This is appropriate because it is
used as blit destination during the update process.

Also note that we now properly handle the case in which make_surface
fails.
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 47 ++++++++++---------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index b078c759243..6311b2257db 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -354,6 +354,17 @@ needs_separate_stencil(const struct brw_context *brw,
           intel_miptree_supports_hiz(brw, mt);
 }
 
+static bool
+needs_r8stencil(const struct brw_context *brw,
+                mesa_format format)
+{
+   const struct gen_device_info *devinfo = &brw->screen->devinfo;
+   const GLenum base_fmt = _mesa_get_format_base_format(format);
+
+   return (base_fmt == GL_STENCIL_INDEX ||
+           base_fmt == GL_DEPTH_STENCIL) && devinfo->gen == 7;
+}
+
 /**
  * Choose the aux usage for this miptree.  This function must be called fairly
  * late in the miptree create process after we have a tiling.
@@ -672,8 +683,6 @@ make_separate_stencil_surface(struct brw_context *brw,
    if (!mt->stencil_mt)
       return false;
 
-   mt->stencil_mt->r8stencil_needs_update = true;
-
    return true;
 }
 
@@ -742,6 +751,18 @@ miptree_create(struct brw_context *brw,
       }
    }
 
+   if (needs_r8stencil(brw, format)) {
+      mt->r8stencil_mt =
+         make_surface(brw, target, MESA_FORMAT_R_UINT8, first_level, last_level,
+                      width0, height0, depth0, num_samples,
+                      ISL_TILING_Y0_BIT, mt_surf_usage(MESA_FORMAT_R_UINT8),
+                      BO_ALLOC_BUSY, 0, NULL);
+      if (mt->r8stencil_mt == NULL) {
+         intel_miptree_release(&mt);
+         return NULL;
+      }
+   }
+
    if (_mesa_is_format_color_format(format) && mt_fmt != format)
       mt->etc_format = format;
 
@@ -2934,32 +2955,14 @@ intel_update_r8stencil(struct brw_context *brw,
 {
    const struct gen_device_info *devinfo = &brw->screen->devinfo;
 
-   assert(devinfo->gen >= 7);
+   assert(devinfo->gen > 6); /* Handle MIPTREE_LAYOUT_GEN6_HIZ_STENCIL */
    struct intel_mipmap_tree *src =
       mt->format == MESA_FORMAT_S_UINT8 ? mt : mt->stencil_mt;
    if (!src || devinfo->gen >= 8 || !src->r8stencil_needs_update)
       return;
 
    assert(src->surf.size > 0);
-
-   if (!mt->r8stencil_mt) {
-      assert(devinfo->gen > 6); /* Handle MIPTREE_LAYOUT_GEN6_HIZ_STENCIL */
-      mt->r8stencil_mt = make_surface(
-                            brw,
-                            src->target,
-                            MESA_FORMAT_R_UINT8,
-                            src->first_level, src->last_level,
-                            src->surf.logical_level0_px.width,
-                            src->surf.logical_level0_px.height,
-                            src->surf.dim == ISL_SURF_DIM_3D ?
-                               src->surf.logical_level0_px.depth :
-                               src->surf.logical_level0_px.array_len,
-                            src->surf.samples,
-                            ISL_TILING_Y0_BIT,
-                            ISL_SURF_USAGE_TEXTURE_BIT,
-                            BO_ALLOC_BUSY, 0, NULL);
-      assert(mt->r8stencil_mt);
-   }
+   assert(mt->r8stencil_mt);
 
    struct intel_mipmap_tree *dst = mt->r8stencil_mt;
 
-- 
2.17.0



More information about the mesa-dev mailing list