From dfd5e3da7b53535fb88b7c9a3180f6650afb0b37 Mon Sep 17 00:00:00 2001 From: Mohamed Ahmed Date: Wed, 19 Feb 2025 23:42:21 +0200 Subject: [PATCH] nvk: Implement VK_MESA_image_alignment_control This is needed by VKD3D in order to satisfy D3D12's image alignment requirements. Otherwise, it has to pad things out weirdly in order to re-align images behind the app's back. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12637 Part-of: --- docs/features.txt | 2 +- docs/relnotes/new_features.txt | 1 + src/nouveau/ci/nvk-ga106-vkd3d-fails.txt | 1 - src/nouveau/vulkan/nvk_image.c | 14 +++++++++++++- src/nouveau/vulkan/nvk_physical_device.c | 7 +++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index 338332c68db..e503120ce5b 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -690,7 +690,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_depth_clamp_zero_one DONE (anv, nvk, radv, tu, v3dv/vc7+) VK_INTEL_shader_integer_functions2 DONE (anv, hasvk, radv) VK_EXT_map_memory_placed DONE (anv, nvk, radv, tu) - VK_MESA_image_alignment_control DONE (anv, radv) + VK_MESA_image_alignment_control DONE (anv, nvk, radv) VK_EXT_legacy_dithering DONE (anv, tu) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index be9f9bb9118..a1a6ca5d607 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -10,3 +10,4 @@ ycbcrImageArrays on panvk/v10+ VK_KHR_imageless_framebuffer on panvk VK_KHR_uniform_buffer_standard_layout on panvk VK_EXT_border_color_swizzle on panvk +VK_MESA_image_alignment_control on NVK \ No newline at end of file diff --git a/src/nouveau/ci/nvk-ga106-vkd3d-fails.txt b/src/nouveau/ci/nvk-ga106-vkd3d-fails.txt index b71b088029a..c3210dd77ab 100644 --- a/src/nouveau/ci/nvk-ga106-vkd3d-fails.txt +++ b/src/nouveau/ci/nvk-ga106-vkd3d-fails.txt @@ -8,5 +8,4 @@ test_multisample_rendering,Crash test_uav_counter_null_behavior_dxbc,Crash test_uav_counter_null_behavior_dxil,Crash -test_suballocate_small_textures_size,Fail test_sampler_feedback_implicit_lod_aniso,Fail diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 905e36fb909..c2906f210b9 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -805,6 +805,15 @@ nvk_image_init(struct nvk_device *dev, explicit_row_stride_B = eci.pPlaneLayouts[0].rowPitch; } + uint32_t max_alignment_B = 0; + const VkImageAlignmentControlCreateInfoMESA *alignment = + vk_find_struct_const(pCreateInfo->pNext, + IMAGE_ALIGNMENT_CONTROL_CREATE_INFO_MESA); + if (alignment && alignment->maximumRequestedAlignment) { + assert(util_is_power_of_two_or_zero(alignment->maximumRequestedAlignment)); + max_alignment_B = alignment->maximumRequestedAlignment; + } + if (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { /* Modifiers are not supported with YCbCr */ assert(image->plane_count == 1); @@ -852,6 +861,7 @@ nvk_image_init(struct nvk_device *dev, .samples = pCreateInfo->samples, .usage = usage & ~NIL_IMAGE_USAGE_LINEAR_BIT, .explicit_row_stride_B = 0, + .max_alignment_B = 0, }; image->linear_tiled_shadow.nil = nil_image_new(&pdev->info, &tiled_shadow_nil_info); @@ -887,7 +897,8 @@ nvk_image_init(struct nvk_device *dev, .levels = pCreateInfo->mipLevels, .samples = pCreateInfo->samples, .usage = usage, - .explicit_row_stride_B = explicit_row_stride_B, + .explicit_row_stride_B = explicit_row_stride_B, + .max_alignment_B = max_alignment_B, }; } @@ -919,6 +930,7 @@ nvk_image_init(struct nvk_device *dev, .samples = pCreateInfo->samples, .usage = usage, .explicit_row_stride_B = 0, + .max_alignment_B = 0, }; image->stencil_copy_temp.nil = diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index 50194222da2..477682c05a5 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -287,6 +287,7 @@ nvk_get_device_extensions(const struct nvk_instance *instance, .GOOGLE_decorate_string = true, .GOOGLE_hlsl_functionality1 = true, .GOOGLE_user_type = true, + .MESA_image_alignment_control = true, .NV_compute_shader_derivatives = nvk_use_nak(info), .NV_shader_sm_builtins = true, .VALVE_mutable_descriptor_type = true, @@ -691,6 +692,9 @@ nvk_get_device_features(const struct nv_device_info *info, /* VK_EXT_ycbcr_image_arrays */ .ycbcrImageArrays = true, + /* VK_MESA_image_alignment_control */ + .imageAlignmentControl = true, + /* VK_NV_shader_sm_builtins */ .shaderSMBuiltins = true, }; @@ -1128,6 +1132,9 @@ nvk_get_device_properties(const struct nvk_instance *instance, .fragmentShadingRateWithCustomSampleLocations = true, .fragmentShadingRateStrictMultiplyCombiner = true, + /* VK_MESA_image_alignment_control */ + .supportedImageAlignmentMask = (4 * 1024) | (16 * 1024) | (64 * 1024), + /* VK_NV_shader_sm_builtins */ .shaderSMCount = (uint32_t)info->tpc_count * info->mp_per_tpc, .shaderWarpsPerSM = info->max_warps_per_mp,