wgpui 0.4.1

Independent wgpu + winit UI framework (community fork of GPUI / GPUI-CE 0.3.3)
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
use std::collections::{HashMap, HashSet};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Condvar, Mutex};

/// An opaque identifier for a registered WGPU surface.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct SurfaceId(pub(crate) u64);

#[allow(dead_code)]
struct DoubleBuffer {
    textures: [wgpu::Texture; 2],
    views: [wgpu::TextureView; 2],
    /// Each texture's own size. A front buffer kept by a resize keeps its old
    /// size until it is swapped to the back and replaced.
    sizes: [(u32, u32); 2],
    device: wgpu::Device,
    front: usize,
    /// Changes whenever resize replaces the textures while preserving the surface id.
    revision: u64,
    width: u32,
    height: u32,
    format: wgpu::TextureFormat,
}

#[derive(Clone, Copy, PartialEq, Eq)]
enum PresentStatus {
    Idle,
    Pending,
    Closed,
}

/// Shared with retained handles so closure remains terminal after textures are removed.
pub(crate) struct SurfacePresentation {
    status: Mutex<PresentStatus>,
    consumed: Condvar,
}

impl SurfacePresentation {
    fn new(status: PresentStatus) -> Self {
        Self {
            status: Mutex::new(status),
            consumed: Condvar::new(),
        }
    }

    fn request(&self) -> Option<bool> {
        let mut status = self.status.lock().unwrap();
        if *status == PresentStatus::Closed {
            return None;
        }
        let pending = *status == PresentStatus::Pending;
        *status = PresentStatus::Pending;
        Some(pending)
    }

    fn clear(&self) {
        let mut status = self.status.lock().unwrap();
        if *status == PresentStatus::Pending {
            *status = PresentStatus::Idle;
        }
        self.consumed.notify_all();
    }

    fn close(&self) {
        *self.status.lock().unwrap() = PresentStatus::Closed;
        self.consumed.notify_all();
    }

    pub(crate) fn is_closed(&self) -> bool {
        *self.status.lock().unwrap() == PresentStatus::Closed
    }

    pub(crate) fn is_pending(&self) -> bool {
        *self.status.lock().unwrap() == PresentStatus::Pending
    }

    pub(crate) fn wait(&self) {
        let mut status = self.status.lock().unwrap();
        while *status == PresentStatus::Pending {
            status = self.consumed.wait(status).unwrap();
        }
    }
}

/// Identifies one lifetime of a native window, not a reusable native id alone.
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) struct SurfaceOwner {
    window_id: winit::window::WindowId,
    generation: u64,
}

struct RegisteredSurface<T> {
    data: T,
    owner: Option<SurfaceOwner>,
    presentation: Arc<SurfacePresentation>,
}
impl<T> std::ops::Deref for RegisteredSurface<T> {
    type Target = T;
    fn deref(&self) -> &T {
        &self.data
    }
}
impl<T> std::ops::DerefMut for RegisteredSurface<T> {
    fn deref_mut(&mut self) -> &mut T {
        &mut self.data
    }
}

struct RegistryState<T> {
    surfaces: HashMap<SurfaceId, RegisteredSurface<T>>,
    closed_owners: HashSet<SurfaceOwner>,
    closed: bool,
    next_owner: u64,
}
impl<T> RegistryState<T> {
    fn new() -> Self {
        Self {
            surfaces: HashMap::new(),
            closed_owners: HashSet::new(),
            closed: false,
            next_owner: 1,
        }
    }
    fn register(
        &mut self,
        id: SurfaceId,
        owner: Option<SurfaceOwner>,
        create: impl FnOnce() -> T,
    ) -> bool {
        if self.closed || owner.is_some_and(|owner| self.closed_owners.contains(&owner)) {
            return false;
        }
        self.surfaces.insert(
            id,
            RegisteredSurface {
                data: create(),
                owner,
                presentation: Arc::new(SurfacePresentation::new(PresentStatus::Idle)),
            },
        );
        true
    }
    fn open_owner(&mut self, window_id: winit::window::WindowId) -> SurfaceOwner {
        let generation = self.next_owner;
        self.next_owner = generation
            .checked_add(1)
            .expect("surface owner generation exhausted");
        SurfaceOwner {
            window_id,
            generation,
        }
    }
    fn close_owner(&mut self, owner: SurfaceOwner) {
        self.closed_owners.insert(owner);
        self.surfaces.retain(|_, surface| {
            if surface.owner == Some(owner) {
                surface.presentation.close();
                false
            } else {
                true
            }
        });
    }
    fn shutdown(&mut self) {
        self.closed = true;
        for surface in self.surfaces.values() {
            surface.presentation.close();
        }
        self.surfaces.clear();
    }
}

/// Thread-safe registry of all active WGPU surfaces.
/// Maps `SurfaceId` to double-buffered texture pairs.
pub struct SurfaceRegistry {
    surfaces: Mutex<RegistryState<DoubleBuffer>>,
    next_id: AtomicU64,
}

impl SurfaceRegistry {
    pub fn new() -> Self {
        Self {
            surfaces: Mutex::new(RegistryState::new()),
            next_id: AtomicU64::new(1),
        }
    }

    /// Create buffers only while the registry and exact owner lifetime remain open.
    /// Returns `None` after closure without allocating GPU resources.
    pub fn create(
        &self,
        device: &wgpu::Device,
        width: u32,
        height: u32,
        format: wgpu::TextureFormat,
        owner: Option<SurfaceOwner>,
    ) -> Option<SurfaceId> {
        let id = SurfaceId(self.next_id.fetch_add(1, Ordering::Relaxed));
        self.surfaces
            .lock()
            .unwrap()
            .register(id, owner, || {
                Self::create_double_buffer(device, width, height, format)
            })
            .then_some(id)
    }

    /// Begin a new native window lifetime, including a legitimately reused window id.
    pub(crate) fn open_owner(&self, owner: winit::window::WindowId) -> SurfaceOwner {
        self.surfaces.lock().unwrap().open_owner(owner)
    }

    pub(crate) fn close_owner(&self, owner: SurfaceOwner) {
        self.surfaces.lock().unwrap().close_owner(owner);
    }

    pub(crate) fn shutdown(&self) {
        self.surfaces.lock().unwrap().shutdown();
    }

    pub(crate) fn presentation(&self, id: SurfaceId) -> Arc<SurfacePresentation> {
        self.surfaces
            .lock()
            .unwrap()
            .surfaces
            .get(&id)
            .map(|surface| surface.presentation.clone())
            .unwrap_or_else(|| Arc::new(SurfacePresentation::new(PresentStatus::Closed)))
    }

    /// Swap front and back buffers (pointer swap, no GPU work). A back buffer
    /// kept from before a resize is replaced with one at the current size.
    pub fn swap_buffers(&self, id: SurfaceId) {
        if let Some(db) = self.surfaces.lock().unwrap().surfaces.get_mut(&id) {
            db.front = 1 - db.front;
            let back = 1 - db.front;
            if db.sizes[back] != (db.width, db.height) {
                let texture = Self::create_texture(
                    &db.device,
                    db.width,
                    db.height,
                    db.format,
                    "surface_buffer",
                );
                db.views[back] = texture.create_view(&wgpu::TextureViewDescriptor::default());
                db.textures[back] = texture;
                db.sizes[back] = (db.width, db.height);
                db.revision = db.revision.wrapping_add(1);
            }
        }
    }

    /// Resize both buffers, creating new textures. With `keep_front`, the front
    /// buffer is kept, so its last frame stays visible until the next swap.
    pub fn resize(
        &self,
        device: &wgpu::Device,
        id: SurfaceId,
        width: u32,
        height: u32,
        keep_front: bool,
    ) {
        let mut state = self.surfaces.lock().unwrap();
        let surfaces = &mut state.surfaces;
        if let Some(db) = surfaces.get_mut(&id) {
            if db.width == width && db.height == height {
                return;
            }
            let mut new_db = Self::create_double_buffer(device, width, height, db.format);
            new_db.revision = db.revision.wrapping_add(1);
            if keep_front {
                let front = db.front;
                new_db.front = front;
                new_db.textures[front] = db.textures[front].clone();
                new_db.views[front] = db.views[front].clone();
                new_db.sizes[front] = db.sizes[front];
            }
            db.data = new_db;
        }
    }

    /// Get the front buffer's `TextureView` (what the renderer reads from).
    #[allow(dead_code)]
    pub fn front_view(&self, id: SurfaceId) -> Option<wgpu::TextureView> {
        // clone an already-created view instead of making a new one every frame.
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| db.views[db.front].clone())
    }

    /// Get the back buffer's `Texture` (what external code renders into).
    #[allow(dead_code)]
    pub fn back_texture(&self, _id: SurfaceId) -> Option<wgpu::Texture> {
        // wgpu::Texture is internally Arc'd, so we can't just hand it out.
        // Instead we'll provide a view via back_view().
        None
    }

    /// Get the back buffer's `TextureView` for use as a render target.
    pub fn back_view(&self, id: SurfaceId) -> Option<wgpu::TextureView> {
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| {
            let back = 1 - db.front;
            db.views[back].clone()
        })
    }

    /// Atomically retrieve both the back view and the corresponding texture
    /// dimensions. This is useful when a caller needs to create auxiliary
    /// resources (e.g. a depth buffer) that must exactly match the view's size.
    pub fn lock_and_get_back_with_size(
        &self,
        id: SurfaceId,
    ) -> Option<(wgpu::TextureView, (u32, u32))> {
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| {
            let back = 1 - db.front;
            (db.views[back].clone(), (db.width, db.height))
        })
    }

    /// Atomically snapshot the texture views needed to bind a surface.
    ///
    /// A surface keeps the same id when it is resized, but both texture views are
    /// replaced. The revision lets renderer-side caches distinguish those texture
    /// generations and rebuild bind groups instead of sampling stale views.
    pub fn binding_snapshot(&self, id: SurfaceId) -> Option<(usize, u64, [wgpu::TextureView; 2])> {
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| {
            (
                db.front,
                db.revision,
                [db.views[0].clone(), db.views[1].clone()],
            )
        })
    }

    /// Get the current size of a surface.
    #[allow(dead_code)]
    pub fn size(&self, id: SurfaceId) -> Option<(u32, u32)> {
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| (db.width, db.height))
    }

    /// Get the texture format for a surface.
    #[allow(dead_code)]
    pub fn format(&self, id: SurfaceId) -> Option<wgpu::TextureFormat> {
        let state = self.surfaces.lock().unwrap();
        let surfaces = &state.surfaces;
        surfaces.get(&id).map(|db| db.format)
    }

    /// Remove a surface and release any retained handle's presentation wait.
    pub fn remove(&self, id: SurfaceId) {
        if let Some(surface) = self.surfaces.lock().unwrap().surfaces.remove(&id) {
            surface.presentation.close();
        }
    }

    /// Return whether an earlier request is pending, or this surface is closed.
    /// Closed/missing surfaces never schedule another compositor callback.
    pub fn set_present_pending(&self, id: SurfaceId) -> bool {
        self.surfaces
            .lock()
            .unwrap()
            .surfaces
            .get(&id)
            .and_then(|surface| surface.presentation.request())
            .unwrap_or(true)
    }

    pub fn is_present_pending(&self, id: SurfaceId) -> bool {
        self.presentation(id).is_pending()
    }

    pub fn has_present_pending_for(&self, owner: winit::window::WindowId) -> bool {
        self.surfaces
            .lock()
            .unwrap()
            .surfaces
            .values()
            .any(|surface| {
                surface.owner.is_some_and(|token| token.window_id == owner)
                    && surface.presentation.is_pending()
            })
    }

    /// Consume a frame without reopening a terminally closed presentation state.
    pub fn clear_present_pending(&self, id: SurfaceId) {
        if let Some(surface) = self.surfaces.lock().unwrap().surfaces.get(&id) {
            surface.presentation.clear();
        }
    }

    fn create_texture(
        device: &wgpu::Device,
        width: u32,
        height: u32,
        format: wgpu::TextureFormat,
        label: &str,
    ) -> wgpu::Texture {
        device.create_texture(&wgpu::TextureDescriptor {
            label: Some(label),
            size: wgpu::Extent3d {
                width: width.max(1),
                height: height.max(1),
                depth_or_array_layers: 1,
            },
            mip_level_count: 1,
            sample_count: 1,
            dimension: wgpu::TextureDimension::D2,
            format,
            usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
            view_formats: &[],
        })
    }

    fn create_double_buffer(
        device: &wgpu::Device,
        width: u32,
        height: u32,
        format: wgpu::TextureFormat,
    ) -> DoubleBuffer {
        let w = width.max(1);
        let h = height.max(1);

        let tex0 = Self::create_texture(device, w, h, format, "surface_buffer_0");
        let tex1 = Self::create_texture(device, w, h, format, "surface_buffer_1");
        let view0 = tex0.create_view(&wgpu::TextureViewDescriptor::default());
        let view1 = tex1.create_view(&wgpu::TextureViewDescriptor::default());

        DoubleBuffer {
            textures: [tex0, tex1],
            views: [view0, view1],
            sizes: [(w, h); 2],
            device: device.clone(),
            front: 0,
            revision: 0,
            width: w,
            height: h,
            format,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::{
        sync::{Barrier, mpsc},
        time::Duration,
    };

    fn sizes(registry: &SurfaceRegistry, id: SurfaceId) -> (usize, [(u32, u32); 2]) {
        let state = registry.surfaces.lock().unwrap();
        let db = &state.surfaces[&id];
        (db.front, db.sizes)
    }

    #[test]
    fn resize_replaces_both_buffers_by_default() {
        let context = super::super::render_context::WgpuContext::new().expect("wgpu device");
        let device = &context.device;
        let registry = SurfaceRegistry::new();
        let format = wgpu::TextureFormat::Rgba8Unorm;
        let id = registry.create(device, 100, 50, format, None).unwrap();
        registry.swap_buffers(id);
        let (was, _, before) = registry.binding_snapshot(id).unwrap();
        registry.resize(device, id, 200, 100, false);
        let (front, _, after) = registry.binding_snapshot(id).unwrap();
        assert!(!after.contains(&before[was]), "the last frame is gone");
        assert_ne!(after[front], after[1 - front]);
        assert_eq!(sizes(&registry, id).1, [(200, 100); 2]);
    }

    #[test]
    fn resize_keeping_the_front_shows_it_until_the_next_swap() {
        let context = super::super::render_context::WgpuContext::new().expect("wgpu device");
        let device = &context.device;
        let registry = SurfaceRegistry::new();
        let format = wgpu::TextureFormat::Rgba8Unorm;
        let id = registry.create(device, 100, 50, format, None).unwrap();
        registry.swap_buffers(id);
        let (was, revision, before) = registry.binding_snapshot(id).unwrap();
        registry.resize(device, id, 200, 100, true);
        let (front, resized, after) = registry.binding_snapshot(id).unwrap();
        assert_eq!(front, was);
        assert_eq!(before[front], after[front], "the last frame stays in front");
        assert_ne!(revision, resized);
        let (_, size) = registry.lock_and_get_back_with_size(id).unwrap();
        assert_eq!(size, (200, 100), "the back buffer renders at the new size");
        assert_eq!(sizes(&registry, id).1[front], (100, 50));

        registry.swap_buffers(id);
        let (front, swapped, _) = registry.binding_snapshot(id).unwrap();
        assert_ne!(resized, swapped);
        assert_eq!(sizes(&registry, id), (front, [(200, 100); 2]));
    }

    #[test]
    fn missing_surface_never_schedules_a_pending_frame() {
        let registry = SurfaceRegistry::new();
        assert!(registry.set_present_pending(SurfaceId(99)));
        assert!(!registry.is_present_pending(SurfaceId(99)));
        assert!(registry.back_view(SurfaceId(99)).is_none());
    }

    #[test]
    fn retained_presentation_wait_finishes_and_later_requests_stay_closed() {
        let mut registry = RegistryState::new();
        let owner = registry.open_owner(winit::window::WindowId::from(1));
        assert!(registry.register(SurfaceId(1), Some(owner), || ()));
        let retained = registry.surfaces[&SurfaceId(1)].presentation.clone();
        assert_eq!(retained.request(), Some(false));
        let waiter = retained.clone();
        let (finished, result) = mpsc::channel();
        let thread = std::thread::spawn(move || {
            waiter.wait();
            finished.send(()).unwrap();
        });
        registry.close_owner(owner);
        result
            .recv_timeout(Duration::from_secs(2))
            .expect("close must release a retained presentation wait");
        thread.join().unwrap();
        for _ in 0..100 {
            retained.clear();
            assert_eq!(
                retained.request(),
                None,
                "present after close cannot re-arm pending"
            );
            assert!(!retained.is_pending());
            retained.wait();
        }
        assert!(!registry.register(SurfaceId(2), Some(owner), || panic!(
            "late creation must not allocate"
        )));
        assert!(
            registry.surfaces.get_mut(&SurfaceId(1)).is_none(),
            "resize cannot resurrect a closed surface"
        );
    }

    #[test]
    fn closing_one_owner_preserves_live_presentations_and_reused_window_ids() {
        let mut registry = RegistryState::new();
        let owner = registry.open_owner(winit::window::WindowId::from(1));
        let other = registry.open_owner(winit::window::WindowId::from(2));
        assert!(registry.register(SurfaceId(1), Some(owner), || ()));
        assert!(registry.register(SurfaceId(2), Some(other), || ()));
        let old = registry.surfaces[&SurfaceId(1)].presentation.clone();
        let live = registry.surfaces[&SurfaceId(2)].presentation.clone();
        assert_eq!(live.request(), Some(false));
        assert_eq!(live.request(), Some(true));
        registry.close_owner(owner);
        assert!(old.is_closed());
        assert!(live.is_pending());
        live.clear();
        live.wait();
        assert_eq!(live.request(), Some(false));
        let replacement = registry.open_owner(owner.window_id);
        assert!(!registry.register(SurfaceId(4), Some(owner), || panic!(
            "stale owner registration"
        )));
        assert!(registry.register(SurfaceId(3), Some(replacement), || ()));
        registry.close_owner(owner);
        assert!(!registry.surfaces[&SurfaceId(3)].presentation.is_closed());
        assert_eq!(
            registry.surfaces[&SurfaceId(3)].presentation.request(),
            Some(false)
        );
        assert_eq!(
            old.request(),
            None,
            "a new window lifetime cannot reopen old handles"
        );
    }

    #[test]
    fn registration_racing_close_cannot_resurrect_owner_surfaces() {
        let (finished, result) = mpsc::channel();
        let coordinator = std::thread::spawn(move || {
            let state = Arc::new(Mutex::new(RegistryState::new()));
            let owner = state
                .lock()
                .unwrap()
                .open_owner(winit::window::WindowId::from(1));
            let start = Arc::new(Barrier::new(2));
            let registration = state.clone();
            let ready = start.clone();
            let producer = std::thread::spawn(move || {
                ready.wait();
                let mut handles = Vec::new();
                for id in 1..1001 {
                    let mut state = registration.lock().unwrap();
                    if state.register(SurfaceId(id), Some(owner), || ()) {
                        handles.push(state.surfaces[&SurfaceId(id)].presentation.clone());
                    }
                }
                handles
            });
            start.wait();
            state.lock().unwrap().close_owner(owner);
            let handles = producer.join().unwrap();
            assert!(handles.iter().all(|handle| handle.is_closed()));
            let mut state = state.lock().unwrap();
            assert!(state.surfaces.is_empty());
            assert!(!state.register(SurfaceId(1002), Some(owner), || panic!(
                "closed owner allocation"
            )));
            finished.send(()).unwrap();
        });
        result
            .recv_timeout(Duration::from_secs(3))
            .expect("registration/close must finish without deadlock");
        coordinator.join().unwrap();
    }

    #[test]
    fn shutdown_closes_all_owners_and_rejects_all_later_registration() {
        let mut registry = RegistryState::new();
        let owner = registry.open_owner(winit::window::WindowId::from(1));
        assert!(registry.register(SurfaceId(1), Some(owner), || ()));
        assert!(registry.register(SurfaceId(2), None, || ()));
        let handles = registry
            .surfaces
            .values()
            .map(|surface| surface.presentation.clone())
            .collect::<Vec<_>>();
        for handle in &handles {
            assert_eq!(handle.request(), Some(false));
        }
        registry.shutdown();
        let replacement = registry.open_owner(owner.window_id);
        assert!(
            !registry.register(SurfaceId(5), Some(replacement), || panic!(
                "shutdown new owner allocation"
            ))
        );
        for handle in handles {
            assert!(handle.is_closed());
            assert_eq!(handle.request(), None);
            handle.wait();
        }
        assert!(!registry.register(SurfaceId(3), Some(owner), || panic!("shutdown allocation")));
        assert!(!registry.register(SurfaceId(4), None, || panic!(
            "shutdown headless allocation"
        )));
    }
}