Skip to content

Commit bc0ede9

Browse files
committed
feat(renderer): add register_draw_pipeline/register_compute_pipeline and update call sites
Encapsulate pipeline registration behind WgpuApp methods to avoid exposing internal pipeline_registry. Replace direct pipeline_registry.register calls in components and examples with the new API.
1 parent d12d427 commit bc0ede9

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

tessera-example-calculator/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn android_main(android_app: AndroidApp) {
6161
&app.config,
6262
app.sample_count,
6363
);
64-
app.drawer.pipeline_registry.register(background_pipeline);
64+
app.register_draw_pipeline(background_pipeline);
6565
},
6666
android_app.clone(),
6767
)
@@ -92,7 +92,7 @@ pub fn desktop_main() -> anyhow::Result<()> {
9292
&app.config,
9393
app.sample_count,
9494
);
95-
app.drawer.pipeline_registry.register(background_pipeline);
95+
app.register_draw_pipeline(background_pipeline);
9696
},
9797
TesseraConfig {
9898
window_title: "Calculator".to_string(),

tessera-ui-basic-components/src/pipelines.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ pub use text::{TextCommand, TextConstraint, TextData, read_font_system, write_fo
1616
pub fn register_pipelines(app: &mut tessera_ui::renderer::WgpuApp) {
1717
// Register shape pipeline
1818
let shape_pipeline = shape::ShapePipeline::new(&app.gpu, &app.config, app.sample_count);
19-
app.drawer.pipeline_registry.register(shape_pipeline);
19+
app.register_draw_pipeline(shape_pipeline);
2020
// Register checkmark pipeline
2121
let checkmark_pipeline =
2222
checkmark::CheckmarkPipeline::new(&app.gpu, &app.config, app.sample_count);
23-
app.drawer.pipeline_registry.register(checkmark_pipeline);
23+
app.register_draw_pipeline(checkmark_pipeline);
2424
// Register text pipeline
2525
let text_pipeline =
2626
text::GlyphonTextRender::new(&app.gpu, &app.queue, &app.config, app.sample_count);
27-
app.drawer.pipeline_registry.register(text_pipeline);
27+
app.register_draw_pipeline(text_pipeline);
2828
// Register fluid glass pipeline
2929
let fluid_glass_pipeline =
3030
fluid_glass::FluidGlassPipeline::new(&app.gpu, &app.config, app.sample_count);
31-
app.drawer.pipeline_registry.register(fluid_glass_pipeline);
31+
app.register_draw_pipeline(fluid_glass_pipeline);
3232
// Register image pipeline
3333
let image_pipeline = image::ImagePipeline::new(&app.gpu, &app.config, app.sample_count);
34-
app.drawer.pipeline_registry.register(image_pipeline);
34+
app.register_draw_pipeline(image_pipeline);
3535
// Register blur pipeline
3636
let blur_pipeline = blur::pipeline::BlurPipeline::new(&app.gpu);
37-
app.compute_pipeline_registry.register(blur_pipeline);
37+
app.register_compute_pipeline(blur_pipeline);
3838

3939
// Register mean pipeline
4040
let mean_pipeline = mean::MeanPipeline::new(&app.gpu);
41-
app.compute_pipeline_registry.register(mean_pipeline);
41+
app.register_compute_pipeline(mean_pipeline);
4242

4343
// Register contrast pipeline
4444
let contrast_pipeline = contrast::ContrastPipeline::new(&app.gpu);
45-
app.compute_pipeline_registry.register(contrast_pipeline);
45+
app.register_compute_pipeline(contrast_pipeline);
4646
}

tessera-ui/src/renderer/app.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use wgpu::{ImageSubresourceRange, TextureFormat};
66
use winit::window::Window;
77

88
use crate::{
9-
ComputeCommand, DrawCommand, Px, PxPosition,
9+
ComputablePipeline, ComputeCommand, DrawCommand, DrawablePipeline, Px, PxPosition,
1010
compute::resource::ComputeResourceManager,
1111
dp::SCALE_FACTOR,
1212
px::{PxRect, PxSize},
@@ -180,6 +180,7 @@ impl WgpuApp {
180180
(None, None)
181181
}
182182
}
183+
183184
pub(crate) async fn new(window: Arc<Window>, sample_count: u32) -> Self {
184185
// Looking for gpus
185186
let instance: wgpu::Instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
@@ -264,6 +265,28 @@ impl WgpuApp {
264265
}
265266
}
266267

268+
/// Registers a new drawable pipeline for a specific command type.
269+
///
270+
/// This method takes ownership of the pipeline and wraps it in a type-erased container that can be stored alongside other pipelines of different types.
271+
pub fn register_draw_pipeline<T, P>(&mut self, pipeline: P)
272+
where
273+
T: DrawCommand + 'static,
274+
P: DrawablePipeline<T> + 'static,
275+
{
276+
self.drawer.pipeline_registry.register(pipeline);
277+
}
278+
279+
/// Registers a new compute pipeline for a specific command type.
280+
///
281+
/// This method takes ownership of the pipeline and wraps it in a type-erased container that can be stored alongside other pipelines of different types.
282+
pub fn register_compute_pipeline<T, P>(&mut self, pipeline: P)
283+
where
284+
T: ComputeCommand + 'static,
285+
P: ComputablePipeline<T> + 'static,
286+
{
287+
self.compute_pipeline_registry.register(pipeline);
288+
}
289+
267290
fn create_pass_target(
268291
gpu: &wgpu::Device,
269292
config: &wgpu::SurfaceConfiguration,

0 commit comments

Comments
 (0)