asahi: Fix depth for cube maps
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 3 Sep 2022 02:23:05 +0000 (22:23 -0400)
committerMarge Bot <emma+marge@anholt.net>
Sun, 4 Sep 2022 18:05:31 +0000 (18:05 +0000)
For cube maps, depth=1 in the hardware (but 6 in Gallium). Likewise for
cube map arrays, depth=n in the hardware (but 6n in Gallium). We need to
divide to compensate. This will be relevant for cube map arrays in the
future -- add the dimension XML for cube map arrays too.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18380>

src/asahi/lib/cmdbuf.xml
src/gallium/drivers/asahi/agx_state.c

index 66fdbc8..ee58bdd 100644 (file)
     <value name="2D Multisampled" value="4"/>
     <value name="3D" value="5"/>
     <value name="Cube" value="6"/>
+    <value name="Cube Array" value="7"/>
     <value name="2D Array Multisampled" value="8"/>
   </enum>
 
index c1bf2cf..3116b34 100644 (file)
@@ -476,10 +476,16 @@ agx_create_sampler_view(struct pipe_context *pctx,
       cfg.unk_mipmapped = rsrc->mipmapped;
       cfg.srgb_2_channel = cfg.srgb && util_format_colormask(desc) == 0x3;
 
-      if (state->target == PIPE_TEXTURE_3D)
+      if (state->target == PIPE_TEXTURE_3D) {
          cfg.depth = u_minify(texture->depth0, level);
-      else
-         cfg.depth = state->u.tex.last_layer - state->u.tex.first_layer + 1;
+      } else {
+         unsigned layers = state->u.tex.last_layer - state->u.tex.first_layer + 1;
+
+         if ((state->target == PIPE_TEXTURE_CUBE) || (state->target == PIPE_TEXTURE_CUBE_ARRAY))
+            layers /= 6;
+
+         cfg.depth = layers;
+      }
 
       if (rsrc->modifier == DRM_FORMAT_MOD_LINEAR) {
          cfg.stride = ail_get_linear_stride_B(&rsrc->layout, level) - 16;