From 08cd331cc0bc05cca51c39fd12c603bb068760d5 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 4 Feb 2025 23:47:03 -0800 Subject: [PATCH] panvk: implement VK_EXT_separate_stencil_usage Needed for Vulkan 1.2. The only real improvement from this is that in some situations we can skip creating texture descriptors for image views that have a more restrictive usage for either the depth or stencil aspect. Signed-off-by: Benjamin Lee Reviewed-by: Mary Guillemard Part-of: --- docs/features.txt | 2 +- docs/relnotes/new_features.txt | 1 + src/panfrost/vulkan/panvk_image.c | 39 +++++++++++---------- src/panfrost/vulkan/panvk_physical_device.c | 21 +++++++---- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index 428bb19603f..0e17ae25f6e 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -479,7 +479,7 @@ Vulkan 1.2 -- all DONE: anv, nvk, tu, vn VK_EXT_host_query_reset DONE (anv, hasvk, lvp, nvk, panvk, pvr, radv, tu, v3dv, vn) VK_EXT_sampler_filter_minmax DONE (anv, lvp, nvk, panvk/v10+, radv, tu, vn) VK_EXT_scalar_block_layout DONE (anv, dzn, hasvk, lvp, nvk, panvk, pvr, radv/gfx7+, tu, vn, v3dv/vc7+) - VK_EXT_separate_stencil_usage DONE (anv, dzn, hasvk, lvp, nvk, radv, tu, v3dv, vn) + VK_EXT_separate_stencil_usage DONE (anv, dzn, hasvk, lvp, nvk, panvk, radv, tu, v3dv, vn) VK_EXT_shader_viewport_index_layer DONE (anv, hasvk, lvp, nvk, radv, tu, vn) Vulkan 1.3 -- all DONE: anv, lvp, nvk, radv, tu, vn, v3dv diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index 8cd15ecfebf..ee7c5a0798f 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -3,3 +3,4 @@ storagePushConstant16 on panvk storageInputOutput16 on panvk VK_KHR_depth_stencil_resolve on panvk VK_KHR_separate_depth_stencil_layouts on panvk +VK_EXT_separate_stencil_usage on panvk diff --git a/src/panfrost/vulkan/panvk_image.c b/src/panfrost/vulkan/panvk_image.c index 37d06f5cdc5..758c621284a 100644 --- a/src/panfrost/vulkan/panvk_image.c +++ b/src/panfrost/vulkan/panvk_image.c @@ -251,46 +251,47 @@ static void panvk_image_pre_mod_select_meta_adjustments(struct panvk_image *image) { const VkImageAspectFlags aspects = vk_format_aspects(image->vk.format); + const VkImageUsageFlags all_usage = + image->vk.usage | image->vk.stencil_usage; /* We do image blit/resolve with vk_meta, so when an image is flagged as * being a potential transfer source, we also need to add the sampled usage. */ - if (image->vk.usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) { + if (image->vk.usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) image->vk.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; - if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) - image->vk.stencil_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; - } + if (image->vk.stencil_usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) + image->vk.stencil_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; + /* Similarly, image that can be a transfer destination can be attached + * as a color or depth-stencil attachment by vk_meta. */ if (image->vk.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) { - /* Similarly, image that can be a transfer destination can be attached - * as a color or depth-stencil attachment by vk_meta. */ if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) image->vk.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) - image->vk.stencil_usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - if (aspects & VK_IMAGE_ASPECT_COLOR_BIT) { image->vk.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; image->vk.usage |= VK_IMAGE_USAGE_STORAGE_BIT; } - - /* vk_meta creates 2D array views of 3D images. */ - if (image->vk.image_type == VK_IMAGE_TYPE_3D) - image->vk.create_flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; } + if (image->vk.stencil_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) + image->vk.stencil_usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + /* vk_meta creates 2D array views of 3D images. */ + if (all_usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT && + image->vk.image_type == VK_IMAGE_TYPE_3D) + image->vk.create_flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; + /* Needed for resolve operations. */ if (image->vk.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) image->vk.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; - if (image->vk.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) { - if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) - image->vk.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; + if (image->vk.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT && + aspects & VK_IMAGE_ASPECT_DEPTH_BIT) + image->vk.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; - if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) - image->vk.stencil_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; - } + if (image->vk.stencil_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) + image->vk.stencil_usage |= VK_IMAGE_USAGE_SAMPLED_BIT; if ((image->vk.usage & (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT)) && diff --git a/src/panfrost/vulkan/panvk_physical_device.c b/src/panfrost/vulkan/panvk_physical_device.c index ecc22ba0325..7178c321775 100644 --- a/src/panfrost/vulkan/panvk_physical_device.c +++ b/src/panfrost/vulkan/panvk_physical_device.c @@ -246,6 +246,7 @@ get_device_extensions(const struct panvk_physical_device *device, .EXT_queue_family_foreign = true, .EXT_sampler_filter_minmax = arch >= 10, .EXT_scalar_block_layout = true, + .EXT_separate_stencil_usage = true, .EXT_shader_module_identifier = true, .EXT_subgroup_size_control = arch >= 10, /* requires vk1.1 */ .EXT_tooling_info = true, @@ -1272,6 +1273,12 @@ get_image_format_properties(struct panvk_physical_device *physical_device, get_format_properties(physical_device, info->format, &format_props); + const VkImageStencilUsageCreateInfo *stencil_usage_info = + vk_find_struct_const(info->pNext, IMAGE_STENCIL_USAGE_CREATE_INFO); + VkImageUsageFlags stencil_usage = + stencil_usage_info ? stencil_usage_info->stencilUsage : info->usage; + VkImageUsageFlags all_usage = info->usage | stencil_usage; + switch (info->tiling) { case VK_IMAGE_TILING_LINEAR: format_feature_flags = format_props.linearTilingFeatures; @@ -1339,7 +1346,7 @@ get_image_format_properties(struct panvk_physical_device *physical_device, (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) && !(info->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && - !(info->usage & VK_IMAGE_USAGE_STORAGE_BIT)) { + !(all_usage & VK_IMAGE_USAGE_STORAGE_BIT)) { sampleCounts |= VK_SAMPLE_COUNT_4_BIT; } @@ -1355,28 +1362,28 @@ get_image_format_properties(struct panvk_physical_device *physical_device, * There is one exception to this below for storage. */ if (!(info->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT)) { - if (info->usage & VK_IMAGE_USAGE_SAMPLED_BIT) { + if (all_usage & VK_IMAGE_USAGE_SAMPLED_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { goto unsupported; } } - if (info->usage & VK_IMAGE_USAGE_STORAGE_BIT) { + if (all_usage & VK_IMAGE_USAGE_STORAGE_BIT) { if (!(format_feature_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { goto unsupported; } } - if (info->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT || - ((info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && + if (all_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT || + ((all_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && !vk_format_is_depth_or_stencil(info->format))) { if (!(format_feature_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { goto unsupported; } } - if ((info->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) || - ((info->usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && + if ((all_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) || + ((all_usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) && vk_format_is_depth_or_stencil(info->format))) { if (!(format_feature_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {