From 34a1c64d087c1d531f64863cd1928011a2d0bfcf Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sat, 30 Jan 2021 18:34:54 +0100 Subject: [PATCH] radv: Add plane width/height helpers. Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/vulkan/radv_device.c | 8 ++++---- src/amd/vulkan/radv_image.c | 15 ++++----------- src/amd/vulkan/vk_format.h | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 61718448aa9..0a062a5acac 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -7041,12 +7041,12 @@ radv_initialise_color_surface(struct radv_device *device, } if (device->physical_device->rad_info.chip_class >= GFX9) { - const struct vk_format_description *format_desc = vk_format_description(iview->image->vk_format); - unsigned mip0_depth = iview->image->type == VK_IMAGE_TYPE_3D ? (iview->extent.depth - 1) : (iview->image->info.array_size - 1); - unsigned width = iview->extent.width / (iview->plane_id ? format_desc->width_divisor : 1); - unsigned height = iview->extent.height / (iview->plane_id ? format_desc->height_divisor : 1); + unsigned width = vk_format_get_plane_width(iview->image->vk_format, + iview->plane_id, iview->extent.width); + unsigned height = vk_format_get_plane_height(iview->image->vk_format, + iview->plane_id, iview->extent.height); if (device->physical_device->rad_info.chip_class >= GFX10) { cb->cb_color_view |= S_028C6C_MIP_LEVEL_GFX10(iview->base_mip); diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index 65b37bc6022..8acbbabd1b3 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -1372,14 +1372,8 @@ radv_image_create_layout(struct radv_device *device, uint64_t offset; unsigned stride; - if (plane) { - const struct vk_format_description *desc = vk_format_description(image->vk_format); - assert(info.width % desc->width_divisor == 0); - assert(info.height % desc->height_divisor == 0); - - info.width /= desc->width_divisor; - info.height /= desc->height_divisor; - } + info.width = vk_format_get_plane_width(image->vk_format, plane, info.width); + info.height = vk_format_get_plane_height(image->vk_format, plane, info.height); if (create_info.no_metadata_planes || image->plane_count > 1) { image->planes[plane].surface.flags |= RADEON_SURF_DISABLE_DCC | @@ -1684,7 +1678,6 @@ radv_image_view_make_descriptor(struct radv_image_view *iview, { struct radv_image *image = iview->image; struct radv_image_plane *plane = &image->planes[plane_id]; - const struct vk_format_description *format_desc = vk_format_description(image->vk_format); bool is_stencil = iview->aspect_mask == VK_IMAGE_ASPECT_STENCIL_BIT; uint32_t blk_w; union radv_descriptor *descriptor; @@ -1709,8 +1702,8 @@ radv_image_view_make_descriptor(struct radv_image_view *iview, hw_level, hw_level + iview->level_count - 1, iview->base_layer, iview->base_layer + iview->layer_count - 1, - iview->extent.width / (plane_id ? format_desc->width_divisor : 1), - iview->extent.height / (plane_id ? format_desc->height_divisor : 1), + vk_format_get_plane_width(image->vk_format, plane_id, iview->extent.width), + vk_format_get_plane_height(image->vk_format, plane_id, iview->extent.height), iview->extent.depth, descriptor->plane_descriptors[descriptor_plane_id], descriptor_plane_id ? NULL : descriptor->fmask_descriptor); diff --git a/src/amd/vulkan/vk_format.h b/src/amd/vulkan/vk_format.h index 2017eb6d896..854b074ce6f 100644 --- a/src/amd/vulkan/vk_format.h +++ b/src/amd/vulkan/vk_format.h @@ -576,6 +576,20 @@ vk_format_get_plane_count(VkFormat format) return desc->plane_count; } +static inline unsigned +vk_format_get_plane_width(VkFormat format, unsigned plane, + unsigned width) +{ + return util_format_get_plane_width(vk_format_to_pipe_format(format), plane, width); +} + +static inline unsigned +vk_format_get_plane_height(VkFormat format, unsigned plane, + unsigned height) +{ + return util_format_get_plane_height(vk_format_to_pipe_format(format), plane, height); +} + static inline VkFormat vk_format_get_plane_format(VkFormat format, unsigned plane_id) {