diff options
author | zccrs <zccrs@live.com> | 2022-11-09 17:57:56 +0800 |
---|---|---|
committer | zccrs <zccrs@live.com> | 2022-11-15 10:58:45 +0800 |
commit | 5b34fe55136cca32c10e70e5fe44fea2d7c6520d (patch) | |
tree | 747c6eba917645912cf11dfb541bfcb4cff3c1b4 | |
parent | 65836ce357e4140d4e5250228a05ddd96119a883 (diff) |
render/vulkan: add wlr_vk_texture_has_alpha
Allow to get whether has alpha channel of the VkImage, it can help an
optimization to disable blending when the texture doesn't have alpha.
Because the VkFormat isn't enough because it's always set to
VK_FORMAT_B8G8R8A8_SRGB or VK_FORMAT_R8G8B8A8_SRGB.
-rw-r--r-- | include/render/vulkan.h | 1 | ||||
-rw-r--r-- | include/wlr/render/vulkan.h | 1 | ||||
-rw-r--r-- | render/vulkan/texture.c | 11 |
3 files changed, 11 insertions, 2 deletions
diff --git a/include/render/vulkan.h b/include/render/vulkan.h index 716c5ace..5dfc3d37 100644 --- a/include/render/vulkan.h +++ b/include/render/vulkan.h @@ -253,6 +253,7 @@ struct wlr_vk_texture { bool dmabuf_imported; bool owned; // if dmabuf_imported: whether we have ownership of the image bool transitioned; // if dma_imported: whether we transitioned it away from preinit + bool has_alpha; // whether the image is has alpha channel struct wl_list foreign_link; // wlr_vk_renderer.foreign_textures struct wl_list destroy_link; // wlr_vk_renderer.destroy_textures struct wl_list link; // wlr_vk_renderer.textures diff --git a/include/wlr/render/vulkan.h b/include/wlr/render/vulkan.h index aec3a3c2..04c877e4 100644 --- a/include/wlr/render/vulkan.h +++ b/include/wlr/render/vulkan.h @@ -32,6 +32,7 @@ bool wlr_texture_is_vk(struct wlr_texture *texture); void wlr_vk_texture_get_image_attribs(struct wlr_texture *texture, struct wlr_vk_image_attribs *attribs); +bool wlr_vk_texture_has_alpha(struct wlr_texture *texture); #endif diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 1f70bc44..6c6e9825 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -322,6 +322,7 @@ static struct wlr_texture *vulkan_texture_from_pixels( const struct wlr_pixel_format_info *format_info = drm_get_pixel_format_info(drm_fmt); assert(format_info); + texture->has_alpha = format_info->has_alpha; // view VkImageViewCreateInfo view_info = { @@ -331,7 +332,7 @@ static struct wlr_texture *vulkan_texture_from_pixels( .components.r = VK_COMPONENT_SWIZZLE_IDENTITY, .components.g = VK_COMPONENT_SWIZZLE_IDENTITY, .components.b = VK_COMPONENT_SWIZZLE_IDENTITY, - .components.a = format_info->has_alpha + .components.a = texture->has_alpha ? VK_COMPONENT_SWIZZLE_IDENTITY : VK_COMPONENT_SWIZZLE_ONE, @@ -656,6 +657,7 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf( const struct wlr_pixel_format_info *format_info = drm_get_pixel_format_info(attribs->format); assert(format_info); + texture->has_alpha = format_info->has_alpha; // view VkImageViewCreateInfo view_info = { @@ -665,7 +667,7 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf( .components.r = VK_COMPONENT_SWIZZLE_IDENTITY, .components.g = VK_COMPONENT_SWIZZLE_IDENTITY, .components.b = VK_COMPONENT_SWIZZLE_IDENTITY, - .components.a = format_info->has_alpha + .components.a = texture->has_alpha ? VK_COMPONENT_SWIZZLE_IDENTITY : VK_COMPONENT_SWIZZLE_ONE, @@ -779,3 +781,8 @@ void wlr_vk_texture_get_image_attribs(struct wlr_texture *texture, attribs->layout = vk_texture->transitioned ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED; } + +bool wlr_vk_texture_has_alpha(struct wlr_texture *texture) { + struct wlr_vk_texture *vk_texture = vulkan_get_texture(texture); + return vk_texture->has_alpha; +} |