asahi: Extract sampler_view_for_surface
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 23 Jun 2023 18:23:30 +0000 (14:23 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Jul 2023 15:33:28 +0000 (15:33 +0000)
We'll reuse this logic for the spilled RT case.

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

src/gallium/drivers/asahi/agx_state.c

index 6e21212..303ead9 100644 (file)
@@ -1097,6 +1097,30 @@ image_view_for_surface(struct pipe_surface *surf)
    };
 }
 
+/* Similarly, to read render targets, surfaces are bound as textures */
+static struct pipe_sampler_view
+sampler_view_for_surface(struct pipe_surface *surf)
+{
+   return (struct pipe_sampler_view){
+      /* To reduce shader variants, we always use a 2D
+       * texture. For reloads of arrays and cube maps, we
+       * map a single layer as a 2D image.
+       */
+      .target = PIPE_TEXTURE_2D,
+      .swizzle_r = PIPE_SWIZZLE_X,
+      .swizzle_g = PIPE_SWIZZLE_Y,
+      .swizzle_b = PIPE_SWIZZLE_Z,
+      .swizzle_a = PIPE_SWIZZLE_W,
+      .u.tex =
+         {
+            .first_layer = surf->u.tex.first_layer,
+            .last_layer = surf->u.tex.last_layer,
+            .first_level = surf->u.tex.level,
+            .last_level = surf->u.tex.level,
+         },
+   };
+}
+
 static void
 agx_pack_image_atomic_data(void *packed, struct pipe_image_view *view)
 {
@@ -2273,27 +2297,9 @@ agx_build_meta(struct agx_batch *batch, bool store, bool partial_render)
          assert(surf != NULL && "cannot load nonexistent attachment");
 
          struct agx_resource *rsrc = agx_resource(surf->texture);
+         struct pipe_sampler_view sampler_view = sampler_view_for_surface(surf);
 
-         agx_pack_texture(texture.cpu, rsrc, surf->format,
-                          &(struct pipe_sampler_view){
-                             /* To reduce shader variants, we always use a 2D
-                              * texture. For reloads of arrays and cube maps, we
-                              * map a single layer as a 2D image.
-                              */
-                             .target = PIPE_TEXTURE_2D,
-                             .swizzle_r = PIPE_SWIZZLE_X,
-                             .swizzle_g = PIPE_SWIZZLE_Y,
-                             .swizzle_b = PIPE_SWIZZLE_Z,
-                             .swizzle_a = PIPE_SWIZZLE_W,
-                             .u.tex =
-                                {
-                                   .first_layer = surf->u.tex.first_layer,
-                                   .last_layer = surf->u.tex.last_layer,
-                                   .first_level = surf->u.tex.level,
-                                   .last_level = surf->u.tex.level,
-                                },
-                          },
-                          true);
+         agx_pack_texture(texture.cpu, rsrc, surf->format, &sampler_view, true);
 
          agx_usc_pack(&b, TEXTURE, cfg) {
             cfg.start = rt;