From 88a4b9eefd5b3f97dcf4da406b9f5dc17988a639 Mon Sep 17 00:00:00 2001 From: Manuel Stoeckl Date: Sat, 21 Oct 2023 21:35:28 -0400 Subject: render/vulkan: create VkImage with option for _SRGB view, if possible --- render/vulkan/texture.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'render') diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 036d5f73..a4e53760 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -411,6 +411,15 @@ static struct wlr_texture *vulkan_texture_from_pixels( texture_set_format(texture, &fmt->format); + VkFormat view_formats[2] = { + fmt->format.vk, + fmt->format.vk_srgb, + }; + VkImageFormatListCreateInfoKHR list_info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, + .pViewFormats = view_formats, + .viewFormatCount = 2, + }; VkImageCreateInfo img_info = { .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, .imageType = VK_IMAGE_TYPE_2D, @@ -423,7 +432,11 @@ static struct wlr_texture *vulkan_texture_from_pixels( .extent = (VkExtent3D) { width, height, 1 }, .tiling = VK_IMAGE_TILING_OPTIMAL, .usage = vulkan_shm_tex_usage, + .pNext = fmt->shm.has_mutable_srgb ? &list_info : NULL, }; + if (fmt->shm.has_mutable_srgb) { + img_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + } res = vkCreateImage(dev, &img_info, NULL, &texture->image); if (res != VK_SUCCESS) { @@ -571,6 +584,9 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, if (disjoint) { img_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT; } + if (mod->has_mutable_srgb) { + img_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; + } VkExternalMemoryImageCreateInfo eimg = { .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO, @@ -595,6 +611,19 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, }; eimg.pNext = &mod_info; + VkFormat view_formats[2] = { + fmt->format.vk, + fmt->format.vk_srgb, + }; + VkImageFormatListCreateInfoKHR list_info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, + .pViewFormats = view_formats, + .viewFormatCount = 2, + }; + if (mod->has_mutable_srgb) { + mod_info.pNext = &list_info; + } + VkImage image; res = vkCreateImage(dev, &img_info, NULL, &image); if (res != VK_SUCCESS) { -- cgit v1.2.3