Files
Graphite/node-graph/wgpu-executor/src/context.rs
0HyperCube 6f6fb3bcd4 Upgrade several Rust dependencies (#1613)
`specta` from Hypercube's fork commit to latest upstream commit
`wasm-bindgen` 0.2.87 -> 0.2.91
`spirv-std` from 0.9 to not-yet-merged commit in https://github.com/EmbarkStudios/rust-gpu/pull/1115
`wgpu` 0.17 -> 0.19
`winit` 0.28.6 -> 0.29
`vello` and `vello_svg` from latest upstream commit to not-yet-merged commit in https://github.com/linebender/vello/pull/427
`resvg` 0.36.0 -> 0.39
`glam` 0.24 -> 0.25
`rustybuzz` 0.8.0 -> 0.10.0
`js-sys` and `web-sys` 0.3.55 -> 0.3.67
`usvg` 0.36.0 -> 0.39
`spirv` 0.2.0 -> 0.3

* Update a couple of dependencies

* More test fixing…

* Use upstream Specta instead of fork

* Update comments in Cargo.toml

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
2024-02-17 15:02:41 -08:00

55 lines
1.5 KiB
Rust

use std::sync::Arc;
use wgpu::{Device, Instance, Queue};
#[derive(Debug, Clone)]
pub struct Context {
pub device: Arc<Device>,
pub queue: Arc<Queue>,
pub instance: Arc<Instance>,
pub adapter: Arc<wgpu::Adapter>,
}
impl Context {
pub async fn new() -> Option<Self> {
// Instantiates instance of WebGPU
let instance_descriptor = wgpu::InstanceDescriptor {
backends: wgpu::Backends::VULKAN | wgpu::Backends::BROWSER_WEBGPU,
..Default::default()
};
let instance = wgpu::Instance::new(instance_descriptor);
// `request_adapter` instantiates the general connection to the GPU
let adapter = instance.request_adapter(&wgpu::RequestAdapterOptions::default()).await?;
let required_limits = adapter.limits();
// `request_device` instantiates the feature specific connection to the GPU, defining some parameters,
// `features` being the available features.
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
label: None,
#[cfg(not(feature = "passthrough"))]
required_features: wgpu::Features::empty(),
#[cfg(feature = "passthrough")]
required_features: wgpu::Features::SPIRV_SHADER_PASSTHROUGH,
required_limits,
},
None,
)
.await
.unwrap();
let info = adapter.get_info();
// skip this on LavaPipe temporarily
if info.vendor == 0x10005 {
return None;
}
Some(Self {
device: Arc::new(device),
queue: Arc::new(queue),
adapter: Arc::new(adapter),
instance: Arc::new(instance),
})
}
}