From 6c3457033a8ecc76f7c07c87221bca69c8e7ce07 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Fri, 3 May 2024 11:13:08 +0200 Subject: [PATCH] radv: Implement VK_MESA_image_alignment_control Signed-off-by: Hans-Kristian Arntzen Co-authored-by: Bas Nieuwenhuizen Co-authored-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Samuel Pitoiset Part-of: --- docs/features.txt | 1 + docs/relnotes/new_features.txt | 1 + src/amd/vulkan/radv_image.c | 21 +++++++++++++++++++++ src/amd/vulkan/radv_physical_device.c | 9 +++++++++ 4 files changed, 32 insertions(+) diff --git a/docs/features.txt b/docs/features.txt index a6f1f5b7ffe..a9a0753b6e4 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -665,6 +665,7 @@ Khronos extensions that are not part of any Vulkan version: VK_INTEL_shader_integer_functions2 DONE (anv, hasvk, radv) VK_KHR_map_memory2 DONE (anv, nvk, radv, tu) VK_EXT_map_memory_placed DONE (anv, nvk, radv, tu) + VK_MESA_image_alignment_control DONE (radv) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index c007dfbc893..eec9619f4ac 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -1,2 +1,3 @@ VK_KHR_dynamic_rendering_local_read on RADV VK_EXT_legacy_vertex_attributes on lavapipe, ANV, Turnip and RADV +VK_MESA_image_alignment_control on RADV diff --git a/src/amd/vulkan/radv_image.c b/src/amd/vulkan/radv_image.c index 93960d79e9c..be51cc5af3b 100644 --- a/src/amd/vulkan/radv_image.c +++ b/src/amd/vulkan/radv_image.c @@ -605,10 +605,13 @@ radv_get_surface_flags(struct radv_device *device, struct radv_image *image, uns const VkImageCreateInfo *pCreateInfo, VkFormat image_format) { const struct radv_physical_device *pdev = radv_device_physical(device); + const struct radv_instance *instance = radv_physical_device_instance(pdev); uint64_t flags; unsigned array_mode = radv_choose_tiling(device, pCreateInfo, image_format); VkFormat format = radv_image_get_plane_format(pdev, image, plane_id); const struct util_format_description *desc = vk_format_description(format); + const VkImageAlignmentControlCreateInfoMESA *alignment = + vk_find_struct_const(pCreateInfo->pNext, IMAGE_ALIGNMENT_CONTROL_CREATE_INFO_MESA); bool is_depth, is_stencil; is_depth = util_format_has_depth(desc); @@ -692,6 +695,24 @@ radv_get_surface_flags(struct radv_device *device, struct radv_image *image, uns if (!(pCreateInfo->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT))) flags |= RADEON_SURF_NO_TEXTURE; + if (alignment && alignment->maximumRequestedAlignment && !(instance->debug_flags & RADV_DEBUG_FORCE_COMPRESS)) { + bool is_4k_capable; + + if (!vk_format_is_depth_or_stencil(image_format)) { + is_4k_capable = + !(pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && (flags & RADEON_SURF_DISABLE_DCC) && + (flags & RADEON_SURF_NO_FMASK); + } else { + /* Depth-stencil format without DEPTH_STENCIL usage does not work either. */ + is_4k_capable = false; + } + + if (is_4k_capable && alignment->maximumRequestedAlignment <= 4096) + flags |= RADEON_SURF_PREFER_4K_ALIGNMENT; + if (alignment->maximumRequestedAlignment <= 64 * 1024) + flags |= RADEON_SURF_PREFER_64K_ALIGNMENT; + } + return flags; } diff --git a/src/amd/vulkan/radv_physical_device.c b/src/amd/vulkan/radv_physical_device.c index 3bf152031f5..b2fe71b0e7e 100644 --- a/src/amd/vulkan/radv_physical_device.c +++ b/src/amd/vulkan/radv_physical_device.c @@ -702,6 +702,7 @@ radv_physical_device_get_supported_extensions(const struct radv_physical_device .GOOGLE_hlsl_functionality1 = true, .GOOGLE_user_type = true, .INTEL_shader_integer_functions2 = true, + .MESA_image_alignment_control = true, .NV_compute_shader_derivatives = true, .NV_device_generated_commands = !pdev->use_llvm && instance->drirc.enable_dgc, .NV_device_generated_commands_compute = !pdev->use_llvm && instance->drirc.enable_dgc, @@ -1219,6 +1220,9 @@ radv_physical_device_get_features(const struct radv_physical_device *pdev, struc /* VK_EXT_legacy_vertex_attributes */ .legacyVertexAttributes = true, + + /* VK_MESA_image_alignment_control */ + .imageAlignmentControl = true, }; } @@ -1918,6 +1922,11 @@ radv_get_physical_device_properties(struct radv_physical_device *pdev) /* VK_EXT_legacy_vertex_attributes */ p->nativeUnalignedPerformance = false; + + /* VK_MESA_image_alignment_control */ + p->supportedImageAlignmentMask = (4 * 1024) | (64 * 1024); + if (gfx11plus) + p->supportedImageAlignmentMask |= 256 * 1024; } static VkResult