The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/main: Refactor fence to be more independent

+69 -35
+11 -1
src/xrt/compositor/main/comp_compositor.c
··· 125 125 } 126 126 127 127 static xrt_result_t 128 + compositor_import_fence(struct xrt_compositor *xc, 129 + xrt_graphics_sync_handle_t handle, 130 + struct xrt_compositor_fence **out_xcf) 131 + { 132 + struct comp_compositor *c = comp_compositor(xc); 133 + 134 + return comp_fence_import(&c->vk, handle, out_xcf); 135 + } 136 + 137 + static xrt_result_t 128 138 compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type type) 129 139 { 130 140 struct comp_compositor *c = comp_compositor(xc); ··· 1425 1435 1426 1436 c->base.base.create_swapchain = compositor_swapchain_create; 1427 1437 c->base.base.import_swapchain = compositor_swapchain_import; 1428 - c->base.base.import_fence = comp_compositor_import_fence; 1438 + c->base.base.import_fence = compositor_import_fence; 1429 1439 c->base.base.begin_session = compositor_begin_session; 1430 1440 c->base.base.end_session = compositor_end_session; 1431 1441 c->base.base.predict_frame = compositor_predict_frame;
+1 -8
src/xrt/compositor/main/comp_compositor.h
··· 19 19 20 20 #include "vk/vk_image_allocator.h" 21 21 22 + #include "main/comp_sync.h" 22 23 #include "main/comp_settings.h" 23 24 #include "main/comp_swapchain.h" 24 25 #include "main/comp_window.h" ··· 209 210 { 210 211 return (struct comp_compositor *)xc; 211 212 } 212 - 213 - /*! 214 - * For importing fences, defined in comp_sync.c . 215 - */ 216 - xrt_result_t 217 - comp_compositor_import_fence(struct xrt_compositor *xc, 218 - xrt_graphics_sync_handle_t handle, 219 - struct xrt_compositor_fence **out_xcf); 220 213 221 214 /*! 222 215 * Spew level logging.
+22 -26
src/xrt/compositor/main/comp_sync.c
··· 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file 5 - * @brief Sync code for the main compositor. 5 + * @brief Independent @ref xrt_compositor_fence implementation. 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 7 * @ingroup comp_main 8 8 */ 9 9 10 - #include "util/u_misc.h" 11 - #include "util/u_handles.h" 10 + #include "xrt/xrt_config_os.h" 12 11 13 - #include "main/comp_compositor.h" 12 + #include "main/comp_sync.h" 14 13 15 - #include <xrt/xrt_handles.h> 16 - #include <xrt/xrt_config_os.h> 14 + #include "util/u_misc.h" 15 + #include "util/u_handles.h" 16 + #include "util/u_trace_marker.h" 17 17 18 18 #include <stdio.h> 19 19 #include <stdlib.h> ··· 23 23 #endif 24 24 25 25 26 + /* 27 + * 28 + * Structs. 29 + * 30 + */ 26 31 32 + /*! 33 + * A very simple implementation of a fence primitive. 34 + */ 27 35 struct fence 28 36 { 29 37 struct xrt_compositor_fence base; 30 - struct comp_compositor *c; 38 + 39 + struct vk_bundle *vk; 31 40 32 41 VkFence fence; 33 42 }; ··· 35 44 36 45 /* 37 46 * 38 - * Helper functions. 39 - * 40 - */ 41 - 42 - 43 - 44 - /* 45 - * 46 47 * Fence member functions. 47 48 * 48 49 */ ··· 53 54 COMP_TRACE_MARKER(); 54 55 55 56 struct fence *f = (struct fence *)xcf; 56 - struct vk_bundle *vk = &f->c->vk; 57 + struct vk_bundle *vk = f->vk; 57 58 58 59 // Count no handle as signled fence. 59 60 if (f->fence == VK_NULL_HANDLE) { ··· 65 66 return XRT_SUCCESS; 66 67 } 67 68 if (ret != VK_SUCCESS) { 68 - COMP_ERROR(f->c, "vkWaitForFences: %s", vk_result_string(ret)); 69 + VK_ERROR(vk, "vkWaitForFences: %s", vk_result_string(ret)); 69 70 return XRT_ERROR_VULKAN; 70 71 } 71 72 ··· 78 79 COMP_TRACE_MARKER(); 79 80 80 81 struct fence *f = (struct fence *)xcf; 81 - struct vk_bundle *vk = &f->c->vk; 82 + struct vk_bundle *vk = f->vk; 82 83 83 84 if (f->fence != VK_NULL_HANDLE) { 84 85 vk->vkDestroyFence(vk->device, f->fence, NULL); ··· 91 92 92 93 /* 93 94 * 94 - * Compositor function. 95 + * 'Exported' function. 95 96 * 96 97 */ 97 98 98 99 xrt_result_t 99 - comp_compositor_import_fence(struct xrt_compositor *xc, 100 - xrt_graphics_sync_handle_t handle, 101 - struct xrt_compositor_fence **out_xcf) 100 + comp_fence_import(struct vk_bundle *vk, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf) 102 101 { 103 102 COMP_TRACE_MARKER(); 104 - 105 - struct comp_compositor *c = comp_compositor(xc); 106 - struct vk_bundle *vk = &c->vk; 107 103 108 104 VkFence fence = VK_NULL_HANDLE; 109 105 ··· 116 112 f->base.wait = fence_wait; 117 113 f->base.destroy = fence_destroy; 118 114 f->fence = fence; 119 - f->c = c; 115 + f->vk = vk; 120 116 121 117 *out_xcf = &f->base; 122 118
+35
src/xrt/compositor/main/comp_sync.h
··· 1 + // Copyright 2019-2021, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Independent @ref xrt_compositor_fence implementation. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup comp_main 8 + */ 9 + 10 + #pragma once 11 + 12 + #include "xrt/xrt_handles.h" 13 + #include "xrt/xrt_compositor.h" 14 + #include "vk/vk_helpers.h" 15 + 16 + 17 + #ifdef __cplusplus 18 + extern "C" { 19 + #endif 20 + 21 + 22 + /*! 23 + * For importing @ref xrt_graphics_sync_handle_t and turn them into a @ref xrt_compositor_fence. 24 + * 25 + * The vk_bundle is owned by the compositor, its the state trackers job to make 26 + * sure that compositor lives for as long as the fence does and that all fences 27 + * are destroyed before the compositor is destroyed. 28 + */ 29 + xrt_result_t 30 + comp_fence_import(struct vk_bundle *vk, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf); 31 + 32 + 33 + #ifdef __cplusplus 34 + } 35 + #endif