Skip to main content

vyre_driver_wgpu/
executable_api.rs

1use crate::{pipeline, WgpuBackend};
2
3/// Progressive staging: `Program -> WgpuIR -> WGSL -> pipeline`.
4///
5/// `WgpuIR` is the intermediate artifact returned by
6/// [`WgpuBackend::compile`]. Each downstream stage (WGSL emission,
7/// pipeline creation) is independently cacheable and testable.
8pub struct WgpuIR {
9    /// Cached pipeline that already embeds the naga::Module, WGSL
10    /// shader source, bind-group layout, and workgroup size.
11    pub pipeline: pipeline::WgpuPipeline,
12}
13
14impl vyre_driver::Executable for WgpuBackend {
15    fn dispatch(
16        &self,
17        program: &vyre_foundation::ir::Program,
18        inputs: &[vyre_driver::MemoryRef<'_>],
19        config: &vyre_driver::DispatchConfig,
20    ) -> Result<Vec<vyre_driver::Memory>, vyre_driver::BackendError> {
21        <Self as vyre_driver::VyreBackend>::dispatch_borrowed(self, program, inputs, config)
22    }
23}
24
25impl WgpuBackend {
26    /// Compile a program once for repeated dispatch.
27    pub fn compile(
28        &self,
29        program: &vyre_foundation::ir::Program,
30    ) -> Result<WgpuIR, vyre_driver::BackendError> {
31        let config = vyre_driver::DispatchConfig::default();
32        self.validate_with_cache(program)?;
33        let pipeline = crate::pipeline::WgpuPipeline::compile_with_device_queue(
34            program,
35            &config,
36            self.adapter_info.clone(),
37            self.enabled_features,
38            self.current_device_queue(),
39            self.dispatch_arena_snapshot(),
40            self.current_persistent_pool(),
41            self.pipeline_cache.clone(),
42            self.bind_group_layout_cache.clone(),
43        )?;
44        Ok(WgpuIR {
45            pipeline: (*pipeline).clone(),
46        })
47    }
48
49    /// Dispatch a previously compiled program artifact.
50    pub fn dispatch_compiled(
51        &self,
52        compiled: &WgpuIR,
53        inputs: &[vyre_driver::MemoryRef<'_>],
54        config: &vyre_driver::DispatchConfig,
55    ) -> Result<Vec<vyre_driver::Memory>, vyre_driver::BackendError> {
56        vyre_driver::CompiledPipeline::dispatch_borrowed(&compiled.pipeline, inputs, config)
57    }
58}