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
use crate::{EffectDef, EffectId, Renderer};
/// What a renderer can tell a graph builder about the effects it draws,
/// without drawing anything: the GPU [`Renderer`]'s registry and the
/// [`crate::CpuRenderer`]'s kernels answer from the same [`EffectDef`]s, so
/// a frame compiles to the same graph whichever renderer draws it.
pub trait EffectCatalog {
/// The definition registered as `id`.
fn effect_definition(&self, id: &EffectId) -> Option<&EffectDef>;
/// Whether what `id` draws can change with the frame time alone. An
/// effect that is not registered answers `true`.
fn effect_reads_time(&self, id: &EffectId) -> bool;
/// The identity a project's effect `id` at `version` is drawn under;
/// `None` when this renderer cannot draw it, or it is an internal pass.
fn project_effect_id(&self, id: &str, version: u32) -> Option<&EffectId>;
}
impl EffectCatalog for Renderer {
fn effect_definition(&self, id: &EffectId) -> Option<&EffectDef> {
Renderer::effect_definition(self, id)
}
fn effect_reads_time(&self, id: &EffectId) -> bool {
Renderer::effect_reads_time(self, id)
}
fn project_effect_id(&self, id: &str, version: u32) -> Option<&EffectId> {
Renderer::project_effect_id(self, id, version)
}
}
/// The controls a frame runner sets and reads on whichever renderer draws
/// its frames: quality, the memory budget, and what has changed since.
pub trait RenderControls {
/// Sets the filter sample budget and the motion blur subframe count
/// passes take; the renderer may cap the budget lower.
fn set_quality_controls(&self, max_filter_samples: u32, motion_blur_subframes: u32);
/// Sets the bytes of pooled pictures the renderer keeps for reuse.
fn set_texture_budget_bytes(&self, budget_bytes: u64);
/// A count that changes whenever results drawn earlier may no longer be
/// what the same graph draws now.
fn content_epoch(&self) -> u64;
/// Records whether a frame was presented, and whether it repeated the
/// one before.
fn record_frame_outcome(&self, presented: bool, repeated: bool);
/// A deterministic key for what `graph` draws on this renderer.
///
/// # Errors
/// Returns [`crate::GraphError::MissingOutput`] when no output was selected.
fn graph_cache_key(
&self,
graph: &crate::RenderGraph<'_>,
) -> Result<crate::RenderCacheKey, crate::GraphError>;
}
impl RenderControls for Renderer {
fn set_quality_controls(&self, max_filter_samples: u32, motion_blur_subframes: u32) {
Renderer::set_quality_controls(self, max_filter_samples, motion_blur_subframes);
}
fn set_texture_budget_bytes(&self, budget_bytes: u64) {
Renderer::set_texture_budget_bytes(self, budget_bytes);
}
fn content_epoch(&self) -> u64 {
Renderer::content_epoch(self)
}
fn record_frame_outcome(&self, presented: bool, repeated: bool) {
Renderer::record_frame_outcome(self, presented, repeated);
}
fn graph_cache_key(
&self,
graph: &crate::RenderGraph<'_>,
) -> Result<crate::RenderCacheKey, crate::GraphError> {
Renderer::graph_cache_key(self, graph)
}
}