Skip to main content

alpha2_render/
backend.rs

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