Monado OpenXR Runtime
comp_vk_swapchain.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Vulkan swapchain code header.
6  * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
7  * @author Jakob Bornecrantz <jakob@collabora.com>
8  * @ingroup comp_main
9  */
10 
11 #pragma once
12 
13 #include "vk/vk_helpers.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 
20 /*
21  *
22  * Structs.
23  *
24  */
25 
26 /*!
27  * Callback when a @ref vk_swapchain changes size.
28  *
29  * @ingroup comp_main
30  */
31 typedef void (*vk_swapchain_cb)(uint32_t width, uint32_t height, void *priv);
32 
33 /*!
34  * A pair of VkImage and VkImageView.
35  *
36  * @ingroup comp_main
37  */
39 {
40  VkImage image;
41  VkImageView view;
42 };
43 
44 /*!
45  * Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by @ref comp code.
46  *
47  * @ingroup comp_main
48  */
50 {
51  struct vk_bundle *vk;
52 
53  VkSwapchainKHR swap_chain;
54 
55  VkSurfaceKHR surface;
56  VkSurfaceFormatKHR surface_format;
57 
58  struct vk_swapchain_buffer *buffers;
59  uint32_t image_count;
60 
61  VkFormat color_format;
62  VkColorSpaceKHR color_space;
63  VkPresentModeKHR present_mode;
64 
65  void *cb_priv;
66  vk_swapchain_cb dimension_cb;
67 };
68 
69 
70 /*
71  *
72  * Functions.
73  *
74  */
75 
76 /*!
77  * Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by @ref comp code.
78  *
79  * @ingroup comp_main
80  */
81 void
83  struct vk_bundle *vk,
84  vk_swapchain_cb dimension_cb,
85  void *priv);
86 
87 /*!
88  * Initialize the given @ref vk_swapchain, does not allocate.
89  *
90  * @ingroup comp_main
91  */
92 void
94  uint32_t width,
95  uint32_t height,
96  VkFormat color_format,
97  VkColorSpaceKHR color_space,
98  VkPresentModeKHR present_mode);
99 
100 /*!
101  * Acquire a image index from the given @ref vk_swapchain for rendering.
102  *
103  * @ingroup comp_main
104  */
105 VkResult
107  VkSemaphore semaphore,
108  uint32_t *index);
109 
110 /*!
111  * Make the given @ref vk_swapchain present the next acquired image.
112  *
113  * @ingroup comp_main
114  */
115 VkResult
117  VkQueue queue,
118  uint32_t index,
119  VkSemaphore semaphore);
120 
121 /*!
122  * Free all managed resources on the given @ref vk_swapchain,
123  * does not free the struct itself.
124  *
125  * @ingroup comp_main
126  */
127 void
129 
130 
131 #ifdef __cplusplus
132 }
133 #endif
A pair of VkImage and VkImageView.
Definition: comp_vk_swapchain.h:38
void vk_swapchain_init(struct vk_swapchain *sc, struct vk_bundle *vk, vk_swapchain_cb dimension_cb, void *priv)
Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code.
Definition: comp_vk_swapchain.c:79
Wraps and manage VkSwapchainKHR and VkSurfaceKHR, used by Compositor code.
Definition: comp_vk_swapchain.h:49
void vk_swapchain_cleanup(struct vk_swapchain *sc)
Free all managed resources on the given vk_swapchain, does not free the struct itself.
Definition: comp_vk_swapchain.c:466
VkResult vk_swapchain_present(struct vk_swapchain *sc, VkQueue queue, uint32_t index, VkSemaphore semaphore)
Make the given vk_swapchain present the next acquired image.
Definition: comp_vk_swapchain.c:245
VkResult vk_swapchain_acquire_next_image(struct vk_swapchain *sc, VkSemaphore semaphore, uint32_t *index)
Acquire a image index from the given vk_swapchain for rendering.
Definition: comp_vk_swapchain.c:235
Common Vulkan code header.
void(* vk_swapchain_cb)(uint32_t width, uint32_t height, void *priv)
Callback when a vk_swapchain changes size.
Definition: comp_vk_swapchain.h:31
void vk_swapchain_create(struct vk_swapchain *sc, uint32_t width, uint32_t height, VkFormat color_format, VkColorSpaceKHR color_space, VkPresentModeKHR present_mode)
Initialize the given vk_swapchain, does not allocate.
Definition: comp_vk_swapchain.c:90
A bundle of Vulkan functions and objects, used by both Compositor and Compositor client code...
Definition: vk_helpers.h:34