diff options
author | zccrs <zccrs@live.com> | 2022-05-23 21:54:36 +0800 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-08 12:56:38 +0100 |
commit | 270914d379bd24aed1f5be219fa3469cc57d9d36 (patch) | |
tree | 41738cff99e7fbbfedf6c832a612bfc24da5bbb6 /render/vulkan | |
parent | 9fefeb69d6fc1136cfad7d690e1d7385c058fd72 (diff) |
render/vulkan: add some interfaces to allow compositors to integrate
Added wlr_vk_renderer_get_* functions to allow get the VkInstance,
VkPhysicalDevice, VkDevice, queue family of a wlr_vk_renderer.
Added wlr_vk_renderer_get_current_image_attribs function to allow get
the VkImage of current renderer buffer to use on compositors.
Added wlr_renderer_is_vk function, it's like the wlr_renderer_is_gles2,
returns true if the wlr_renderer is a wlr_vk_renderer.
Added wlr_vk_image_get_attribs function to get a VkImage and it's
extras information (e.g. a VkImageLayout and VkImageFormat of the
VkImage) from a wlr_texture.
Diffstat (limited to 'render/vulkan')
-rw-r--r-- | render/vulkan/renderer.c | 38 | ||||
-rw-r--r-- | render/vulkan/texture.c | 13 |
2 files changed, 47 insertions, 4 deletions
diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index 8bf01b1d..e620b42e 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -42,8 +42,12 @@ static bool default_debug = true; static const struct wlr_renderer_impl renderer_impl; +bool wlr_renderer_is_vk(struct wlr_renderer *wlr_renderer) { + return wlr_renderer->impl == &renderer_impl; +} + struct wlr_vk_renderer *vulkan_get_renderer(struct wlr_renderer *wlr_renderer) { - assert(wlr_renderer->impl == &renderer_impl); + assert(wlr_renderer_is_vk(wlr_renderer)); return (struct wlr_vk_renderer *)wlr_renderer; } @@ -1817,3 +1821,35 @@ struct wlr_renderer *wlr_vk_renderer_create_with_drm_fd(int drm_fd) { return vulkan_renderer_create_for_device(dev); } + +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; +} + +VkPhysicalDevice wlr_vk_renderer_get_physical_device(struct wlr_renderer *renderer) +{ + struct wlr_vk_renderer *vk_renderer = vulkan_get_renderer(renderer); + return vk_renderer->dev->phdev; +} + +VkDevice wlr_vk_renderer_get_device(struct wlr_renderer *renderer) +{ + struct wlr_vk_renderer *vk_renderer = vulkan_get_renderer(renderer); + return vk_renderer->dev->dev; +} + +uint32_t wlr_vk_renderer_get_queue_family(struct wlr_renderer *renderer) +{ + struct wlr_vk_renderer *vk_renderer = vulkan_get_renderer(renderer); + return vk_renderer->dev->queue_family; +} + +void wlr_vk_renderer_get_current_image_attribs(struct wlr_renderer *renderer, + struct wlr_vk_image_attribs *attribs) { + struct wlr_vk_renderer *vk_renderer = vulkan_get_renderer(renderer); + attribs->image = vk_renderer->current_render_buffer->image; + attribs->format = vk_renderer->current_render_buffer->render_setup->render_format; + attribs->layout = VK_IMAGE_LAYOUT_UNDEFINED; +} diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 3eaab3ae..5776233c 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -283,8 +283,6 @@ static struct wlr_texture *vulkan_texture_from_pixels( .usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, }; - VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - res = vkCreateImage(dev, &img_info, NULL, &texture->image); if (res != VK_SUCCESS) { wlr_vk_error("vkCreateImage failed", res); @@ -362,7 +360,7 @@ static struct wlr_texture *vulkan_texture_from_pixels( VkDescriptorImageInfo ds_img_info = { .imageView = texture->image_view, - .imageLayout = layout, + .imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, }; VkWriteDescriptorSet ds_write = { @@ -771,3 +769,12 @@ struct wlr_texture *vulkan_texture_from_buffer(struct wlr_renderer *wlr_renderer return NULL; } } + +void wlr_vk_texture_get_image_attribs(struct wlr_texture *texture, + struct wlr_vk_image_attribs *attribs) { + struct wlr_vk_texture *vk_texture = vulkan_get_texture(texture); + attribs->image = vk_texture->image; + attribs->format = vk_texture->format->vk_format; + attribs->layout = vk_texture->transitioned ? + VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL : VK_IMAGE_LAYOUT_UNDEFINED; +} |