From 51b04a7dfbc20e5da6e45d514773f0e22bb2b331 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Fri, 4 Mar 2022 12:29:52 -0800 Subject: [PATCH] turnip: Add support for VK_KHR_format_feature_flags2. This reports all of our storage formats as supporting read/write without format, since we don't have any in-shader format conversions. Similarly, shadow comparisons were already supported on all the depth formats. This extension is required for VK 1.3. Part-of: --- docs/features.txt | 2 +- src/freedreno/vulkan/tu_device.c | 1 + src/freedreno/vulkan/tu_formats.c | 34 +++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index c21d16ba4d4..9ee43f92dd1 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -474,7 +474,7 @@ Vulkan 1.3 -- all DONE: anv, radv, lvp VK_KHR_copy_commands2 DONE (anv, lvp, radv, tu, v3dv) VK_KHR_dynamic_rendering DONE (anv, lvp, radv) - VK_KHR_format_feature_flags2 DONE (anv, radv) + VK_KHR_format_feature_flags2 DONE (anv, radv, tu) VK_KHR_maintenance4 DONE (anv, radv) VK_KHR_shader_non_semantic_info DONE (anv, radv, tu, v3dv) VK_KHR_shader_terminate_invocation DONE (anv, radv, tu) diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index 04d963af4e4..2fd037cc90b 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -131,6 +131,7 @@ get_device_extensions(const struct tu_physical_device *device, .KHR_external_memory_fd = true, .KHR_external_semaphore = true, .KHR_external_semaphore_fd = true, + .KHR_format_feature_flags2 = true, .KHR_get_memory_requirements2 = true, .KHR_imageless_framebuffer = true, .KHR_incremental_present = TU_HAS_SURFACE, diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index 1bd62265264..9cc38cf4055 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -163,9 +163,9 @@ static void tu_physical_device_get_format_properties( struct tu_physical_device *physical_device, VkFormat vk_format, - VkFormatProperties *out_properties) + VkFormatProperties3 *out_properties) { - VkFormatFeatureFlags linear = 0, optimal = 0, buffer = 0; + VkFormatFeatureFlags2 linear = 0, optimal = 0, buffer = 0; enum pipe_format format = tu_vk_format_to_pipe_format(vk_format); const struct util_format_description *desc = util_format_description(format); @@ -223,8 +223,12 @@ tu_physical_device_get_format_properties( */ struct tu_native_format tex = tu6_format_texture(format, TILE6_LINEAR); if (tex.swap == WZYX && tex.fmt != FMT6_1_5_5_5_UNORM) { - optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; - buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT; + optimal |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT | + VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT | + VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT_KHR; + buffer |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT | + VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT | + VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT_KHR; } /* TODO: The blob also exposes these for R16G16_UINT/R16G16_SINT, but we @@ -274,6 +278,12 @@ tu_physical_device_get_format_properties( buffer = 0; } + /* All our depth formats support shadow comparisons. */ + if (vk_format_has_depth(vk_format) && (optimal & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { + optimal |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT; + linear |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT; + } + /* From the Vulkan 1.3.205 spec, section 19.3 "43.3. Required Format Support": * * Mandatory format support: depth/stencil with VkImageType @@ -304,8 +314,20 @@ tu_GetPhysicalDeviceFormatProperties2( { TU_FROM_HANDLE(tu_physical_device, physical_device, physicalDevice); + VkFormatProperties3 local_props3; + VkFormatProperties3 *props3 = + vk_find_struct(pFormatProperties->pNext, FORMAT_PROPERTIES_3); + if (!props3) + props3 = &local_props3; + tu_physical_device_get_format_properties( - physical_device, format, &pFormatProperties->formatProperties); + physical_device, format, props3); + + pFormatProperties->formatProperties = (VkFormatProperties) { + .linearTilingFeatures = props3->linearTilingFeatures, + .optimalTilingFeatures = props3->optimalTilingFeatures, + .bufferFeatures = props3->bufferFeatures, + }; VkDrmFormatModifierPropertiesListEXT *list = vk_find_struct(pFormatProperties->pNext, DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT); @@ -344,7 +366,7 @@ tu_get_image_format_properties( VkImageFormatProperties *pImageFormatProperties, VkFormatFeatureFlags *p_feature_flags) { - VkFormatProperties format_props; + VkFormatProperties3 format_props; VkFormatFeatureFlags format_feature_flags; VkExtent3D maxExtent; uint32_t maxMipLevels;