The open source OpenXR runtime

c/main: Refactor frame handling a bit

+73 -9
+2 -1
src/xrt/compositor/main/comp_compositor.c
··· 59 59 60 60 #include "util/comp_vulkan.h" 61 61 #include "main/comp_compositor.h" 62 + #include "main/comp_frame.h" 62 63 63 64 #ifdef XRT_FEATURE_WINDOW_PEEK 64 65 #include "main/comp_window_peek.h" ··· 185 186 186 187 comp_target_update_timings(c->target); 187 188 188 - assert(c->frame.waited.id == -1); 189 + assert(comp_frame_is_invalid_locked(&c->frame.waited)); 189 190 190 191 int64_t frame_id = -1; 191 192 uint64_t wake_up_time_ns = 0;
+57
src/xrt/compositor/main/comp_frame.h
··· 1 + // Copyright 2022-2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Small helper functions to manage frames. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup comp_main 8 + */ 9 + 10 + #pragma once 11 + 12 + #include "main/comp_compositor.h" 13 + 14 + 15 + /*! 16 + * Is this frame invalid. 17 + */ 18 + static inline bool 19 + comp_frame_is_invalid_locked(struct comp_frame *f) 20 + { 21 + return f->id == -1; 22 + } 23 + 24 + /*! 25 + * Clear a slot, need to be externally synchronized. 26 + */ 27 + static inline void 28 + comp_frame_clear_locked(struct comp_frame *slot) 29 + { 30 + U_ZERO(slot); 31 + slot->id = -1; 32 + } 33 + 34 + /*! 35 + * Move a frame into a cleared frame, need to be externally synchronized. 36 + */ 37 + static inline void 38 + comp_frame_move_into_cleared(struct comp_frame *dst, struct comp_frame *src) 39 + { 40 + assert(comp_frame_is_invalid_locked(dst)); 41 + 42 + // Copy data. 43 + *dst = *src; 44 + 45 + U_ZERO(src); 46 + src->id = -1; 47 + } 48 + 49 + /*! 50 + * Move a frame, clear src, need to be externally synchronized. 51 + */ 52 + static inline void 53 + comp_frame_move_and_clear_locked(struct comp_frame *dst, struct comp_frame *src) 54 + { 55 + comp_frame_clear_locked(dst); 56 + comp_frame_move_into_cleared(dst, src); 57 + }
+14 -8
src/xrt/compositor/main/comp_renderer.c
··· 29 29 #include "util/u_frame_times_widget.h" 30 30 31 31 #include "main/comp_layer_renderer.h" 32 + #include "main/comp_frame.h" 32 33 33 34 #ifdef XRT_FEATURE_WINDOW_PEEK 34 35 #include "main/comp_window_peek.h" ··· 666 667 const void *next = NULL; 667 668 668 669 #ifdef VK_KHR_timeline_semaphore 669 - assert(r->c->frame.rendering.id >= 0); 670 + assert(!comp_frame_is_invalid_locked(&r->c->frame.rendering)); 670 671 uint64_t render_complete_signal_values[WAIT_SEMAPHORE_COUNT] = {(uint64_t)r->c->frame.rendering.id}; 671 672 672 673 VkTimelineSemaphoreSubmitInfoKHR timeline_info = { ··· 814 815 815 816 VkResult ret; 816 817 817 - assert(r->c->frame.rendering.id >= 0); 818 + assert(!comp_frame_is_invalid_locked(&r->c->frame.rendering)); 818 819 uint64_t render_complete_signal_value = (uint64_t)r->c->frame.rendering.id; 819 820 820 821 ret = comp_target_present( // ··· 1960 1961 struct comp_target *ct = r->c->target; 1961 1962 struct comp_compositor *c = r->c; 1962 1963 1964 + // Check that we don't have any bad data. 1965 + assert(!comp_frame_is_invalid_locked(&c->frame.waited)); 1966 + assert(comp_frame_is_invalid_locked(&c->frame.rendering)); 1963 1967 1964 - assert(c->frame.rendering.id == -1); 1968 + // Move waited frame to rendering frame, clear waited. 1969 + comp_frame_move_and_clear_locked(&c->frame.rendering, &c->frame.waited); 1965 1970 1966 - c->frame.rendering = c->frame.waited; 1967 - c->frame.waited.id = -1; 1968 - 1971 + // Tell the target we are starting to render, for frame timing. 1969 1972 comp_target_mark_begin(ct, c->frame.rendering.id, os_monotonic_get_ns()); 1970 1973 1971 1974 // Are we ready to render? No - skip rendering. ··· 1973 1976 // Need to emulate rendering for the timing. 1974 1977 //! @todo This should be discard. 1975 1978 comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns()); 1979 + 1980 + // Clear the rendering frame. 1981 + comp_frame_clear_locked(&c->frame.rendering); 1976 1982 return; 1977 1983 } 1978 1984 ··· 2022 2028 // Save for timestamps below. 2023 2029 uint64_t frame_id = c->frame.rendering.id; 2024 2030 2025 - // Clear the frame. 2026 - c->frame.rendering.id = -1; 2031 + // Clear the rendered frame. 2032 + comp_frame_clear_locked(&c->frame.rendering); 2027 2033 2028 2034 mirror_to_debug_gui_fixup_ui_state(r); 2029 2035 if (can_mirror_to_debug_gui(r)) {