graphics-core 0.1.0

Shared low-level, host-agnostic WGPU graphics substrate for offscreen rendering, readback, 2D/camera math, and overlay/preview pipelines.
Documentation
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//! Single-pass fullscreen composite + alpha-finalize and depth-stamp pipelines (zero Vello dependency).

use std::fmt;

use crate::pipelines::SourceAlphaMode;

const COMPOSITE_WGSL: &str = r#"
struct VsOut {
    @builtin(position) pos: vec4<f32>,
    @location(0) uv: vec2<f32>,
};

@vertex
fn vs_main(@builtin(vertex_index) vi: u32) -> VsOut {
    let uv = vec2<f32>(f32((vi << 1u) & 2u), f32(vi & 2u));
    let pos = vec4<f32>(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, 0.0, 1.0);
    return VsOut(pos, uv);
}

@group(0) @binding(0) var base_tex: texture_2d<f32>;
@group(0) @binding(1) var overlay_tex: texture_2d<f32>;
@group(0) @binding(2) var tex_samp: sampler;

fn to_premul(c: vec4<f32>, straight: bool) -> vec4<f32> {
    if (straight) {
        return vec4<f32>(c.rgb * c.a, c.a);
    }
    return c;
}

fn finalize_pm(pm: vec4<f32>, out_straight: bool) -> vec4<f32> {
    if (out_straight) {
        let rgb = select(vec3<f32>(0.0), clamp(pm.rgb / pm.a, vec3<f32>(0.0), vec3<f32>(1.0)), pm.a > 1e-5);
        return vec4<f32>(rgb, clamp(pm.a, 0.0, 1.0));
    }
    return pm;
}

fn composite_impl(uv: vec2<f32>, base_straight: bool, overlay_straight: bool, out_straight: bool) -> vec4<f32> {
    let base_pm = to_premul(textureSample(base_tex, tex_samp, uv), base_straight);
    let over_pm = to_premul(textureSample(overlay_tex, tex_samp, uv), overlay_straight);
    let pm = over_pm + base_pm * (1.0 - over_pm.a);
    return finalize_pm(pm, out_straight);
}

@fragment fn fs_ss_s(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, true, true, true); }
@fragment fn fs_ss_p(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, true, true, false); }
@fragment fn fs_sp_s(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, true, false, true); }
@fragment fn fs_sp_p(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, true, false, false); }
@fragment fn fs_ps_s(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, false, true, true); }
@fragment fn fs_ps_p(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, false, true, false); }
@fragment fn fs_pp_s(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, false, false, true); }
@fragment fn fs_pp_p(in: VsOut) -> @location(0) vec4<f32> { return composite_impl(in.uv, false, false, false); }
"#;

const SINGLE_WGSL: &str = r#"
struct VsOut {
    @builtin(position) pos: vec4<f32>,
    @location(0) uv: vec2<f32>,
};

@vertex
fn vs_main(@builtin(vertex_index) vi: u32) -> VsOut {
    let uv = vec2<f32>(f32((vi << 1u) & 2u), f32(vi & 2u));
    let pos = vec4<f32>(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, 0.0, 1.0);
    return VsOut(pos, uv);
}

@group(0) @binding(0) var src_tex: texture_2d<f32>;
@group(0) @binding(1) var src_samp: sampler;

fn finalize_single_impl(uv: vec2<f32>, src_straight: bool, out_straight: bool) -> vec4<f32> {
    let raw = textureSample(src_tex, src_samp, uv);
    let pm = select(raw, vec4<f32>(raw.rgb * raw.a, raw.a), src_straight);
    if (out_straight) {
        let rgb = select(vec3<f32>(0.0), clamp(pm.rgb / pm.a, vec3<f32>(0.0), vec3<f32>(1.0)), pm.a > 1e-5);
        return vec4<f32>(rgb, clamp(pm.a, 0.0, 1.0));
    }
    return pm;
}

@fragment fn fs_s_s(in: VsOut) -> @location(0) vec4<f32> { return finalize_single_impl(in.uv, true, true); }
@fragment fn fs_s_p(in: VsOut) -> @location(0) vec4<f32> { return finalize_single_impl(in.uv, true, false); }
@fragment fn fs_p_s(in: VsOut) -> @location(0) vec4<f32> { return finalize_single_impl(in.uv, false, true); }
@fragment fn fs_p_p(in: VsOut) -> @location(0) vec4<f32> { return finalize_single_impl(in.uv, false, false); }

@fragment
fn fs_stamp_depth(in: VsOut) {
    let c = textureSample(src_tex, src_samp, in.uv);
    if (c.a <= 0.0) {
        discard;
    }
}
"#;

/// Output alpha encoding emitted by [`CompositeFinalizePipeline`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum OutputAlphaMode {
    /// Emit straight (unpremultiplied) RGB + A, zeroing RGB when alpha <= 1e-5.
    #[default]
    Straight,
    /// Emit premultiplied RGB + A directly into the destination attachment.
    Premultiplied,
}

/// Errors returned by [`CompositeFinalizePipeline`] depth-stamping operations.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CompositeFinalizeError {
    /// Depth-stamp pass requested on a pipeline created with `depth_format: None`.
    DepthPipelineNotConfigured,
}

impl fmt::Display for CompositeFinalizeError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::DepthPipelineNotConfigured => {
                write!(f, "CompositeFinalizePipeline created without depth_format")
            }
        }
    }
}

impl std::error::Error for CompositeFinalizeError {}

#[inline]
fn source_mode_idx(mode: SourceAlphaMode) -> usize {
    match mode {
        SourceAlphaMode::Straight => 0,
        SourceAlphaMode::Premultiplied => 1,
    }
}

#[inline]
fn output_mode_idx(mode: OutputAlphaMode) -> usize {
    match mode {
        OutputAlphaMode::Straight => 0,
        OutputAlphaMode::Premultiplied => 1,
    }
}

fn create_fullscreen_color_pipeline(
    device: &wgpu::Device,
    layout: &wgpu::PipelineLayout,
    shader: &wgpu::ShaderModule,
    dst_format: wgpu::TextureFormat,
    fs_entry: &str,
    label: &str,
) -> wgpu::RenderPipeline {
    device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
        label: Some(label),
        layout: Some(layout),
        vertex: wgpu::VertexState {
            module: shader,
            entry_point: Some("vs_main"),
            compilation_options: wgpu::PipelineCompilationOptions::default(),
            buffers: &[],
        },
        primitive: wgpu::PrimitiveState {
            topology: wgpu::PrimitiveTopology::TriangleList,
            ..Default::default()
        },
        depth_stencil: None,
        multisample: wgpu::MultisampleState::default(),
        fragment: Some(wgpu::FragmentState {
            module: shader,
            entry_point: Some(fs_entry),
            compilation_options: wgpu::PipelineCompilationOptions::default(),
            targets: &[Some(wgpu::ColorTargetState {
                format: dst_format,
                blend: None,
                write_mask: wgpu::ColorWrites::ALL,
            })],
        }),
        multiview_mask: None,
        cache: None,
    })
}

fn create_depth_stamp_pipeline(
    device: &wgpu::Device,
    layout: &wgpu::PipelineLayout,
    shader: &wgpu::ShaderModule,
    depth_format: wgpu::TextureFormat,
) -> wgpu::RenderPipeline {
    device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
        label: Some("graphics_core_composite_stamp_depth"),
        layout: Some(layout),
        vertex: wgpu::VertexState {
            module: shader,
            entry_point: Some("vs_main"),
            compilation_options: wgpu::PipelineCompilationOptions::default(),
            buffers: &[],
        },
        primitive: wgpu::PrimitiveState {
            topology: wgpu::PrimitiveTopology::TriangleList,
            ..Default::default()
        },
        depth_stencil: Some(wgpu::DepthStencilState {
            format: depth_format,
            depth_write_enabled: Some(true),
            depth_compare: Some(wgpu::CompareFunction::Always),
            stencil: wgpu::StencilState::default(),
            bias: wgpu::DepthBiasState::default(),
        }),
        multisample: wgpu::MultisampleState::default(),
        fragment: Some(wgpu::FragmentState {
            module: shader,
            entry_point: Some("fs_stamp_depth"),
            compilation_options: wgpu::PipelineCompilationOptions::default(),
            targets: &[],
        }),
        multiview_mask: None,
        cache: None,
    })
}

fn texture_layout_entry(binding: u32) -> wgpu::BindGroupLayoutEntry {
    wgpu::BindGroupLayoutEntry {
        binding,
        visibility: wgpu::ShaderStages::FRAGMENT,
        ty: wgpu::BindingType::Texture {
            sample_type: wgpu::TextureSampleType::Float { filterable: true },
            view_dimension: wgpu::TextureViewDimension::D2,
            multisampled: false,
        },
        count: None,
    }
}

fn sampler_layout_entry(binding: u32) -> wgpu::BindGroupLayoutEntry {
    wgpu::BindGroupLayoutEntry {
        binding,
        visibility: wgpu::ShaderStages::FRAGMENT,
        ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
        count: None,
    }
}

/// Pure-WGPU single-pass composite, alpha-finalize (`LoadOp::DontCare`), and overlay depth-stamp pipeline.
pub struct CompositeFinalizePipeline {
    composite_bgl: wgpu::BindGroupLayout,
    single_bgl: wgpu::BindGroupLayout,
    sampler: wgpu::Sampler,
    // Indexed as [base_alpha][overlay_alpha][output_alpha].
    composite_pipelines: [[[wgpu::RenderPipeline; 2]; 2]; 2],
    // Indexed as [src_alpha][output_alpha].
    single_pipelines: [[wgpu::RenderPipeline; 2]; 2],
    depth_stamp_pipeline: Option<wgpu::RenderPipeline>,
}

impl CompositeFinalizePipeline {
    pub fn new(
        device: &wgpu::Device,
        dst_format: wgpu::TextureFormat,
        depth_format: Option<wgpu::TextureFormat>,
    ) -> Self {
        let composite_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
            label: Some("graphics_core_composite_finalize_shader"),
            source: wgpu::ShaderSource::Wgsl(COMPOSITE_WGSL.into()),
        });
        let single_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
            label: Some("graphics_core_single_finalize_shader"),
            source: wgpu::ShaderSource::Wgsl(SINGLE_WGSL.into()),
        });

        let composite_bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
            label: Some("graphics_core_composite_finalize_bgl"),
            entries: &[
                texture_layout_entry(0),
                texture_layout_entry(1),
                sampler_layout_entry(2),
            ],
        });
        let single_bgl = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
            label: Some("graphics_core_single_finalize_bgl"),
            entries: &[texture_layout_entry(0), sampler_layout_entry(1)],
        });

        let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            label: Some("graphics_core_composite_finalize_sampler"),
            mag_filter: wgpu::FilterMode::Nearest,
            min_filter: wgpu::FilterMode::Nearest,
            mipmap_filter: wgpu::MipmapFilterMode::Nearest,
            ..Default::default()
        });

        let composite_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
            label: Some("graphics_core_composite_finalize_layout"),
            bind_group_layouts: &[Some(&composite_bgl)],
            immediate_size: 0,
        });
        let single_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
            label: Some("graphics_core_single_finalize_layout"),
            bind_group_layouts: &[Some(&single_bgl)],
            immediate_size: 0,
        });

        let composite_pipelines = [
            [
                [
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_ss_s",
                        "graphics_core_composite_ss_s",
                    ),
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_ss_p",
                        "graphics_core_composite_ss_p",
                    ),
                ],
                [
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_sp_s",
                        "graphics_core_composite_sp_s",
                    ),
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_sp_p",
                        "graphics_core_composite_sp_p",
                    ),
                ],
            ],
            [
                [
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_ps_s",
                        "graphics_core_composite_ps_s",
                    ),
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_ps_p",
                        "graphics_core_composite_ps_p",
                    ),
                ],
                [
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_pp_s",
                        "graphics_core_composite_pp_s",
                    ),
                    create_fullscreen_color_pipeline(
                        device,
                        &composite_layout,
                        &composite_shader,
                        dst_format,
                        "fs_pp_p",
                        "graphics_core_composite_pp_p",
                    ),
                ],
            ],
        ];

        let single_pipelines = [
            [
                create_fullscreen_color_pipeline(
                    device,
                    &single_layout,
                    &single_shader,
                    dst_format,
                    "fs_s_s",
                    "graphics_core_single_s_s",
                ),
                create_fullscreen_color_pipeline(
                    device,
                    &single_layout,
                    &single_shader,
                    dst_format,
                    "fs_s_p",
                    "graphics_core_single_s_p",
                ),
            ],
            [
                create_fullscreen_color_pipeline(
                    device,
                    &single_layout,
                    &single_shader,
                    dst_format,
                    "fs_p_s",
                    "graphics_core_single_p_s",
                ),
                create_fullscreen_color_pipeline(
                    device,
                    &single_layout,
                    &single_shader,
                    dst_format,
                    "fs_p_p",
                    "graphics_core_single_p_p",
                ),
            ],
        ];

        let depth_stamp_pipeline = depth_format
            .map(|df| create_depth_stamp_pipeline(device, &single_layout, &single_shader, df));

        Self {
            composite_bgl,
            single_bgl,
            sampler,
            composite_pipelines,
            single_pipelines,
            depth_stamp_pipeline,
        }
    }

    /// Creates a reusable bind group for 2-input `overlay` over `base` compositing.
    pub fn create_composite_bind_group(
        &self,
        device: &wgpu::Device,
        base_view: &wgpu::TextureView,
        overlay_view: &wgpu::TextureView,
    ) -> wgpu::BindGroup {
        device.create_bind_group(&wgpu::BindGroupDescriptor {
            label: Some("graphics_core_composite_finalize_bg"),
            layout: &self.composite_bgl,
            entries: &[
                wgpu::BindGroupEntry {
                    binding: 0,
                    resource: wgpu::BindingResource::TextureView(base_view),
                },
                wgpu::BindGroupEntry {
                    binding: 1,
                    resource: wgpu::BindingResource::TextureView(overlay_view),
                },
                wgpu::BindGroupEntry {
                    binding: 2,
                    resource: wgpu::BindingResource::Sampler(&self.sampler),
                },
            ],
        })
    }

    /// Creates a reusable bind group for 1-input finalization or overlay depth stamping.
    pub fn create_single_bind_group(
        &self,
        device: &wgpu::Device,
        src_view: &wgpu::TextureView,
    ) -> wgpu::BindGroup {
        device.create_bind_group(&wgpu::BindGroupDescriptor {
            label: Some("graphics_core_single_finalize_bg"),
            layout: &self.single_bgl,
            entries: &[
                wgpu::BindGroupEntry {
                    binding: 0,
                    resource: wgpu::BindingResource::TextureView(src_view),
                },
                wgpu::BindGroupEntry {
                    binding: 1,
                    resource: wgpu::BindingResource::Sampler(&self.sampler),
                },
            ],
        })
    }

    fn run_fullscreen_color_pass(
        encoder: &mut wgpu::CommandEncoder,
        dst_view: &wgpu::TextureView,
        pipeline: &wgpu::RenderPipeline,
        bind_group: &wgpu::BindGroup,
        label: &'static str,
    ) {
        // SAFETY: the fullscreen triangle covers the entire viewport with color blending disabled.
        let load = wgpu::LoadOp::DontCare(unsafe { wgpu::LoadOpDontCare::enabled() });
        let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
            label: Some(label),
            color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                view: dst_view,
                resolve_target: None,
                ops: wgpu::Operations {
                    load,
                    store: wgpu::StoreOp::Store,
                },
                depth_slice: None,
            })],
            depth_stencil_attachment: None,
            timestamp_writes: None,
            occlusion_query_set: None,
            multiview_mask: None,
        });
        pass.set_pipeline(pipeline);
        pass.set_bind_group(0, bind_group, &[]);
        pass.draw(0..3, 0..1);
    }

    /// Composites `overlay` over `base` via `f32` Porter-Duff `SrcOver` into `dst_view` (`LoadOp::DontCare`).
    pub fn composite_with_bind_group(
        &self,
        encoder: &mut wgpu::CommandEncoder,
        dst_view: &wgpu::TextureView,
        bind_group: &wgpu::BindGroup,
        base_alpha: SourceAlphaMode,
        overlay_alpha: SourceAlphaMode,
        output_alpha: OutputAlphaMode,
    ) {
        let pipeline = &self.composite_pipelines[source_mode_idx(base_alpha)]
            [source_mode_idx(overlay_alpha)][output_mode_idx(output_alpha)];
        Self::run_fullscreen_color_pass(
            encoder,
            dst_view,
            pipeline,
            bind_group,
            "graphics_core_composite_finalize_pass",
        );
    }

    /// Convenience wrapper creating a temporary composite bind group and encoding [`Self::composite_with_bind_group`].
    #[allow(clippy::too_many_arguments)]
    pub fn composite(
        &self,
        device: &wgpu::Device,
        encoder: &mut wgpu::CommandEncoder,
        dst_view: &wgpu::TextureView,
        base_view: &wgpu::TextureView,
        overlay_view: &wgpu::TextureView,
        base_alpha: SourceAlphaMode,
        overlay_alpha: SourceAlphaMode,
        output_alpha: OutputAlphaMode,
    ) {
        let bg = self.create_composite_bind_group(device, base_view, overlay_view);
        self.composite_with_bind_group(
            encoder,
            dst_view,
            &bg,
            base_alpha,
            overlay_alpha,
            output_alpha,
        );
    }

    /// Finalizes a single source texture into `dst_view` (`LoadOp::DontCare`).
    pub fn finalize_single_with_bind_group(
        &self,
        encoder: &mut wgpu::CommandEncoder,
        dst_view: &wgpu::TextureView,
        bind_group: &wgpu::BindGroup,
        src_alpha: SourceAlphaMode,
        output_alpha: OutputAlphaMode,
    ) {
        let pipeline =
            &self.single_pipelines[source_mode_idx(src_alpha)][output_mode_idx(output_alpha)];
        Self::run_fullscreen_color_pass(
            encoder,
            dst_view,
            pipeline,
            bind_group,
            "graphics_core_single_finalize_pass",
        );
    }

    /// Convenience wrapper creating a temporary bind group and encoding [`Self::finalize_single_with_bind_group`].
    pub fn finalize_single(
        &self,
        device: &wgpu::Device,
        encoder: &mut wgpu::CommandEncoder,
        dst_view: &wgpu::TextureView,
        src_view: &wgpu::TextureView,
        src_alpha: SourceAlphaMode,
        output_alpha: OutputAlphaMode,
    ) {
        let bg = self.create_single_bind_group(device, src_view);
        self.finalize_single_with_bind_group(encoder, dst_view, &bg, src_alpha, output_alpha);
    }

    /// Stamps `z = 0.0` into `depth_view` (`LoadOp::Load`) wherever the bound overlay texture has `alpha > 0.0`.
    pub fn stamp_overlay_depth_with_bind_group(
        &self,
        encoder: &mut wgpu::CommandEncoder,
        depth_view: &wgpu::TextureView,
        single_bind_group: &wgpu::BindGroup,
    ) -> Result<(), CompositeFinalizeError> {
        let pipeline = self
            .depth_stamp_pipeline
            .as_ref()
            .ok_or(CompositeFinalizeError::DepthPipelineNotConfigured)?;
        let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
            label: Some("graphics_core_composite_stamp_depth_pass"),
            color_attachments: &[],
            depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
                view: depth_view,
                depth_ops: Some(wgpu::Operations {
                    load: wgpu::LoadOp::Load,
                    store: wgpu::StoreOp::Store,
                }),
                stencil_ops: None,
            }),
            timestamp_writes: None,
            occlusion_query_set: None,
            multiview_mask: None,
        });
        pass.set_pipeline(pipeline);
        pass.set_bind_group(0, single_bind_group, &[]);
        pass.draw(0..3, 0..1);
        Ok(())
    }

    /// Convenience wrapper creating a temporary single-texture bind group and stamping `z = 0.0` into `depth_view`.
    pub fn stamp_overlay_depth(
        &self,
        device: &wgpu::Device,
        encoder: &mut wgpu::CommandEncoder,
        depth_view: &wgpu::TextureView,
        overlay_view: &wgpu::TextureView,
    ) -> Result<(), CompositeFinalizeError> {
        let bg = self.create_single_bind_group(device, overlay_view);
        self.stamp_overlay_depth_with_bind_group(encoder, depth_view, &bg)
    }
}