Module: Mesa Branch: main Commit: c738c99a4a877c8ae408dfbd50d8ba7176d2673e URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c738c99a4a877c8ae408dfbd50d8ba7176d2673e
Author: Bas Nieuwenhuizen <[email protected]> Date: Sat Aug 20 20:17:07 2022 +0200 radv: Add 3d tile shapes for sparse binding. Reviewed-by: Samuel Pitoiset <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18165> --- src/amd/vulkan/radv_formats.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/amd/vulkan/radv_formats.c b/src/amd/vulkan/radv_formats.c index 1f48bb7ab0b..dfca8d9e59c 100644 --- a/src/amd/vulkan/radv_formats.c +++ b/src/amd/vulkan/radv_formats.c @@ -1861,8 +1861,8 @@ fail: } static void -fill_sparse_image_format_properties(struct radv_physical_device *pdev, VkFormat format, - VkSparseImageFormatProperties *prop) +fill_sparse_image_format_properties(struct radv_physical_device *pdev, VkImageType type, + VkFormat format, VkSparseImageFormatProperties *prop) { prop->aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; prop->flags = 0; @@ -1873,12 +1873,29 @@ fill_sparse_image_format_properties(struct radv_physical_device *pdev, VkFormat if (pdev->rad_info.gfx_level < GFX9) prop->flags |= VK_SPARSE_IMAGE_FORMAT_SINGLE_MIPTAIL_BIT; - /* This assumes the sparse image tile size is always 64 KiB (1 << 16) */ - unsigned l2_size = 16 - util_logbase2(vk_format_get_blocksize(format)); - unsigned w = (1u << ((l2_size + 1) / 2)) * vk_format_get_blockwidth(format); - unsigned h = (1u << (l2_size / 2)) * vk_format_get_blockheight(format); - - prop->imageGranularity = (VkExtent3D){w, h, 1}; + unsigned w, h; + unsigned d = 1; + if (type == VK_IMAGE_TYPE_3D) { + if (pdev->rad_info.gfx_level >= GFX9) { + unsigned l2_size = 16 - util_logbase2(vk_format_get_blocksize(format)); + w = (1u << ((l2_size + 2) / 3)) * vk_format_get_blockwidth(format); + h = (1u << ((l2_size + 1) / 3)) * vk_format_get_blockheight(format); + d = (1u << ((l2_size + 0) / 3)); + } else { + /* GFX7/GFX8 thick tiling modes */ + unsigned bs = vk_format_get_blocksize(format); + unsigned l2_size = 16 - util_logbase2(bs) - (bs <= 4 ? 2 : 0); + w = (1u << ((l2_size + 1) / 2)) * vk_format_get_blockwidth(format); + h = (1u << (l2_size / 2)) * vk_format_get_blockheight(format); + d = bs <= 4 ? 4 : 1; + } + } else { + /* This assumes the sparse image tile size is always 64 KiB (1 << 16) */ + unsigned l2_size = 16 - util_logbase2(vk_format_get_blocksize(format)); + w = (1u << ((l2_size + 1) / 2)) * vk_format_get_blockwidth(format); + h = (1u << (l2_size / 2)) * vk_format_get_blockheight(format); + } + prop->imageGranularity = (VkExtent3D){w, h, d}; } VKAPI_ATTR void VKAPI_CALL @@ -1913,7 +1930,8 @@ radv_GetPhysicalDeviceSparseImageFormatProperties2( vk_outarray_append_typed(VkSparseImageFormatProperties2, &out, prop) { - fill_sparse_image_format_properties(pdev, pFormatInfo->format, &prop->properties); + fill_sparse_image_format_properties(pdev, pFormatInfo->type, pFormatInfo->format, + &prop->properties); }; } @@ -1936,7 +1954,8 @@ radv_GetImageSparseMemoryRequirements2(VkDevice _device, vk_outarray_append_typed(VkSparseImageMemoryRequirements2, &out, req) { - fill_sparse_image_format_properties(device->physical_device, image->vk.format, + fill_sparse_image_format_properties(device->physical_device, image->vk.image_type, + image->vk.format, &req->memoryRequirements.formatProperties); req->memoryRequirements.imageMipTailFirstLod = image->planes[0].surface.first_mip_tail_level;
