Download node-graph/wgpu-executor/src/context.rs from openfree/graphite2: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/openfree/graphite2/resolve/main/node-graph/wgpu-executor/src/context.rs
- Command line
-
hf download hf://spaces/openfree/graphite2/node-graph/wgpu-executor/src/context.rs
-
curl -L -o context.rs https://huggingface.co/spaces/openfree/graphite2/resolve/main/node-graph/wgpu-executor/src/context.rs
1.81 kB
| use std::sync::Arc; | |
| use wgpu::{Device, Instance, Queue}; | |
| 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::all(), | |
| ..Default::default() | |
| }; | |
| let instance = Instance::new(instance_descriptor); | |
| let adapter_options = wgpu::RequestAdapterOptions { | |
| power_preference: wgpu::PowerPreference::HighPerformance, | |
| compatible_surface: None, | |
| force_fallback_adapter: false, | |
| }; | |
| // `request_adapter` instantiates the general connection to the GPU | |
| let adapter = instance.request_adapter(&adapter_options).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(), | |
| // Currently disabled because not all backend support passthrough. | |
| // TODO: reenable only when vulkan adapter is available | |
| // #[cfg(feature = "passthrough")] | |
| // required_features: wgpu::Features::SPIRV_SHADER_PASSTHROUGH, | |
| required_limits, | |
| memory_hints: Default::default(), | |
| }, | |
| 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), | |
| }) | |
| } | |
| } | |