summaryrefslogtreecommitdiff
path: root/vulkan/libvulkan/swapchain.cpp
diff options
context:
space:
mode:
author Tom Murphy <tomnom@google.com> 2024-08-30 22:51:47 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-08-30 22:51:47 +0000
commit16f184b3e52f91ee09cdc981a33dd600ac4a69db (patch)
treedf8e73ce2f9baab757465648b759835f2ee213b0 /vulkan/libvulkan/swapchain.cpp
parent48604fb057c83150a9f21af81eb970cf9ed70af7 (diff)
parentea32184c013e10610a74c9d2a1727ea77ac1bada (diff)
Merge "Implement the VK_KHR_swapchain_mutable_format device extension in the vulkan loader" into main
Diffstat (limited to 'vulkan/libvulkan/swapchain.cpp')
-rw-r--r--vulkan/libvulkan/swapchain.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index ba2b8887bc..09b0a145af 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -1472,6 +1472,12 @@ static VkResult getProducerUsage(const VkDevice& device,
.flags = create_protected_swapchain ? VK_IMAGE_CREATE_PROTECTED_BIT : 0u,
};
+ // If supporting mutable format swapchain add the mutable format flag
+ if (create_info->flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) {
+ image_format_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
+ image_format_info.flags |= VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR;
+ }
+
VkAndroidHardwareBufferUsageANDROID ahb_usage;
ahb_usage.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID;
ahb_usage.pNext = nullptr;
@@ -1890,6 +1896,11 @@ VkResult CreateSwapchainKHR(VkDevice device,
num_images = 1;
}
+ VkImageFormatListCreateInfo extra_mutable_formats = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR,
+ };
+ VkImageFormatListCreateInfo* extra_mutable_formats_ptr;
+
// Look through the create_info pNext chain passed to createSwapchainKHR
// for an image compression control struct.
// if one is found AND the appropriate extensions are enabled, create a
@@ -1908,7 +1919,29 @@ VkResult CreateSwapchainKHR(VkDevice device,
image_compression.pNext = nullptr;
usage_info_pNext = &image_compression;
} break;
-
+ case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO: {
+ const VkImageFormatListCreateInfo* format_list =
+ reinterpret_cast<const VkImageFormatListCreateInfo*>(
+ create_infos);
+ if (create_info->flags &
+ VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) {
+ if (format_list && format_list->viewFormatCount > 0 &&
+ format_list->pViewFormats) {
+ extra_mutable_formats.viewFormatCount =
+ format_list->viewFormatCount;
+ extra_mutable_formats.pViewFormats =
+ format_list->pViewFormats;
+ extra_mutable_formats_ptr = &extra_mutable_formats;
+ } else {
+ ALOGE(
+ "vk_swapchain_create_mutable_format_bit_khr was "
+ "set during swapchain creation but no valid "
+ "vkimageformatlistcreateinfo was found in the "
+ "pnext chain");
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+ }
+ } break;
default:
// Ignore all other info structs
break;
@@ -2004,6 +2037,11 @@ VkResult CreateSwapchainKHR(VkDevice device,
.pQueueFamilyIndices = create_info->pQueueFamilyIndices,
};
+ if (create_info->flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) {
+ image_create.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
+ image_create.flags |= VK_IMAGE_CREATE_EXTENDED_USAGE_BIT_KHR;
+ }
+
// Note: don't do deferred allocation for shared present modes. There's only one buffer
// involved so very little benefit.
if ((create_info->flags & VK_SWAPCHAIN_CREATE_DEFERRED_MEMORY_ALLOCATION_BIT_EXT) &&
@@ -2013,7 +2051,7 @@ VkResult CreateSwapchainKHR(VkDevice device,
// AcquireNextImage.
VkImageSwapchainCreateInfoKHR image_swapchain_create = {
.sType = VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR,
- .pNext = nullptr,
+ .pNext = extra_mutable_formats_ptr,
.swapchain = HandleFromSwapchain(swapchain),
};
image_create.pNext = &image_swapchain_create;
@@ -2065,6 +2103,11 @@ VkResult CreateSwapchainKHR(VkDevice device,
ANativeWindowBuffer_getHardwareBuffer(img.buffer.get());
image_create.pNext = &image_native_buffer;
+ if (extra_mutable_formats_ptr) {
+ extra_mutable_formats_ptr->pNext = image_create.pNext;
+ image_create.pNext = extra_mutable_formats_ptr;
+ }
+
ATRACE_BEGIN("CreateImage");
result =
dispatch.CreateImage(device, &image_create, nullptr, &img.image);