From: Jason Ekstrand Date: Thu, 22 Jul 2021 13:15:38 +0000 (-0500) Subject: anv,vulkan: Move ANV image layout helpers to common code X-Git-Tag: upstream/22.3.5~19109 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f2afa0abc7f8fadab9df21f0f0837b8ccbb974a;p=platform%2Fupstream%2Fmesa.git anv,vulkan: Move ANV image layout helpers to common code Reviewed-by: Iago Toral Quiroga Reviewed-by: Lionel Landwerlin Part-of: --- diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index eb136db..78ef854 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1902,161 +1902,6 @@ VkResult anv_GetImageDrmFormatModifierPropertiesEXT( return VK_SUCCESS; } -static VkImageUsageFlags -vk_image_layout_to_usage_flags(VkImageLayout layout, - VkImageAspectFlagBits aspect) -{ - assert(util_bitcount(aspect) == 1); - - switch (layout) { - case VK_IMAGE_LAYOUT_UNDEFINED: - case VK_IMAGE_LAYOUT_PREINITIALIZED: - return 0u; - - case VK_IMAGE_LAYOUT_GENERAL: - return ~0u; - - case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - assert(aspect & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV); - return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - assert(aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | - VK_IMAGE_ASPECT_STENCIL_BIT)); - return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL: - assert(aspect & VK_IMAGE_ASPECT_DEPTH_BIT); - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); - - case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL: - assert(aspect & VK_IMAGE_ASPECT_STENCIL_BIT); - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); - - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - assert(aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | - VK_IMAGE_ASPECT_STENCIL_BIT)); - return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | - VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; - - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL: - assert(aspect & VK_IMAGE_ASPECT_DEPTH_BIT); - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); - - case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL: - assert(aspect & VK_IMAGE_ASPECT_STENCIL_BIT); - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); - - case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: - return VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; - - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - return VK_IMAGE_USAGE_TRANSFER_SRC_BIT; - - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - return VK_IMAGE_USAGE_TRANSFER_DST_BIT; - - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: - if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) { - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); - } else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); - } else { - assert(!"Must be a depth/stencil aspect"); - return 0; - } - - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: - if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) { - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); - } else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { - return vk_image_layout_to_usage_flags( - VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); - } else { - assert(!"Must be a depth/stencil aspect"); - return 0; - } - - case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: - assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); - /* This needs to be handled specially by the caller */ - return 0; - - case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: - assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); - return vk_image_layout_to_usage_flags(VK_IMAGE_LAYOUT_GENERAL, aspect); - - case VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV: - assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); - return VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV; - - case VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT: - assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); - return VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT; - - case VK_IMAGE_LAYOUT_MAX_ENUM: - case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR: - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR: - unreachable("Invalid image layout."); - } - - unreachable("Invalid image layout."); -} - -static bool -vk_image_layout_is_read_only(VkImageLayout layout, - VkImageAspectFlagBits aspect) -{ - assert(util_bitcount(aspect) == 1); - - switch (layout) { - case VK_IMAGE_LAYOUT_UNDEFINED: - case VK_IMAGE_LAYOUT_PREINITIALIZED: - return true; /* These are only used for layout transitions */ - - case VK_IMAGE_LAYOUT_GENERAL: - case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL: - case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL: - return false; - - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: - case VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV: - case VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT: - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL: - return true; - - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: - return aspect == VK_IMAGE_ASPECT_DEPTH_BIT; - - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: - return aspect == VK_IMAGE_ASPECT_STENCIL_BIT; - - case VK_IMAGE_LAYOUT_MAX_ENUM: - case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR: - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR: - unreachable("Invalid image layout."); - } - - unreachable("Invalid image layout."); -} - /** * This function returns the assumed isl_aux_state for a given VkImageLayout. * Because Vulkan image layouts don't map directly to isl_aux_state enums, the diff --git a/src/vulkan/util/vk_image.c b/src/vulkan/util/vk_image.c index 2e1f4ad..663a209 100644 --- a/src/vulkan/util/vk_image.c +++ b/src/vulkan/util/vk_image.c @@ -398,3 +398,158 @@ vk_image_view_destroy(struct vk_device *device, { vk_object_free(device, alloc, image_view); } + +bool +vk_image_layout_is_read_only(VkImageLayout layout, + VkImageAspectFlagBits aspect) +{ + assert(util_bitcount(aspect) == 1); + + switch (layout) { + case VK_IMAGE_LAYOUT_UNDEFINED: + case VK_IMAGE_LAYOUT_PREINITIALIZED: + return true; /* These are only used for layout transitions */ + + case VK_IMAGE_LAYOUT_GENERAL: + case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: + case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: + case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL: + case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL: + return false; + + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: + case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: + case VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV: + case VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT: + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL: + return true; + + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: + return aspect == VK_IMAGE_ASPECT_DEPTH_BIT; + + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: + return aspect == VK_IMAGE_ASPECT_STENCIL_BIT; + + case VK_IMAGE_LAYOUT_MAX_ENUM: + case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR: + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR: + unreachable("Invalid image layout."); + } + + unreachable("Invalid image layout."); +} + +VkImageUsageFlags +vk_image_layout_to_usage_flags(VkImageLayout layout, + VkImageAspectFlagBits aspect) +{ + assert(util_bitcount(aspect) == 1); + + switch (layout) { + case VK_IMAGE_LAYOUT_UNDEFINED: + case VK_IMAGE_LAYOUT_PREINITIALIZED: + return 0u; + + case VK_IMAGE_LAYOUT_GENERAL: + return ~0u; + + case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: + assert(aspect & VK_IMAGE_ASPECT_ANY_COLOR_MASK_MESA); + return VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: + assert(aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | + VK_IMAGE_ASPECT_STENCIL_BIT)); + return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL: + assert(aspect & VK_IMAGE_ASPECT_DEPTH_BIT); + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); + + case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL: + assert(aspect & VK_IMAGE_ASPECT_STENCIL_BIT); + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); + + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + assert(aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | + VK_IMAGE_ASPECT_STENCIL_BIT)); + return VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL: + assert(aspect & VK_IMAGE_ASPECT_DEPTH_BIT); + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); + + case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL: + assert(aspect & VK_IMAGE_ASPECT_STENCIL_BIT); + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); + + case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: + return VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + + case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: + return VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + + case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: + return VK_IMAGE_USAGE_TRANSFER_DST_BIT; + + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: + if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) { + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); + } else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); + } else { + assert(!"Must be a depth/stencil aspect"); + return 0; + } + + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: + if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT) { + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, aspect); + } else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { + return vk_image_layout_to_usage_flags( + VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, aspect); + } else { + assert(!"Must be a depth/stencil aspect"); + return 0; + } + + case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: + assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); + /* This needs to be handled specially by the caller */ + return 0; + + case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: + assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); + return vk_image_layout_to_usage_flags(VK_IMAGE_LAYOUT_GENERAL, aspect); + + case VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV: + assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); + return VK_IMAGE_USAGE_SHADING_RATE_IMAGE_BIT_NV; + + case VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT: + assert(aspect == VK_IMAGE_ASPECT_COLOR_BIT); + return VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT; + + case VK_IMAGE_LAYOUT_MAX_ENUM: + case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR: + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR: + unreachable("Invalid image layout."); + } + + unreachable("Invalid image layout."); +} diff --git a/src/vulkan/util/vk_image.h b/src/vulkan/util/vk_image.h index b28c6e3..9a694b2 100644 --- a/src/vulkan/util/vk_image.h +++ b/src/vulkan/util/vk_image.h @@ -203,6 +203,11 @@ void vk_image_view_destroy(struct vk_device *device, const VkAllocationCallbacks *alloc, struct vk_image_view *image_view); +bool vk_image_layout_is_read_only(VkImageLayout layout, + VkImageAspectFlagBits aspect); +VkImageUsageFlags vk_image_layout_to_usage_flags(VkImageLayout layout, + VkImageAspectFlagBits aspect); + #ifdef __cplusplus } #endif