···11-// Copyright 2019-2020, Collabora, Ltd.
11+// Copyright 2019-2021, Collabora, Ltd.
22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
···2020#include "vk/vk_image_allocator.h"
21212222#include "main/comp_settings.h"
2323+#include "main/comp_swapchain.h"
2324#include "main/comp_window.h"
2425#include "main/comp_renderer.h"
2526#include "main/comp_target.h"
···3940 * Structs
4041 *
4142 */
4242-4343-/*!
4444- * A single swapchain image, holds the needed state for tracking image usage.
4545- *
4646- * @ingroup comp_main
4747- * @see comp_swapchain
4848- */
4949-struct comp_swapchain_image
5050-{
5151- //! Sampler used by the renderer and distortion code.
5252- VkSampler sampler;
5353- VkSampler repeat_sampler;
5454- //! Views used by the renderer and distortion code, for each array
5555- //! layer.
5656- struct
5757- {
5858- VkImageView *alpha;
5959- VkImageView *no_alpha;
6060- } views;
6161- //! The number of array slices in a texture, 1 == regular 2D texture.
6262- size_t array_size;
6363-};
6464-6565-/*!
6666- * A swapchain that is almost a one to one mapping to a OpenXR swapchain.
6767- *
6868- * Not used by the window backend that uses the vk_swapchain to render to.
6969- *
7070- * @ingroup comp_main
7171- * @implements xrt_swapchain_native
7272- * @see comp_compositor
7373- */
7474-struct comp_swapchain
7575-{
7676- struct xrt_swapchain_native base;
7777-7878- struct comp_compositor *c;
7979-8080- struct vk_image_collection vkic;
8181- struct comp_swapchain_image images[XRT_MAX_SWAPCHAIN_IMAGES];
8282-8383- /*!
8484- * This fifo is used to always give out the oldest image to acquire
8585- * image, this should probably be made even smarter.
8686- */
8787- struct u_index_fifo fifo;
8888-};
89439044/*!
9145 * A single layer.
···221175 struct comp_frame rendering;
222176 } frame;
223177224224- struct
225225- {
226226- //! Thread object for safely destroying swapchain.
227227- struct u_threading_stack destroy_swapchains;
228228- } threading;
229229-178178+ struct comp_swapchain_gc cscgc;
230179231180 struct
232181 {
···251200comp_is_format_supported(struct comp_compositor *c, VkFormat format);
252201253202/*!
254254- * Convenience function to convert a xrt_swapchain to a comp_swapchain.
255255- *
256256- * @private @memberof comp_swapchain
257257- */
258258-static inline struct comp_swapchain *
259259-comp_swapchain(struct xrt_swapchain *xsc)
260260-{
261261- return (struct comp_swapchain *)xsc;
262262-}
263263-264264-/*!
265203 * Convenience function to convert a xrt_compositor to a comp_compositor.
266204 *
267205 * @private @memberof comp_compositor
···271209{
272210 return (struct comp_compositor *)xc;
273211}
274274-275275-/*!
276276- * Do garbage collection, destroying any resources that has been scheduled for
277277- * destruction from other threads.
278278- *
279279- * @public @memberof comp_compositor
280280- */
281281-void
282282-comp_compositor_garbage_collect(struct comp_compositor *c);
283283-284284-/*!
285285- * A compositor function that is implemented in the swapchain code.
286286- *
287287- * @public @memberof comp_compositor
288288- */
289289-xrt_result_t
290290-comp_swapchain_create(struct xrt_compositor *xc,
291291- const struct xrt_swapchain_create_info *info,
292292- struct xrt_swapchain **out_xsc);
293293-294294-/*!
295295- * A compositor function that is implemented in the swapchain code.
296296- *
297297- * @public @memberof comp_compositor
298298- */
299299-xrt_result_t
300300-comp_swapchain_import(struct xrt_compositor *xc,
301301- const struct xrt_swapchain_create_info *info,
302302- struct xrt_image_native *native_images,
303303- uint32_t num_images,
304304- struct xrt_swapchain **out_xsc);
305305-306306-/*!
307307- * Swapchain destruct is delayed until it is safe to destroy them, this function
308308- * does the actual destruction and is called from @ref
309309- * comp_compositor_garbage_collect.
310310- *
311311- * @private @memberof comp_swapchain
312312- */
313313-void
314314-comp_swapchain_really_destroy(struct comp_swapchain *sc);
315212316213/*!
317214 * For importing fences, defined in comp_sync.c .
···11+// Copyright 2019-2021, Collabora, Ltd.
22+// SPDX-License-Identifier: BSL-1.0
33+/*!
44+ * @file
55+ * @brief Independent swapchain implementation.
66+ * @author Jakob Bornecrantz <jakob@collabora.com>
77+ * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
88+ * @ingroup comp_main
99+ */
1010+1111+#pragma once
1212+1313+#include "vk/vk_image_allocator.h"
1414+1515+#include "util/u_threading.h"
1616+#include "util/u_index_fifo.h"
1717+1818+1919+#ifdef __cplusplus
2020+extern "C" {
2121+#endif
2222+2323+2424+/*!
2525+ * A garbage collector that collects swapchains to be safely destroyed.
2626+ */
2727+struct comp_swapchain_gc
2828+{
2929+ //! Thread object for safely destroying swapchain.
3030+ struct u_threading_stack destroy_swapchains;
3131+};
3232+3333+/*!
3434+ * A single swapchain image, holds the needed state for tracking image usage.
3535+ *
3636+ * @ingroup comp_main
3737+ * @see comp_swapchain
3838+ */
3939+struct comp_swapchain_image
4040+{
4141+ //! Sampler used by the renderer and distortion code.
4242+ VkSampler sampler;
4343+ VkSampler repeat_sampler;
4444+ //! Views used by the renderer and distortion code, for each array layer.
4545+ struct
4646+ {
4747+ VkImageView *alpha;
4848+ VkImageView *no_alpha;
4949+ } views;
5050+ //! The number of array slices in a texture, 1 == regular 2D texture.
5151+ size_t array_size;
5252+};
5353+5454+/*!
5555+ * A swapchain that is almost a one to one mapping to a OpenXR swapchain.
5656+ *
5757+ * Not used by the window backend that uses the comp_target to render to.
5858+ *
5959+ * The vk_bundle is owned by the compositor, its the state trackers job to make
6060+ * sure that compositor lives for as long as the swapchain does and that all
6161+ * swapchains are destroyed before the compositor is destroyed.
6262+ *
6363+ * @ingroup comp_main
6464+ * @implements xrt_swapchain_native
6565+ * @see comp_compositor
6666+ */
6767+struct comp_swapchain
6868+{
6969+ struct xrt_swapchain_native base;
7070+7171+ struct vk_bundle *vk;
7272+ struct comp_swapchain_gc *gc;
7373+7474+ struct vk_image_collection vkic;
7575+ struct comp_swapchain_image images[XRT_MAX_SWAPCHAIN_IMAGES];
7676+7777+ /*!
7878+ * This fifo is used to always give out the oldest image to acquire
7979+ * image, this should probably be made even smarter.
8080+ */
8181+ struct u_index_fifo fifo;
8282+};
8383+8484+8585+/*
8686+ *
8787+ * Helper functions.
8888+ *
8989+ */
9090+9191+/*!
9292+ * Convenience function to convert a xrt_swapchain to a comp_swapchain.
9393+ *
9494+ * @private @memberof comp_swapchain
9595+ */
9696+static inline struct comp_swapchain *
9797+comp_swapchain(struct xrt_swapchain *xsc)
9898+{
9999+ return (struct comp_swapchain *)xsc;
100100+}
101101+102102+103103+/*
104104+ *
105105+ * 'Exported' functions.
106106+ *
107107+ */
108108+109109+/*!
110110+ * Do garbage collection, destroying any resources that has been scheduled for
111111+ * destruction from other threads.
112112+ *
113113+ * @public @memberof comp_compositor
114114+ */
115115+void
116116+comp_swapchain_garbage_collect(struct comp_swapchain_gc *cscgc);
117117+118118+/*!
119119+ * A compositor function that is implemented in the swapchain code.
120120+ *
121121+ * @public @memberof comp_compositor
122122+ */
123123+xrt_result_t
124124+comp_swapchain_create(struct vk_bundle *vk,
125125+ struct comp_swapchain_gc *cscgc,
126126+ const struct xrt_swapchain_create_info *info,
127127+ struct xrt_swapchain **out_xsc);
128128+129129+/*!
130130+ * A compositor function that is implemented in the swapchain code.
131131+ *
132132+ * @public @memberof comp_compositor
133133+ */
134134+xrt_result_t
135135+comp_swapchain_import(struct vk_bundle *vk,
136136+ struct comp_swapchain_gc *cscgc,
137137+ const struct xrt_swapchain_create_info *info,
138138+ struct xrt_image_native *native_images,
139139+ uint32_t num_images,
140140+ struct xrt_swapchain **out_xsc);
141141+142142+/*!
143143+ * Swapchain destruct is delayed until it is safe to destroy them, this function
144144+ * does the actual destruction and is called from @ref
145145+ * comp_swapchain_garbage_collect.
146146+ *
147147+ * @private @memberof comp_swapchain
148148+ */
149149+void
150150+comp_swapchain_really_destroy(struct comp_swapchain *sc);
151151+152152+153153+#ifdef __cplusplus
154154+}
155155+#endif