Skip to main content

alpha2_render/
backend.rs

1use crate::{EffectDef, EffectId, Renderer};
2
3/// Effect information a graph builder needs without drawing. The GPU [`Renderer`] and the
4/// [`crate::CpuRenderer`] answer from the same [`EffectDef`]s, so a frame compiles to the same
5/// graph on either.
6pub trait EffectCatalog {
7    /// The definition registered as `id`.
8    fn effect_definition(&self, id: &EffectId) -> Option<&EffectDef>;
9
10    /// Whether `id`'s output can change with frame time alone; `true` for unknown effects.
11    fn effect_reads_time(&self, id: &EffectId) -> bool;
12
13    /// The identity a project's effect `id`@`version` draws under; `None` if this renderer cannot
14    /// draw it or it is internal.
15    fn project_effect_id(&self, id: &str, version: u32) -> Option<&EffectId>;
16}
17
18impl EffectCatalog for Renderer {
19    fn effect_definition(&self, id: &EffectId) -> Option<&EffectDef> {
20        Renderer::effect_definition(self, id)
21    }
22
23    fn effect_reads_time(&self, id: &EffectId) -> bool {
24        Renderer::effect_reads_time(self, id)
25    }
26
27    fn project_effect_id(&self, id: &str, version: u32) -> Option<&EffectId> {
28        Renderer::project_effect_id(self, id, version)
29    }
30}
31
32/// Controls a frame runner sets and reads on either renderer.
33pub trait RenderControls {
34    /// Sets the filter sample budget (possibly capped lower) and motion blur subframe count.
35    fn set_quality_controls(&self, max_filter_samples: u32, motion_blur_subframes: u32);
36
37    /// Sets the byte budget of pooled pictures kept for reuse.
38    fn set_texture_budget_bytes(&self, budget_bytes: u64);
39
40    /// Changes whenever earlier results may differ from what the same graph draws now.
41    fn content_epoch(&self) -> u64;
42
43    /// Records whether a frame was presented and whether it repeated the previous one.
44    fn record_frame_outcome(&self, presented: bool, repeated: bool);
45
46    /// A deterministic key for what `graph` draws on this renderer.
47    ///
48    /// # Errors
49    /// Returns [`crate::GraphError::MissingOutput`] when no output was selected.
50    fn graph_cache_key(
51        &self,
52        graph: &crate::RenderGraph<'_>,
53    ) -> Result<crate::RenderCacheKey, crate::GraphError>;
54}
55
56impl RenderControls for Renderer {
57    fn set_quality_controls(&self, max_filter_samples: u32, motion_blur_subframes: u32) {
58        Renderer::set_quality_controls(self, max_filter_samples, motion_blur_subframes);
59    }
60
61    fn set_texture_budget_bytes(&self, budget_bytes: u64) {
62        Renderer::set_texture_budget_bytes(self, budget_bytes);
63    }
64
65    fn content_epoch(&self) -> u64 {
66        Renderer::content_epoch(self)
67    }
68
69    fn record_frame_outcome(&self, presented: bool, repeated: bool) {
70        Renderer::record_frame_outcome(self, presented, repeated);
71    }
72
73    fn graph_cache_key(
74        &self,
75        graph: &crate::RenderGraph<'_>,
76    ) -> Result<crate::RenderCacheKey, crate::GraphError> {
77        Renderer::graph_cache_key(self, graph)
78    }
79}