1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use crate::{
collect::{ChildLayer, LayerScene},
scene::{
BackdropLayer, CompositorScene, DrawOp, EffectLayer, ImageDraw, RunDraw, ShadowDraw,
TextDraw,
},
};
pub(crate) const MAX_FRAMES_IN_FLIGHT: usize = 2;
/// Why the present stage refused a packet without drawing it. Each reason
/// names the expectation the packet no longer matches; the frame is not an
/// error, its scene travels back through `RenderReturns` for recycling.
/// `pub` (not `pub(crate)`) because the cancellation-protocol tests in
/// `tests/` observe outcomes through `#[doc(hidden)]` hooks; the module is
/// private, so the only public path is the hidden re-export in `lib.rs`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CancelReason {
/// The packet was built against a different `GpuRenderer` instance.
RendererEpoch,
/// The packet was built against a different surface configuration.
SurfaceEpoch,
/// The packet was lowered for a different surface size.
Viewport,
/// The present stage had no usable surface to draw the packet on: the
/// surface was dropped, or acquire failed past its one reconfigure
/// retry. Producer state (epochs, viewport) still matched, only the
/// swapchain was missing.
SurfaceUnavailable,
/// The device reported an uncaptured error (validation/OOM/internal)
/// since the previous frame: nothing of this packet is encoded on the
/// suspect device. One cancel per poisoning; the gate clears as it
/// fires, so the next packet renders (see `DeviceErrorSentry`).
DeviceError,
}
/// What the present stage did with a packet. `NotRun` is the `Default` so a
/// draw that never happened can never be reported `Presented`.
/// `pub` like [`CancelReason`], for the same hidden test re-export.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PresentOutcome {
/// No packet was consumed (the default of an untouched returns value).
#[default]
NotRun,
/// The packet was drawn and presented.
Presented,
/// The packet drew what the surface showed: no image, draw or present.
Unchanged,
/// The packet was refused before any encoding; the scene returned whole.
Cancelled(CancelReason),
}
pub(crate) struct FramePacket {
pub(crate) frame_id: u64,
pub(crate) viewport: (u32, u32),
pub(crate) renderer_epoch: u64,
pub(crate) surface_epoch: u64,
pub(crate) root_scale: f32,
pub(crate) root: Box<LayerScene>,
pub(crate) overlay: Option<Box<LayerScene>>,
pub(crate) clear: wgpu::Color,
// Whether the app held still, asking for no frame, between the frame
// before and this one.
pub(crate) held_still: bool,
// Whether a pointer was held on the app's controls for this frame.
pub(crate) pointer_held: bool,
// The scene update the packet was collected from: a frame drawn from the
// update the frame before drew shows nothing new of the app's.
pub(crate) scene_update: u64,
}
impl FramePacket {
// How the packet's scene moved since the frame that drew `drawn`, the
// scene update before.
pub(crate) fn scene_motion(&self, drawn: Option<u64>) -> SceneMotion {
if self.pointer_held {
SceneMotion::Held
} else if drawn == Some(self.scene_update) {
SceneMotion::Still
} else {
SceneMotion::Moving
}
}
}
// How a frame's scene moved since the frame before, which on WebGL decides
// whether a paced build runs at its end (see `PipelineCompiler::paced`).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum SceneMotion {
// The frame draws the scene update the frame before drew, with no
// pointer held.
Still,
// The scene changed, with no pointer held.
Moving,
// A pointer is held on the app's controls.
Held,
}
pub(crate) struct FrameSceneStorage {
pub(crate) root: Box<LayerScene>,
pub(crate) overlay: Option<Box<LayerScene>>,
}
/// Present-stage timestamps for one consumed packet, in nanoseconds on the
/// clock the producer injected at runtime start (`0` = stage did not run or
/// no clock was injected). Carried back in `RenderReturns` so the
/// producer's frame telemetry keeps recording acquire/render/present phases
/// after those stages move to the present thread. Plain integers so the
/// packet types stay clock-library-free on every target.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct PresentTimings {
/// When the present stage had acquired the surface texture.
pub after_acquire_ns: i64,
/// When the present stage had rendered the frame's draws.
pub after_render_ns: i64,
/// When the present stage had presented the frame to the surface.
pub after_present_ns: i64,
}
#[derive(Default)]
pub(crate) struct RenderReturns {
pub(crate) scene: Option<FrameSceneStorage>,
pub(crate) frame_id: u64,
pub(crate) outcome: PresentOutcome,
#[cfg(not(target_arch = "wasm32"))]
pub(crate) timings: PresentTimings,
}
const _: () = {
const fn assert_send<T: Send>() {}
assert_send::<FramePacket>();
assert_send::<FrameSceneStorage>();
assert_send::<LayerScene>();
assert_send::<ChildLayer>();
assert_send::<CompositorScene>();
assert_send::<RunDraw>();
assert_send::<ImageDraw>();
assert_send::<TextDraw>();
assert_send::<ShadowDraw>();
assert_send::<DrawOp>();
assert_send::<EffectLayer>();
assert_send::<BackdropLayer>();
assert_send::<RenderReturns>();
assert_send::<CancelReason>();
assert_send::<PresentOutcome>();
assert_send::<PresentTimings>();
};