Skip to main content

tessera_ui/
pipeline_context.rs

1//! Pipeline registration context for renderer initialization
2
3use crate::{
4    ComputablePipeline, ComputeCommand, DrawCommand, DrawablePipeline,
5    renderer::{RenderCore, RenderResources},
6};
7
8/// Context passed to pipeline initialization functions.
9pub struct PipelineContext<'a> {
10    core: &'a mut RenderCore,
11}
12
13impl<'a> PipelineContext<'a> {
14    /// Returns the resource and upload service owned by this renderer.
15    pub fn graphics(&self) -> &crate::GraphicsDevice {
16        self.core.resources().graphics
17    }
18    /// Creates a new pipeline context for the given renderer app.
19    pub(crate) fn new(core: &'a mut RenderCore) -> Self {
20        Self { core }
21    }
22
23    /// Returns shared GPU resources used for pipeline creation.
24    pub fn resources(&self) -> RenderResources<'_> {
25        self.core.resources()
26    }
27
28    /// Registers a draw pipeline for a specific command type.
29    pub fn register_draw_pipeline<T, P>(&mut self, pipeline: P)
30    where
31        T: DrawCommand + 'static,
32        P: DrawablePipeline<T> + 'static,
33    {
34        self.core.register_draw_pipeline(pipeline);
35    }
36
37    /// Registers a compute pipeline for a specific command type.
38    pub fn register_compute_pipeline<T, P>(&mut self, pipeline: P)
39    where
40        T: ComputeCommand + 'static,
41        P: ComputablePipeline<T> + 'static,
42    {
43        self.core.register_compute_pipeline(pipeline);
44    }
45
46    /// Registers a factory that creates a draw pipeline before the first frame that uses it.
47    pub fn register_draw_pipeline_factory<T, P>(
48        &mut self,
49        factory: impl FnOnce(RenderResources<'_>) -> P + Send + 'static,
50    ) where
51        T: DrawCommand + 'static,
52        P: DrawablePipeline<T> + 'static,
53    {
54        self.core.register_draw_pipeline_factory(factory);
55    }
56
57    /// Registers a factory that creates a compute pipeline before its first dispatch.
58    pub fn register_compute_pipeline_factory<T, P>(
59        &mut self,
60        factory: impl FnOnce(RenderResources<'_>) -> P + Send + 'static,
61    ) where
62        T: ComputeCommand + 'static,
63        P: ComputablePipeline<T> + 'static,
64    {
65        self.core.register_compute_pipeline_factory(factory);
66    }
67}