sinomo-ui-render-wgpu 0.7.0

wgpu renderer boundary for SUI scene frames.
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
use crate::WgpuRenderer;
use crate::gpu::SharedRenderer;
use crate::gpu::TextAtlasQuadVertex;
use crate::resources::create_text_atlas_array_bind_group_layout;
use std::collections::HashMap;
use sui_core::Error;
use sui_core::Result;
use wgpu::util::DeviceExt;

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
pub(crate) struct DevicePreparation {
    pub window: Option<sui_core::WindowId>,
    cancelled: std::sync::Arc<std::sync::atomic::AtomicBool>,
    thread: Option<std::thread::JoinHandle<Result<(SharedRenderer, u64)>>>,
}

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
impl DevicePreparation {
    fn finish(mut self) -> Result<(SharedRenderer, u64)> {
        self.thread
            .take()
            .expect("pending device thread")
            .join()
            .map_err(|_| Error::new("GPU device preparation thread panicked"))?
    }
}

#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
impl Drop for DevicePreparation {
    fn drop(&mut self) {
        // Closing an unrendered window must not install resources later or block
        // the UI. In-flight driver calls finish on the worker and release their
        // owned surface/device; subsequent initialization stages are cancelled.
        self.cancelled
            .store(true, std::sync::atomic::Ordering::Release);
    }
}

pub(crate) fn optional_renderer_features(adapter: &wgpu::Adapter) -> wgpu::Features {
    let mut features = wgpu::Features::empty();
    if adapter
        .features()
        .contains(wgpu::Features::DUAL_SOURCE_BLENDING)
    {
        features |= wgpu::Features::DUAL_SOURCE_BLENDING;
    }
    features
}

impl SharedRenderer {
    pub(crate) fn new(adapter: wgpu::Adapter, device: wgpu::Device, queue: wgpu::Queue) -> Self {
        let image_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("SUI image bind group layout"),
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Texture {
                            sample_type: wgpu::TextureSampleType::Float { filterable: true },
                            view_dimension: wgpu::TextureViewDimension::D2,
                            multisampled: false,
                        },
                        count: None,
                    },
                ],
            });
        let text_atlas_array_bind_group_layout = create_text_atlas_array_bind_group_layout(&device);
        let image_linear_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            label: Some("SUI linear image sampler"),
            mag_filter: wgpu::FilterMode::Linear,
            min_filter: wgpu::FilterMode::Linear,
            mipmap_filter: wgpu::MipmapFilterMode::Linear,
            ..Default::default()
        });
        let image_nearest_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            label: Some("SUI nearest image sampler"),
            mag_filter: wgpu::FilterMode::Nearest,
            min_filter: wgpu::FilterMode::Nearest,
            mipmap_filter: wgpu::MipmapFilterMode::Nearest,
            lod_max_clamp: 0.0,
            ..Default::default()
        });
        let text_atlas_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            label: Some("SUI text atlas sampler"),
            mag_filter: wgpu::FilterMode::Linear,
            min_filter: wgpu::FilterMode::Linear,
            mipmap_filter: wgpu::MipmapFilterMode::Nearest,
            ..Default::default()
        });
        let text_quad_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
            label: Some("SUI text atlas quad"),
            contents: bytemuck::cast_slice(&TextAtlasQuadVertex::unit_quad()),
            usage: wgpu::BufferUsages::VERTEX,
        });
        let clear_vertex = |x: f32, y: f32| crate::gpu::SolidVertex {
            position: [x, y],
            color: [0.0; 4],
            clip: crate::gpu::NO_CLIP,
        };
        let clear_triangle_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
            label: Some("SUI damage clear triangle"),
            contents: bytemuck::cast_slice(&[
                clear_vertex(-1.0, -1.0),
                clear_vertex(3.0, -1.0),
                clear_vertex(-1.0, 3.0),
            ]),
            usage: wgpu::BufferUsages::VERTEX,
        });
        let analytic_path_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("SUI analytic path bind group layout"),
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Buffer {
                            ty: wgpu::BufferBindingType::Storage { read_only: true },
                            has_dynamic_offset: false,
                            min_binding_size: None,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Buffer {
                            ty: wgpu::BufferBindingType::Storage { read_only: true },
                            has_dynamic_offset: false,
                            min_binding_size: None,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 2,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Buffer {
                            ty: wgpu::BufferBindingType::Storage { read_only: true },
                            has_dynamic_offset: false,
                            min_binding_size: None,
                        },
                        count: None,
                    },
                ],
            });
        let fragment_translation_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("SUI fragment translation bind group layout"),
                entries: &[wgpu::BindGroupLayoutEntry {
                    binding: 0,
                    visibility: wgpu::ShaderStages::VERTEX,
                    ty: wgpu::BindingType::Buffer {
                        ty: wgpu::BufferBindingType::Uniform,
                        has_dynamic_offset: true,
                        min_binding_size: wgpu::BufferSize::new(
                            crate::resources::FRAGMENT_TRANSLATION_SIZE,
                        ),
                    },
                    count: None,
                }],
            });
        let output_transform_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("SUI output transform bind group layout"),
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Texture {
                            sample_type: wgpu::TextureSampleType::Float { filterable: false },
                            view_dimension: wgpu::TextureViewDimension::D2,
                            multisampled: false,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Buffer {
                            ty: wgpu::BufferBindingType::Uniform,
                            has_dynamic_offset: false,
                            min_binding_size: None,
                        },
                        count: None,
                    },
                ],
            });

        let dual_source_blending_enabled = device
            .features()
            .contains(wgpu::Features::DUAL_SOURCE_BLENDING);

        Self {
            offscreen: false,
            collect_pipeline_timings: true,
            pipeline_create_time_us: 0,
            pipeline_create_count: 0,
            adapter,
            device,
            queue,
            pipelines: HashMap::new(),
            sdr_fit: crate::output::SdrFit::default(),
            image_bind_group_layout,
            text_atlas_array_bind_group_layout,
            analytic_path_bind_group_layout,
            fragment_translation_bind_group_layout,
            output_transform_bind_group_layout,
            image_linear_sampler,
            image_nearest_sampler,
            text_atlas_sampler,
            text_quad_buffer,
            clear_triangle_buffer,
            dual_source_blending_enabled,
        }
    }
}
impl WgpuRenderer {
    /// Start offscreen device preparation while the host constructs/layouts its
    /// first frame. Desktop hosts should use `prepare_window` for surface-aware
    /// adapter selection. Other targets retain their existing initialization path.
    pub fn prepare_device(&mut self) {
        #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
        self.start_device_preparation(None, None);
    }

    #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
    pub(crate) fn start_device_preparation(
        &mut self,
        window: Option<sui_core::WindowId>,
        surface: Option<std::sync::Arc<wgpu::Surface<'static>>>,
    ) {
        if self.shared.is_some() || self.device_preparation.is_some() {
            return;
        }
        let instance = self.instance.clone();
        let cancelled = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
        let cancellation = cancelled.clone();
        let task = std::thread::Builder::new()
            .name("sui-gpu-prepare".into())
            .spawn(move || {
                let started = web_time::Instant::now();
                let shared =
                    Self::acquire_shared(&instance, surface.as_deref(), Some(&cancellation))?;
                // As for synchronous preparation, at least a microsecond marks
                // the frame that prepared the device, even one it only took
                // from the shared device in under a microsecond.
                Ok((shared, (started.elapsed().as_micros() as u64).max(1)))
            });
        // A host that cannot spawn another thread can still initialize normally.
        if let Ok(thread) = task {
            self.device_preparation = Some(DevicePreparation {
                window,
                cancelled,
                thread: Some(thread),
            });
        }
    }

    pub(crate) fn install_shared(&mut self, mut shared: SharedRenderer) {
        shared.collect_pipeline_timings = self.runtime_diagnostics_enabled;
        if let Some(registry) = &self.external_texture_registry {
            registry.attach(
                shared.device.clone(),
                shared.queue.clone(),
                shared.adapter.get_info(),
            );
        }
        self.shared = Some(shared);
    }

    pub(crate) fn ensure_shared(
        &mut self,
        compatible_surface: Option<&wgpu::Surface<'_>>,
    ) -> Result<()> {
        if self.shared.is_some() {
            return Ok(());
        }

        #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
        if let Some(preparation) = self.device_preparation.take() {
            let started = web_time::Instant::now();
            let (shared, work_us) = preparation.finish()?;
            if self.runtime_diagnostics_enabled {
                self.pending_device_prepare_time_us += work_us;
                self.pending_device_wait_time_us += started.elapsed().as_micros() as u64;
            }
            if compatible_surface.is_none_or(|surface| shared.adapter.is_surface_supported(surface))
            {
                self.install_shared(shared);
                return Ok(());
            }
            // An offscreen preparation may be followed by a native window. If
            // it needs a different adapter, retry with that actual surface.
        }

        let started = self
            .runtime_diagnostics_enabled
            .then(web_time::Instant::now);
        let shared = Self::acquire_shared(&self.instance, compatible_surface, None)?;
        self.install_shared(shared);
        if let Some(started) = started {
            // At least a microsecond marks the frame that prepared the
            // device, even one it only took from the shared device.
            let elapsed = (started.elapsed().as_micros() as u64).max(1);
            self.pending_device_prepare_time_us += elapsed;
            self.pending_device_wait_time_us += elapsed;
        }
        Ok(())
    }

    /// A device for this renderer. Renderers without a window share one,
    /// with the pipelines compiled on it: acquiring a device and compiling
    /// pipelines takes most of a second, which each offscreen renderer, such
    /// as a headless test's or a capture's, would otherwise pay again.
    fn acquire_shared(
        instance: &wgpu::Instance,
        compatible_surface: Option<&wgpu::Surface<'_>>,
        cancelled: Option<&std::sync::atomic::AtomicBool>,
    ) -> Result<SharedRenderer> {
        #[cfg(not(target_arch = "wasm32"))]
        if compatible_surface.is_none() {
            let mut offscreen = OFFSCREEN
                .lock()
                .unwrap_or_else(std::sync::PoisonError::into_inner);
            if let Some(shared) = offscreen.as_ref() {
                return Ok(shared.clone());
            }
            let mut shared = Self::acquire_device(instance, None, cancelled)?;
            shared.offscreen = true;
            *offscreen = Some(shared.clone());
            return Ok(shared);
        }
        Self::acquire_device(instance, compatible_surface, cancelled)
    }

    fn acquire_device(
        instance: &wgpu::Instance,
        compatible_surface: Option<&wgpu::Surface<'_>>,
        cancelled: Option<&std::sync::atomic::AtomicBool>,
    ) -> Result<SharedRenderer> {
        let check_cancelled = || {
            if cancelled
                .is_some_and(|cancelled| cancelled.load(std::sync::atomic::Ordering::Acquire))
            {
                Err(Error::new("GPU device preparation cancelled"))
            } else {
                Ok(())
            }
        };
        check_cancelled()?;
        #[cfg(target_os = "windows")]
        let preferred = Self::preferred_windows_adapter(instance, compatible_surface);
        #[cfg(not(target_os = "windows"))]
        let preferred = None;
        let adapter = match preferred {
            Some(adapter) => adapter,
            None => pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::HighPerformance,
                force_fallback_adapter: false,
                compatible_surface,
                apply_limit_buckets: false,
            }))
            .map_err(|error| Error::new(format!("failed to acquire wgpu adapter: {error}")))?,
        };

        check_cancelled()?;
        let required_features = optional_renderer_features(&adapter);
        let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
            label: Some("SUI renderer device"),
            required_features,
            required_limits: adapter.limits(),
            ..Default::default()
        }))
        .map_err(|error| Error::new(format!("failed to create wgpu device: {error}")))?;

        check_cancelled()?;
        Ok(SharedRenderer::new(adapter, device, queue))
    }

    #[cfg(target_os = "windows")]
    fn preferred_windows_adapter(
        instance: &wgpu::Instance,
        surface: Option<&wgpu::Surface<'_>>,
    ) -> Option<wgpu::Adapter> {
        // Prefer the native presentation backend. NVIDIA's Vulkan FIFO path can
        // spend multiple refresh intervals acquiring images during window moves;
        // DX12 also supports our native scRGB swapchain configuration directly.
        // Explicit backend selection and machines without a compatible DX12 GPU
        // continue through wgpu's normal adapter selection/fallback path.
        if std::env::var_os("WGPU_BACKEND").is_some() {
            return None;
        }
        pollster::block_on(instance.enumerate_adapters(wgpu::Backends::DX12))
            .into_iter()
            .filter(|adapter| surface.is_none_or(|surface| adapter.is_surface_supported(surface)))
            .filter_map(|adapter| {
                let info = adapter.get_info();
                windows_adapter_rank(info.backend, info.device_type).map(|rank| (rank, adapter))
            })
            .min_by_key(|(rank, _)| *rank)
            .map(|(_, adapter)| adapter)
    }

    #[cfg(target_arch = "wasm32")]
    pub async fn initialize_async(
        &mut self,
        compatible_surface: Option<&wgpu::Surface<'_>>,
    ) -> Result<()> {
        if self.shared.is_some() {
            return Ok(());
        }

        let adapter = self
            .instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::None,
                force_fallback_adapter: false,
                compatible_surface,
                apply_limit_buckets: false,
            })
            .await
            .map_err(|error| Error::new(format!("failed to acquire wgpu adapter: {error}")))?;

        let required_features = optional_renderer_features(&adapter);
        let (device, queue) = adapter
            .request_device(&wgpu::DeviceDescriptor {
                label: Some("SUI renderer device"),
                required_features,
                required_limits: adapter.limits(),
                ..Default::default()
            })
            .await
            .map_err(|error| Error::new(format!("failed to create wgpu device: {error}")))?;

        self.install_shared(SharedRenderer::new(adapter, device, queue));

        Ok(())
    }
}

#[cfg(any(target_os = "windows", test))]
fn windows_adapter_rank(backend: wgpu::Backend, device_type: wgpu::DeviceType) -> Option<u8> {
    if backend != wgpu::Backend::Dx12 {
        return None;
    }
    match device_type {
        wgpu::DeviceType::DiscreteGpu => Some(0),
        wgpu::DeviceType::IntegratedGpu => Some(1),
        wgpu::DeviceType::VirtualGpu => Some(2),
        wgpu::DeviceType::Cpu | wgpu::DeviceType::Other => None,
    }
}

/// Build the renderer's wgpu instance with the GL backend left out unless the
/// environment explicitly asks for it (`WGPU_BACKEND=gl`).
///
/// Initializing the GL/WGL backend spins up a device thread per instance, and
/// concurrent initialization — one renderer per test in the headless harness —
/// deadlocks inside some Windows OpenGL drivers (observed as all test threads
/// parked on `wgl::create_instance_device` results while the creator threads
/// sat inside `nvoglv64.dll`; the same churn also produces access-violation
/// crashes). The primary native backends (Vulkan/Metal/DX12) cover every
/// platform SUI supports, so GL is opt-in rather than eagerly probed.
pub(crate) fn default_wgpu_instance() -> wgpu::Instance {
    let mut descriptor = wgpu::InstanceDescriptor::new_without_display_handle_from_env();
    if std::env::var_os("WGPU_BACKEND").is_none() {
        descriptor.backends -= wgpu::Backends::GL;
    }
    wgpu::Instance::new(descriptor)
}

/// The device renderers without a window share, and the pipelines compiled
/// on it so far.
#[cfg(not(target_arch = "wasm32"))]
static OFFSCREEN: std::sync::Mutex<Option<SharedRenderer>> = std::sync::Mutex::new(None);

/// Keep a pipeline an offscreen renderer compiled for the renderers after it.
pub(crate) fn share_offscreen_pipeline(
    key: crate::gpu::PipelineKey,
    pipeline: &wgpu::RenderPipeline,
) {
    #[cfg(not(target_arch = "wasm32"))]
    if let Some(shared) = OFFSCREEN
        .lock()
        .unwrap_or_else(std::sync::PoisonError::into_inner)
        .as_mut()
    {
        shared
            .pipelines
            .entry(key)
            .or_insert_with(|| pipeline.clone());
    }
    #[cfg(target_arch = "wasm32")]
    let _ = (key, pipeline);
}

#[cfg(test)]
mod tests {
    #[test]
    #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
    fn preparation_failure_is_reported_without_installing_a_device() {
        use std::sync::{Arc, atomic::AtomicBool};
        let mut renderer = super::WgpuRenderer::new();
        renderer.device_preparation = Some(super::DevicePreparation {
            window: None,
            cancelled: Arc::new(AtomicBool::new(false)),
            thread: Some(std::thread::spawn(|| {
                Err(sui_core::Error::new("expected device failure"))
            })),
        });
        let id = renderer
            .device_preparation
            .as_ref()
            .unwrap()
            .thread
            .as_ref()
            .unwrap()
            .thread()
            .id();
        renderer.prepare_device();
        assert_eq!(
            renderer
                .device_preparation
                .as_ref()
                .unwrap()
                .thread
                .as_ref()
                .unwrap()
                .thread()
                .id(),
            id
        );
        assert!(
            renderer
                .ensure_shared(None)
                .unwrap_err()
                .to_string()
                .contains("expected device failure")
        );
        assert!(renderer.shared.is_none());
        assert!(renderer.device_preparation.is_none());
    }

    #[test]
    #[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
    fn removing_a_prepared_window_and_dropping_renderer_cancel_pending_work() {
        use std::sync::{
            Arc,
            atomic::{AtomicBool, Ordering},
            mpsc,
        };
        for remove_window in [false, true] {
            let mut renderer = super::WgpuRenderer::new();
            let cancelled = Arc::new(AtomicBool::new(false));
            let observed = cancelled.clone();
            let (resume, resumed) = mpsc::channel();
            let (done, completed) = mpsc::channel();
            let window = sui_core::WindowId::new(8962);
            renderer.device_preparation = Some(super::DevicePreparation {
                window: Some(window),
                cancelled,
                thread: Some(std::thread::spawn(move || {
                    resumed.recv().unwrap();
                    done.send(observed.load(Ordering::Acquire)).unwrap();
                    Err(sui_core::Error::new("cancelled test preparation"))
                })),
            });
            if remove_window {
                renderer.remove_window(window);
            }
            drop(renderer);
            resume.send(()).unwrap();
            assert!(
                completed
                    .recv_timeout(std::time::Duration::from_secs(5))
                    .unwrap()
            );
        }
    }

    #[test]
    fn windows_preference_selects_hardware_dx12_without_forcing_software_rendering() {
        use wgpu::{
            Backend::Dx12,
            DeviceType::{Cpu, DiscreteGpu, IntegratedGpu},
        };
        let discrete = super::windows_adapter_rank(Dx12, DiscreteGpu).unwrap();
        assert!(super::windows_adapter_rank(Dx12, IntegratedGpu).unwrap() > discrete);
        assert_eq!(super::windows_adapter_rank(Dx12, Cpu), None);
        assert_eq!(
            super::windows_adapter_rank(wgpu::Backend::Vulkan, DiscreteGpu),
            None
        );
    }
}