From 8886a3385b237540d3a7f4441bb66e9b84a73dcd Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 15 Jul 2025 10:20:46 +0200 Subject: [PATCH] radv: add a function to create an image view for HiZ surfaces Only for storage because that's the only use case. Signed-off-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_image_view.c | 35 ++++++++++++++++++++++++++++++++ src/amd/vulkan/radv_image_view.h | 3 +++ 2 files changed, 38 insertions(+) diff --git a/src/amd/vulkan/radv_image_view.c b/src/amd/vulkan/radv_image_view.c index 1340407b582..f2f4b18fe83 100644 --- a/src/amd/vulkan/radv_image_view.c +++ b/src/amd/vulkan/radv_image_view.c @@ -642,6 +642,41 @@ radv_image_view_init(struct radv_image_view *iview, struct radv_device *device, } } +void +radv_hiz_image_view_init(struct radv_image_view *iview, struct radv_device *device, + const VkImageViewCreateInfo *pCreateInfo) +{ + VK_FROM_HANDLE(radv_image, image, pCreateInfo->image); + + vk_image_view_init(&device->vk, &iview->vk, true, pCreateInfo); + + assert(vk_format_has_depth(image->vk.format) && vk_format_has_stencil(image->vk.format)); + assert(iview->vk.aspects == VK_IMAGE_ASPECT_DEPTH_BIT); + + memset(&iview->descriptor, 0, sizeof(iview->descriptor)); + + iview->image = image; + + const uint32_t type = + radv_tex_dim(image->vk.image_type, iview->vk.view_type, image->vk.array_layers, image->vk.samples, true, false); + + const struct ac_gfx12_hiz_state hiz_state = { + .surf = &image->planes[0].surface, + .va = image->bindings[0].addr, + .type = type, + .num_samples = image->vk.samples, + .first_level = iview->vk.base_mip_level, + .last_level = iview->vk.base_mip_level + iview->vk.level_count - 1, + .num_levels = image->vk.mip_levels, + .first_layer = iview->vk.base_array_layer, + .last_layer = iview->vk.base_array_layer + iview->vk.layer_count - 1, + }; + + uint32_t *desc = iview->storage_descriptor.plane_descriptors[0]; + + ac_build_gfx12_hiz_descriptor(&hiz_state, desc); +} + void radv_image_view_finish(struct radv_image_view *iview) { diff --git a/src/amd/vulkan/radv_image_view.h b/src/amd/vulkan/radv_image_view.h index c19621c2d6b..86c8f007e5a 100644 --- a/src/amd/vulkan/radv_image_view.h +++ b/src/amd/vulkan/radv_image_view.h @@ -64,6 +64,9 @@ void radv_image_view_init(struct radv_image_view *view, struct radv_device *devi const struct radv_image_view_extra_create_info *extra_create_info); void radv_image_view_finish(struct radv_image_view *iview); +void radv_hiz_image_view_init(struct radv_image_view *iview, struct radv_device *device, + const VkImageViewCreateInfo *pCreateInfo); + void radv_set_mutable_tex_desc_fields(struct radv_device *device, struct radv_image *image, const struct legacy_surf_level *base_level_info, unsigned plane_id, unsigned base_level, unsigned first_level, unsigned block_width, bool is_stencil,