tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
c/main: Refactor frame handling a bit
Jakob Bornecrantz
2 years ago
27fafacf
2a17212d
+73
-9
3 changed files
expand all
collapse all
unified
split
src
xrt
compositor
main
comp_compositor.c
comp_frame.h
comp_renderer.c
+2
-1
src/xrt/compositor/main/comp_compositor.c
···
59
60
#include "util/comp_vulkan.h"
61
#include "main/comp_compositor.h"
0
62
63
#ifdef XRT_FEATURE_WINDOW_PEEK
64
#include "main/comp_window_peek.h"
···
185
186
comp_target_update_timings(c->target);
187
188
-
assert(c->frame.waited.id == -1);
189
190
int64_t frame_id = -1;
191
uint64_t wake_up_time_ns = 0;
···
59
60
#include "util/comp_vulkan.h"
61
#include "main/comp_compositor.h"
62
+
#include "main/comp_frame.h"
63
64
#ifdef XRT_FEATURE_WINDOW_PEEK
65
#include "main/comp_window_peek.h"
···
186
187
comp_target_update_timings(c->target);
188
189
+
assert(comp_frame_is_invalid_locked(&c->frame.waited));
190
191
int64_t frame_id = -1;
192
uint64_t wake_up_time_ns = 0;
+57
src/xrt/compositor/main/comp_frame.h
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
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
#include "util/u_frame_times_widget.h"
30
31
#include "main/comp_layer_renderer.h"
0
32
33
#ifdef XRT_FEATURE_WINDOW_PEEK
34
#include "main/comp_window_peek.h"
···
666
const void *next = NULL;
667
668
#ifdef VK_KHR_timeline_semaphore
669
-
assert(r->c->frame.rendering.id >= 0);
670
uint64_t render_complete_signal_values[WAIT_SEMAPHORE_COUNT] = {(uint64_t)r->c->frame.rendering.id};
671
672
VkTimelineSemaphoreSubmitInfoKHR timeline_info = {
···
814
815
VkResult ret;
816
817
-
assert(r->c->frame.rendering.id >= 0);
818
uint64_t render_complete_signal_value = (uint64_t)r->c->frame.rendering.id;
819
820
ret = comp_target_present( //
···
1960
struct comp_target *ct = r->c->target;
1961
struct comp_compositor *c = r->c;
1962
0
0
0
1963
1964
-
assert(c->frame.rendering.id == -1);
0
1965
1966
-
c->frame.rendering = c->frame.waited;
1967
-
c->frame.waited.id = -1;
1968
-
1969
comp_target_mark_begin(ct, c->frame.rendering.id, os_monotonic_get_ns());
1970
1971
// Are we ready to render? No - skip rendering.
···
1973
// Need to emulate rendering for the timing.
1974
//! @todo This should be discard.
1975
comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns());
0
0
0
1976
return;
1977
}
1978
···
2022
// Save for timestamps below.
2023
uint64_t frame_id = c->frame.rendering.id;
2024
2025
-
// Clear the frame.
2026
-
c->frame.rendering.id = -1;
2027
2028
mirror_to_debug_gui_fixup_ui_state(r);
2029
if (can_mirror_to_debug_gui(r)) {
···
29
#include "util/u_frame_times_widget.h"
30
31
#include "main/comp_layer_renderer.h"
32
+
#include "main/comp_frame.h"
33
34
#ifdef XRT_FEATURE_WINDOW_PEEK
35
#include "main/comp_window_peek.h"
···
667
const void *next = NULL;
668
669
#ifdef VK_KHR_timeline_semaphore
670
+
assert(!comp_frame_is_invalid_locked(&r->c->frame.rendering));
671
uint64_t render_complete_signal_values[WAIT_SEMAPHORE_COUNT] = {(uint64_t)r->c->frame.rendering.id};
672
673
VkTimelineSemaphoreSubmitInfoKHR timeline_info = {
···
815
816
VkResult ret;
817
818
+
assert(!comp_frame_is_invalid_locked(&r->c->frame.rendering));
819
uint64_t render_complete_signal_value = (uint64_t)r->c->frame.rendering.id;
820
821
ret = comp_target_present( //
···
1961
struct comp_target *ct = r->c->target;
1962
struct comp_compositor *c = r->c;
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));
1967
1968
+
// Move waited frame to rendering frame, clear waited.
1969
+
comp_frame_move_and_clear_locked(&c->frame.rendering, &c->frame.waited);
1970
1971
+
// Tell the target we are starting to render, for frame timing.
0
0
1972
comp_target_mark_begin(ct, c->frame.rendering.id, os_monotonic_get_ns());
1973
1974
// Are we ready to render? No - skip rendering.
···
1976
// Need to emulate rendering for the timing.
1977
//! @todo This should be discard.
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);
1982
return;
1983
}
1984
···
2028
// Save for timestamps below.
2029
uint64_t frame_id = c->frame.rendering.id;
2030
2031
+
// Clear the rendered frame.
2032
+
comp_frame_clear_locked(&c->frame.rendering);
2033
2034
mirror_to_debug_gui_fixup_ui_state(r);
2035
if (can_mirror_to_debug_gui(r)) {