From e6d2a426e67a364661c42dda48660ba5256a4966 Mon Sep 17 00:00:00 2001 From: Caterina Shablia Date: Thu, 24 Jul 2025 13:48:10 +0000 Subject: [PATCH] vulkan/runtime: add vk_image_subresource_slice_count vk_image_subresource_slice_count is useful when implementing image barriers. When maintenance9 is enabled, VkImageSubresourceRange::{baseArrayLayer,layerCount} specify the slices, rather than layers, to transition. This helper returns the number of slices specified in the subresource range, accounting for the VK_REMAINING_ARRAY_LAYERS sentinel. Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/vulkan/runtime/vk_image.c | 19 +++++++++++++++++++ src/vulkan/runtime/vk_image.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index 90c5b948c63..d8a8dd52e2d 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -284,6 +284,25 @@ vk_image_expand_aspect_mask(const struct vk_image *image, } } +uint32_t +vk_image_subresource_slice_count(const struct vk_device *device, + const struct vk_image *image, + const VkImageSubresourceLayers *range) +{ + assert(image->image_type == VK_IMAGE_TYPE_3D); + + bool layers_are_slices = device->enabled_features.maintenance9 && + (image->create_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT); + uint32_t slices = u_minify(image->extent.depth, range->mipLevel); + + if (!layers_are_slices) { + assert(range->baseArrayLayer == 0); + return slices; + } + return range->layerCount == VK_REMAINING_ARRAY_LAYERS ? + slices - range->baseArrayLayer : range->layerCount; +} + VkExtent3D vk_image_extent_to_elements(const struct vk_image *image, VkExtent3D extent) { diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h index f9869f19532..d318c283346 100644 --- a/src/vulkan/runtime/vk_image.h +++ b/src/vulkan/runtime/vk_image.h @@ -143,6 +143,11 @@ vk_image_mip_level_extent(const struct vk_image *image, return extent; } +uint32_t +vk_image_subresource_slice_count(const struct vk_device *device, + const struct vk_image *image, + const VkImageSubresourceLayers *range); + /* This is defined as a macro so that it works for both * VkImageSubresourceRange and VkImageSubresourceLayers */