1use crate::{
2 GpuAdapterInfo, GpuBackendKind, GpuCapabilities, GpuError, GpuImageHandle, GpuImageRequest,
3 GpuOptions, GpuRequest, buffer::TransferStats, handles::GpuBufferHandle,
4};
5use std::any::Any;
6#[cfg(feature = "gpu-wgpu")]
7use std::sync::Arc;
8
9pub trait GpuBackend: Send + Sync {
19 fn kind(&self) -> GpuBackendKind;
20 fn adapter_info(&self) -> GpuAdapterInfo;
21 fn capabilities(&self) -> GpuCapabilities;
22 fn select_adapter(&self, opts: &GpuOptions) -> Result<GpuAdapterInfo, GpuError>;
23 fn as_any(&self) -> &dyn Any;
24 fn create_buffer(&self, req: &GpuRequest) -> Result<GpuBufferHandle, GpuError>;
25 fn create_image(&self, req: &GpuImageRequest) -> Result<GpuImageHandle, GpuError>;
26 fn upload_texture(
27 &self,
28 _req: &GpuImageRequest,
29 _data: &[u8],
30 ) -> Result<GpuImageHandle, GpuError> {
31 Err(GpuError::Unsupported)
32 }
33 fn read_texture(&self, _handle: &GpuImageHandle) -> Result<Vec<u8>, GpuError> {
34 Err(GpuError::Unsupported)
35 }
36 fn stats(&self) -> TransferStats {
37 TransferStats::default()
38 }
39 fn take_stats(&self) -> TransferStats {
40 self.stats()
41 }
42 fn record_download(&self, _bytes: u64) {}
43
44 #[cfg(feature = "gpu-wgpu")]
49 fn wgpu_device_queue(&self) -> Option<(&wgpu::Device, &wgpu::Queue)> {
50 None
51 }
52
53 #[cfg(feature = "gpu-wgpu")]
54 fn wgpu_get_texture(&self, _handle: &GpuImageHandle) -> Option<Arc<wgpu::Texture>> {
55 None
56 }
57
58 #[cfg(feature = "gpu-wgpu")]
59 fn wgpu_register_texture(
60 &self,
61 _texture: Arc<wgpu::Texture>,
62 _format: wgpu::TextureFormat,
63 _width: u32,
64 _height: u32,
65 _usage: wgpu::TextureUsages,
66 ) -> Option<GpuImageHandle> {
67 None
68 }
69}
70
71pub trait GpuContext: Send + Sync {
81 fn backend(&self) -> GpuBackendKind;
82 fn adapter_info(&self) -> GpuAdapterInfo;
83 fn capabilities(&self) -> GpuCapabilities;
84 fn stats(&self) -> TransferStats {
85 TransferStats::default()
86 }
87 fn take_stats(&self) -> TransferStats {
88 self.stats()
89 }
90 fn record_download(&self, _bytes: u64) {}
91}