1#![allow(unexpected_cfgs, dead_code, unreachable_patterns)]
2
3mod backend;
4mod compat;
5mod dispatch;
6mod error;
7mod future;
8mod mapping;
9mod types;
10
11pub use compat::{Compat, CompatTexture, WgpuCompatError};
12
13#[cfg(feature = "wire")]
14pub mod wire_backend;
15
16#[cfg(not(feature = "wire"))]
17pub fn create_instance(desc: &wgpu::InstanceDescriptor) -> wgpu::Instance {
18 use wgpu::custom::InstanceInterface;
19 let custom = types::DawnInstance::new(desc);
20 wgpu::Instance::from_custom(custom)
21}
22
23#[cfg(feature = "wire")]
24pub fn create_instance(_desc: &wgpu::InstanceDescriptor) -> wgpu::Instance {
25 let socket_name = std::env::var("DAWN_WGPU_WIRE_SOCKET")
26 .unwrap_or_else(|_| "dawn-wgpu-wire-default".to_string());
27 let connect_attempts = std::env::var("DAWN_WGPU_WIRE_CONNECT_ATTEMPTS")
28 .ok()
29 .and_then(|v| v.parse::<usize>().ok())
30 .unwrap_or(5);
31 let connect_delay_ms = std::env::var("DAWN_WGPU_WIRE_CONNECT_DELAY_MS")
32 .ok()
33 .and_then(|v| v.parse::<u64>().ok())
34 .unwrap_or(10);
35 let opts = wire_backend::WireInitOptions {
36 reserve_surface: true,
37 connect_attempts,
38 connect_delay: std::time::Duration::from_millis(connect_delay_ms),
39 };
40 create_wire_instance_with_options(&socket_name, opts).unwrap_or_else(|err| {
41 panic!("wire feature enabled: failed to create wire instance (socket={socket_name}): {err}")
42 })
43}
44
45#[cfg(feature = "wire")]
46fn create_wire_instance_with_options(
47 name: &str,
48 opts: wire_backend::WireInitOptions,
49) -> Result<wgpu::Instance, wire_backend::WireBackendError> {
50 let backend = wire_backend::IpcWireBackend::connect_name_with_options(name, opts)?;
51 let (instance, handle) = backend.into_instance_and_handle();
52 let custom = types::DawnInstance {
53 inner: types::SendSync::new(instance),
54 wire_handle: Some(handle),
55 };
56 Ok(wgpu::Instance::from_custom(custom))
57}