mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 09:59:48 +01:00
render/vulkan: add vulkan_get_pipeline_layout()
Will make it easier to add more pipeline layouts for other YCbCr formats.
This commit is contained in:
parent
fd38761676
commit
5ea0eb3468
3 changed files with 32 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue