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
59
60
60
#include "util/comp_vulkan.h"
61
61
#include "main/comp_compositor.h"
62
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
188
-
assert(c->frame.waited.id == -1);
189
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
1
+
// Copyright 2022-2023, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Small helper functions to manage frames.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup comp_main
8
8
+
*/
9
9
+
10
10
+
#pragma once
11
11
+
12
12
+
#include "main/comp_compositor.h"
13
13
+
14
14
+
15
15
+
/*!
16
16
+
* Is this frame invalid.
17
17
+
*/
18
18
+
static inline bool
19
19
+
comp_frame_is_invalid_locked(struct comp_frame *f)
20
20
+
{
21
21
+
return f->id == -1;
22
22
+
}
23
23
+
24
24
+
/*!
25
25
+
* Clear a slot, need to be externally synchronized.
26
26
+
*/
27
27
+
static inline void
28
28
+
comp_frame_clear_locked(struct comp_frame *slot)
29
29
+
{
30
30
+
U_ZERO(slot);
31
31
+
slot->id = -1;
32
32
+
}
33
33
+
34
34
+
/*!
35
35
+
* Move a frame into a cleared frame, need to be externally synchronized.
36
36
+
*/
37
37
+
static inline void
38
38
+
comp_frame_move_into_cleared(struct comp_frame *dst, struct comp_frame *src)
39
39
+
{
40
40
+
assert(comp_frame_is_invalid_locked(dst));
41
41
+
42
42
+
// Copy data.
43
43
+
*dst = *src;
44
44
+
45
45
+
U_ZERO(src);
46
46
+
src->id = -1;
47
47
+
}
48
48
+
49
49
+
/*!
50
50
+
* Move a frame, clear src, need to be externally synchronized.
51
51
+
*/
52
52
+
static inline void
53
53
+
comp_frame_move_and_clear_locked(struct comp_frame *dst, struct comp_frame *src)
54
54
+
{
55
55
+
comp_frame_clear_locked(dst);
56
56
+
comp_frame_move_into_cleared(dst, src);
57
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
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
669
-
assert(r->c->frame.rendering.id >= 0);
670
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
817
-
assert(r->c->frame.rendering.id >= 0);
818
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
1964
+
// Check that we don't have any bad data.
1965
1965
+
assert(!comp_frame_is_invalid_locked(&c->frame.waited));
1966
1966
+
assert(comp_frame_is_invalid_locked(&c->frame.rendering));
1963
1967
1964
1964
-
assert(c->frame.rendering.id == -1);
1968
1968
+
// Move waited frame to rendering frame, clear waited.
1969
1969
+
comp_frame_move_and_clear_locked(&c->frame.rendering, &c->frame.waited);
1965
1970
1966
1966
-
c->frame.rendering = c->frame.waited;
1967
1967
-
c->frame.waited.id = -1;
1968
1968
-
1971
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
1979
+
1980
1980
+
// Clear the rendering frame.
1981
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
2025
-
// Clear the frame.
2026
2026
-
c->frame.rendering.id = -1;
2031
2031
+
// Clear the rendered frame.
2032
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)) {