diff options
author | Manuel Stoeckl <code@mstoeckl.com> | 2023-10-21 21:35:28 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-12-04 15:13:31 +0000 |
commit | 88a4b9eefd5b3f97dcf4da406b9f5dc17988a639 (patch) | |
tree | ef8a96c67172a2c2f53553680d6977b3c27e4cbb /render | |
parent | fd4548bb93af7e26f52a9ca266da3af78b17bf93 (diff) |
render/vulkan: create VkImage with option for _SRGB view, if possible
Diffstat (limited to 'render')
-rw-r--r-- | render/vulkan/texture.c | 29 |
1 files changed, 29 insertions, 0 deletions
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) { |