i965: Add and use a getter for the miptree aux buffer
authorNanley Chery <nanley.g.chery@intel.com>
Mon, 9 Apr 2018 18:11:46 +0000 (11:11 -0700)
committerNanley Chery <nanley.g.chery@intel.com>
Tue, 24 Apr 2018 20:41:14 +0000 (13:41 -0700)
Make the next patch easier to read by eliminating most of the would-be
duplicate field accesses now.

v2: Update the HiZ comment instead of deleting it (Rafael).

Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
src/mesa/drivers/dri/i965/brw_blorp.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.h

index 5dcd95e9f448c51613d7ca2db36a661e2c125ec1..962a316c5cfaf712417fcdaa30e9e4ae21ace865 100644 (file)
@@ -154,12 +154,6 @@ blorp_surf_for_miptree(struct brw_context *brw,
       .aux_usage = aux_usage,
    };
 
-   struct intel_miptree_aux_buffer *aux_buf = NULL;
-   if (mt->mcs_buf)
-      aux_buf = mt->mcs_buf;
-   else if (mt->hiz_buf)
-      aux_buf = mt->hiz_buf;
-
    if (mt->format == MESA_FORMAT_S_UINT8 && is_render_target &&
        devinfo->gen <= 7)
       mt->r8stencil_needs_update = true;
@@ -174,6 +168,8 @@ blorp_surf_for_miptree(struct brw_context *brw,
        */
       surf->clear_color = mt->fast_clear_color;
 
+      struct intel_miptree_aux_buffer *aux_buf =
+         intel_miptree_get_aux_buffer(mt);
       surf->aux_surf = &aux_buf->surf;
       surf->aux_addr = (struct blorp_address) {
          .reloc_flags = is_render_target ? EXEC_OBJECT_WRITE : 0,
index 3fb101bf68bb7297a560d0de92f85d0c5b288ca8..06f739faf61fb6e40aa92588a2c03b4bfe1f085d 100644 (file)
@@ -155,21 +155,7 @@ brw_emit_surface_state(struct brw_context *brw,
    struct brw_bo *aux_bo = NULL;
    struct isl_surf *aux_surf = NULL;
    uint64_t aux_offset = 0;
-   struct intel_miptree_aux_buffer *aux_buf = NULL;
-   switch (aux_usage) {
-   case ISL_AUX_USAGE_MCS:
-   case ISL_AUX_USAGE_CCS_D:
-   case ISL_AUX_USAGE_CCS_E:
-      aux_buf = mt->mcs_buf;
-      break;
-
-   case ISL_AUX_USAGE_HIZ:
-      aux_buf = mt->hiz_buf;
-      break;
-
-   case ISL_AUX_USAGE_NONE:
-      break;
-   }
+   struct intel_miptree_aux_buffer *aux_buf = intel_miptree_get_aux_buffer(mt);
 
    if (aux_usage != ISL_AUX_USAGE_NONE) {
       aux_surf = &aux_buf->surf;
index d95128de119ab1a798248e6c07735a6d8ff4b61e..3cb6f70a6ced0d3302ced01f76c33afccd8bd1f0 100644 (file)
@@ -1249,8 +1249,7 @@ intel_miptree_release(struct intel_mipmap_tree **mt)
       brw_bo_unreference((*mt)->bo);
       intel_miptree_release(&(*mt)->stencil_mt);
       intel_miptree_release(&(*mt)->r8stencil_mt);
-      intel_miptree_aux_buffer_free((*mt)->hiz_buf);
-      intel_miptree_aux_buffer_free((*mt)->mcs_buf);
+      intel_miptree_aux_buffer_free(intel_miptree_get_aux_buffer(*mt));
       free_aux_state_map((*mt)->aux_state);
 
       intel_miptree_release(&(*mt)->plane[0]);
@@ -2876,31 +2875,17 @@ intel_miptree_make_shareable(struct brw_context *brw,
                                 0, INTEL_REMAINING_LAYERS,
                                 ISL_AUX_USAGE_NONE, false);
 
-   if (mt->mcs_buf) {
-      intel_miptree_aux_buffer_free(mt->mcs_buf);
+   struct intel_miptree_aux_buffer *aux_buf = intel_miptree_get_aux_buffer(mt);
+   if (aux_buf) {
+      intel_miptree_aux_buffer_free(aux_buf);
       mt->mcs_buf = NULL;
-
-      /* Any pending MCS/CCS operations are no longer needed. Trying to
-       * execute any will likely crash due to the missing aux buffer. So let's
-       * delete all pending ops.
-       */
-      free(mt->aux_state);
-      mt->aux_state = NULL;
-      brw->ctx.NewDriverState |= BRW_NEW_AUX_STATE;
-   }
-
-   if (mt->hiz_buf) {
-      intel_miptree_aux_buffer_free(mt->hiz_buf);
       mt->hiz_buf = NULL;
 
+      /* Make future calls of intel_miptree_level_has_hiz() return false. */
       for (uint32_t l = mt->first_level; l <= mt->last_level; ++l) {
          mt->level[l].has_hiz = false;
       }
 
-      /* Any pending HiZ operations are no longer needed. Trying to execute
-       * any will likely crash due to the missing aux buffer. So let's delete
-       * all pending ops.
-       */
       free(mt->aux_state);
       mt->aux_state = NULL;
       brw->ctx.NewDriverState |= BRW_NEW_AUX_STATE;
index 2f754427fc5de0d00ce91b80bab25419bec474b4..8fe5c4add671f8741ee2e2e8efa146a5733f9503 100644 (file)
@@ -485,6 +485,23 @@ enum isl_dim_layout
 get_isl_dim_layout(const struct gen_device_info *devinfo,
                    enum isl_tiling tiling, GLenum target);
 
+static inline struct intel_miptree_aux_buffer *
+intel_miptree_get_aux_buffer(const struct intel_mipmap_tree *mt)
+{
+   switch (mt->aux_usage) {
+   case ISL_AUX_USAGE_MCS:
+   case ISL_AUX_USAGE_CCS_D:
+   case ISL_AUX_USAGE_CCS_E:
+      return mt->mcs_buf;
+   case ISL_AUX_USAGE_HIZ:
+      return mt->hiz_buf;
+   case ISL_AUX_USAGE_NONE:
+      return NULL;
+   default:
+      unreachable("Invalid aux_usage!\n");
+   }
+}
+
 void
 intel_get_image_dims(struct gl_texture_image *image,
                      int *width, int *height, int *depth);