diff options
author | Simon Ser <contact@emersion.fr> | 2023-05-05 11:54:57 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-05-24 08:58:59 +0000 |
commit | 5ea0eb3468a99a3c33c40c568bfb72b7ec184d21 (patch) | |
tree | 473502aa80e1516edc72e51d123b2be9ba8fc25a | |
parent | fd3876167659c254062df1cafb9303f0280bcd33 (diff) |
render/vulkan: add vulkan_get_pipeline_layout()
Will make it easier to add more pipeline layouts for other YCbCr
formats.
-rw-r--r-- | include/render/vulkan.h | 4 | ||||
-rw-r--r-- | render/vulkan/renderer.c | 20 | ||||
-rw-r--r-- | render/vulkan/texture.c | 14 |
3 files changed, 32 insertions, 6 deletions
diff --git a/include/render/vulkan.h b/include/render/vulkan.h index 34ca8ade..8eab7a9a 100644 --- a/include/render/vulkan.h +++ b/include/render/vulkan.h @@ -297,6 +297,9 @@ struct wlr_vk_format_props *vulkan_format_props_from_drm( struct wlr_vk_device *dev, uint32_t drm_format); struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *r); +struct wlr_vk_pipeline_layout *vulkan_get_pipeline_layout(struct wlr_vk_renderer *renderer, + const struct wlr_vk_format *format); + // State (e.g. image texture) associated with a surface. struct wlr_vk_texture { struct wlr_texture wlr_texture; @@ -306,6 +309,7 @@ struct wlr_vk_texture { VkImage image; VkImageView image_view; const struct wlr_vk_format *format; + struct wlr_vk_pipeline_layout *pipeline_layout; VkDescriptorSet ds; struct wlr_vk_descriptor_pool *ds_pool; struct wlr_vk_command_buffer *last_used_cb; // to track when it can be destroyed diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index 8d7fdb78..00b8d0e2 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -17,6 +17,7 @@ #include <wlr/render/vulkan.h> #include <wlr/backend/interface.h> #include <wlr/types/wlr_linux_dmabuf_v1.h> +#include <xf86drm.h> #include "render/dmabuf.h" #include "render/pixel_format.h" @@ -1405,11 +1406,11 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render wl_list_insert(&renderer->foreign_textures, &texture->foreign_link); } - VkPipelineLayout pipe_layout = renderer->default_pipeline_layout.vk; + VkPipelineLayout pipe_layout = texture->pipeline_layout->vk; + VkPipeline pipe; // SRGB formats already have the transfer function applied if (texture->format->drm == DRM_FORMAT_NV12) { - pipe_layout = renderer->nv12_pipeline_layout.vk; pipe = renderer->current_render_buffer->render_setup->tex_nv12_pipe; } else if (texture->format->is_srgb) { pipe = renderer->current_render_buffer->render_setup->tex_identity_pipe; @@ -2841,6 +2842,21 @@ struct wlr_renderer *wlr_vk_renderer_create_with_drm_fd(int drm_fd) { return vulkan_renderer_create_for_device(dev); } +struct wlr_vk_pipeline_layout *vulkan_get_pipeline_layout(struct wlr_vk_renderer *renderer, + const struct wlr_vk_format *format) { + if (!format->is_ycbcr) { + return &renderer->default_pipeline_layout; + } + if (format->drm == DRM_FORMAT_NV12 && renderer->dev->sampler_ycbcr_conversion) { + return &renderer->nv12_pipeline_layout; + } + char *name = drmGetFormatName(format->drm); + wlr_log(WLR_ERROR, "No pipeline layout found for format %s (0x%08"PRIX32")", + name, format->drm); + free(name); + return NULL; +} + VkInstance wlr_vk_renderer_get_instance(struct wlr_renderer *renderer) { struct wlr_vk_renderer *vk_renderer = vulkan_get_renderer(renderer); return vk_renderer->dev->instance->instance; diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 59a41d35..6a895a42 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -282,6 +282,7 @@ static struct wlr_texture *vulkan_texture_from_pixels( } texture->format = &fmt->format; + texture->pipeline_layout = &renderer->default_pipeline_layout; VkImageCreateInfo img_info = { .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, @@ -662,6 +663,12 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf( } texture->format = &fmt->format; + + texture->pipeline_layout = vulkan_get_pipeline_layout(renderer, texture->format); + if (texture->pipeline_layout == NULL) { + goto error; + } + texture->image = vulkan_import_dmabuf(renderer, attribs, texture->memories, &texture->mem_count, false); if (!texture->image) { @@ -695,13 +702,12 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf( .image = texture->image, }; - VkDescriptorSetLayout ds_layout = renderer->default_pipeline_layout.ds; VkSamplerYcbcrConversionInfo ycbcr_conversion_info; if (fmt->format.is_ycbcr) { - ds_layout = renderer->nv12_pipeline_layout.ds; + assert(texture->pipeline_layout->ycbcr.conversion != VK_NULL_HANDLE); ycbcr_conversion_info = (VkSamplerYcbcrConversionInfo){ .sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, - .conversion = renderer->nv12_pipeline_layout.ycbcr.conversion, + .conversion = texture->pipeline_layout->ycbcr.conversion, }; view_info.pNext = &ycbcr_conversion_info; } @@ -712,7 +718,7 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf( goto error; } - texture->ds_pool = vulkan_alloc_texture_ds(renderer, ds_layout, &texture->ds); + texture->ds_pool = vulkan_alloc_texture_ds(renderer, texture->pipeline_layout->ds, &texture->ds); if (!texture->ds_pool) { wlr_log(WLR_ERROR, "failed to allocate descriptor"); goto error; |