isl: Round up some pitches to 512B for Gen12's CCS
[mesa.git] / src / intel / isl / isl_emit_depth_stencil.c
index 4869659c627ec5fa5f7745f72d6f0d414fc58d20..382c0ce22f555f6eb8f1ec75dee735513459f47c 100644 (file)
 #define __gen_address_type uint64_t
 #define __gen_user_data void
 
-static inline uint64_t
-__gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
+static uint64_t
+__gen_combine_address(__attribute__((unused)) void *data,
+                      __attribute__((unused)) void *loc, uint64_t addr,
+                      uint32_t delta)
 {
    return addr + delta;
 }
@@ -37,11 +39,7 @@ __gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
 
 #include "isl_priv.h"
 
-#define __PASTE2(x, y) x ## y
-#define __PASTE(x, y) __PASTE2(x, y)
-#define isl_genX(x) __PASTE(isl_, genX(x))
-
-static const uint32_t isl_to_gen_ds_surftype [] = {
+static const uint32_t isl_to_gen_ds_surftype[] = {
 #if GEN_GEN >= 9
    /* From the SKL PRM, "3DSTATE_DEPTH_STENCIL::SurfaceType":
     *
@@ -96,7 +94,7 @@ isl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
 #endif
       db.SurfaceBaseAddress = info->depth_address;
 #if GEN_GEN >= 6
-      db.DepthBufferMOCS = info->mocs;
+      db.MOCS = info->mocs;
 #endif
 
 #if GEN_GEN <= 6
@@ -106,13 +104,23 @@ isl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
       db.MIPMapLayoutMode = MIPLAYOUT_BELOW;
 #endif
 
-      db.SurfacePitch = info->depth_surf->row_pitch - 1;
+      db.SurfacePitch = info->depth_surf->row_pitch_B - 1;
 #if GEN_GEN >= 8
       db.SurfaceQPitch =
          isl_surf_get_array_pitch_el_rows(info->depth_surf) >> 2;
 #endif
    }
 
+#if GEN_GEN == 5 || GEN_GEN == 6
+   const bool separate_stencil =
+      info->stencil_surf && info->stencil_surf->format == ISL_FORMAT_R8_UINT;
+   if (separate_stencil || info->hiz_usage == ISL_AUX_USAGE_HIZ) {
+      assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
+      db.SeparateStencilBufferEnable = true;
+      db.HierarchicalDepthBufferEnable = true;
+   }
+#endif
+
 #if GEN_GEN >= 6
    struct GENX(3DSTATE_STENCIL_BUFFER) sb = {
       GENX(3DSTATE_STENCIL_BUFFER_header),
@@ -122,20 +130,41 @@ isl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
 #endif
 
    if (info->stencil_surf) {
-#if GEN_GEN >= 7
+#if GEN_GEN >= 7 && GEN_GEN < 12
       db.StencilWriteEnable = true;
 #endif
-#if GEN_GEN >= 8 || GEN_IS_HASWELL
+#if GEN_GEN >= 12
+      sb.StencilWriteEnable = true;
+      sb.SurfaceType = SURFTYPE_2D;
+      sb.Width = info->stencil_surf->logical_level0_px.width - 1;
+      sb.Height = info->stencil_surf->logical_level0_px.height - 1;
+      sb.Depth = sb.RenderTargetViewExtent = info->view->array_len - 1;
+      sb.SurfLOD = info->view->base_level;
+      sb.MinimumArrayElement = info->view->base_array_layer;
+#elif GEN_GEN >= 8 || GEN_IS_HASWELL
       sb.StencilBufferEnable = true;
 #endif
       sb.SurfaceBaseAddress = info->stencil_address;
 #if GEN_GEN >= 6
-      sb.StencilBufferMOCS = info->mocs;
+      sb.MOCS = info->mocs;
 #endif
-      sb.SurfacePitch = info->stencil_surf->row_pitch - 1;
+      sb.SurfacePitch = info->stencil_surf->row_pitch_B - 1;
 #if GEN_GEN >= 8
       sb.SurfaceQPitch =
          isl_surf_get_array_pitch_el_rows(info->stencil_surf) >> 2;
+#endif
+   } else {
+#if GEN_GEN >= 12
+      sb.SurfaceType = SURFTYPE_NULL;
+
+      /* The docs seem to indicate that if surf-type is null, then we may need
+       * to match the depth-buffer value for `Depth`. It may be a
+       * documentation bug, since the other fields don't require this.
+       *
+       * TODO: Confirm documentation and remove seeting of `Depth` if not
+       * required.
+       */
+      sb.Depth = db.Depth;
 #endif
    }
 
@@ -151,13 +180,10 @@ isl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
           info->hiz_usage == ISL_AUX_USAGE_HIZ);
    if (info->hiz_usage == ISL_AUX_USAGE_HIZ) {
       db.HierarchicalDepthBufferEnable = true;
-#if GEN_GEN == 5 || GEN_GEN == 6
-      db.SeparateStencilBufferEnable = true;
-#endif
 
       hiz.SurfaceBaseAddress = info->hiz_address;
-      hiz.HierarchicalDepthBufferMOCS = info->mocs;
-      hiz.SurfacePitch = info->hiz_surf->row_pitch - 1;
+      hiz.MOCS = info->mocs;
+      hiz.SurfacePitch = info->hiz_surf->row_pitch_B - 1;
 #if GEN_GEN >= 8
       /* From the SKL PRM Vol2a:
        *
@@ -177,7 +203,26 @@ isl_genX(emit_depth_stencil_hiz_s)(const struct isl_device *dev, void *batch,
 #endif
 
       clear.DepthClearValueValid = true;
+#if GEN_GEN >= 8
       clear.DepthClearValue = info->depth_clear_value;
+#else
+      switch (info->depth_surf->format) {
+      case ISL_FORMAT_R32_FLOAT: {
+         union { float f; uint32_t u; } fu;
+         fu.f = info->depth_clear_value;
+         clear.DepthClearValue = fu.u;
+         break;
+      }
+      case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
+         clear.DepthClearValue = info->depth_clear_value * ((1u << 24) - 1);
+         break;
+      case ISL_FORMAT_R16_UNORM:
+         clear.DepthClearValue = info->depth_clear_value * ((1u << 16) - 1);
+         break;
+      default:
+         unreachable("Invalid depth type");
+      }
+#endif
    }
 #endif /* GEN_GEN >= 6 */