Module: Mesa
Branch: main
Commit: 8aa62ba240de81741a6bc159bf86f30a7cb0cd40
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8aa62ba240de81741a6bc159bf86f30a7cb0cd40

Author: Chia-I Wu <[email protected]>
Date:   Mon Oct 30 14:04:13 2023 -0700

radv: fix asserts for radv_init_metadata

radv_init_metadata hits several assert failures when the image is
multi-planar.  Make sure we use plane 0.

This change should make no difference in practice.  Also, this is done
only to follow radeonsi.  Since the opaque metadata is mainly for
validations and DCC, and we don't enable DCC for multi-planar images, we
probably don't need to call radv_query_opaque_metadata at all.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25964>

---

 src/amd/vulkan/radv_image.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c
index 58fefb95293..6d7bd584e52 100644
--- a/src/amd/vulkan/radv_image.c
+++ b/src/amd/vulkan/radv_image.c
@@ -1395,30 +1395,36 @@ radv_make_texture_descriptor(struct radv_device 
*device, struct radv_image *imag
 }
 
 static void
-radv_query_opaque_metadata(struct radv_device *device, struct radv_image 
*image, struct radeon_bo_metadata *md)
+radv_query_opaque_metadata(struct radv_device *device, struct radv_image 
*image, unsigned plane_id,
+                           struct radeon_bo_metadata *md)
 {
    static const VkComponentMapping fixedmapping;
+   const VkFormat plane_format = 
radv_image_get_plane_format(device->physical_device, image, plane_id);
+   const unsigned plane_width = vk_format_get_plane_width(image->vk.format, 
plane_id, image->vk.extent.width);
+   const unsigned plane_height = vk_format_get_plane_height(image->vk.format, 
plane_id, image->vk.extent.height);
+   struct radeon_surf *surface = &image->planes[plane_id].surface;
+   const struct legacy_surf_level *base_level_info =
+      device->physical_device->rad_info.gfx_level <= GFX8 ? 
&surface->u.legacy.level[0] : NULL;
    uint32_t desc[8];
 
-   assert(image->plane_count == 1);
+   radv_make_texture_descriptor(device, image, false, 
(VkImageViewType)image->vk.image_type, plane_format,
+                                &fixedmapping, 0, image->vk.mip_levels - 1, 0, 
image->vk.array_layers - 1, plane_width,
+                                plane_height, image->vk.extent.depth, 0.0f, 
desc, NULL, 0, NULL, NULL);
 
-   radv_make_texture_descriptor(device, image, false, 
(VkImageViewType)image->vk.image_type, image->vk.format,
-                                &fixedmapping, 0, image->vk.mip_levels - 1, 0, 
image->vk.array_layers - 1,
-                                image->vk.extent.width, 
image->vk.extent.height, image->vk.extent.depth, 0.0f, desc,
-                                NULL, 0, NULL, NULL);
+   si_set_mutable_tex_desc_fields(device, image, base_level_info, plane_id, 0, 
0, surface->blk_w, false, false, false,
+                                  false, desc, NULL);
 
-   si_set_mutable_tex_desc_fields(device, image, 
&image->planes[0].surface.u.legacy.level[0], 0, 0, 0,
-                                  image->planes[0].surface.blk_w, false, 
false, false, false, desc, NULL);
-
-   ac_surface_compute_umd_metadata(&device->physical_device->rad_info, 
&image->planes[0].surface, image->vk.mip_levels,
-                                   desc, &md->size_metadata, md->metadata,
+   ac_surface_compute_umd_metadata(&device->physical_device->rad_info, 
surface, image->vk.mip_levels, desc,
+                                   &md->size_metadata, md->metadata,
                                    device->instance->debug_flags & 
RADV_DEBUG_EXTRA_MD);
 }
 
 void
 radv_init_metadata(struct radv_device *device, struct radv_image *image, 
struct radeon_bo_metadata *metadata)
 {
-   struct radeon_surf *surface = &image->planes[0].surface;
+   /* use plane 0, even when there are multiple planes, to follow radeonsi */
+   const unsigned plane_id = 0;
+   struct radeon_surf *surface = &image->planes[plane_id].surface;
 
    memset(metadata, 0, sizeof(*metadata));
 
@@ -1446,7 +1452,7 @@ radv_init_metadata(struct radv_device *device, struct 
radv_image *image, struct
       metadata->u.legacy.stride = surface->u.legacy.level[0].nblk_x * 
surface->bpe;
       metadata->u.legacy.scanout = (surface->flags & RADEON_SURF_SCANOUT) != 0;
    }
-   radv_query_opaque_metadata(device, image, metadata);
+   radv_query_opaque_metadata(device, image, plane_id, metadata);
 }
 
 void

Reply via email to