Skip to main content

dawn_wgpu/
types.rs

1use dawn_rs::*;
2use std::fmt;
3use std::ops::Deref;
4use std::sync::Arc;
5
6pub struct DawnInstance {
7    pub(crate) inner: Instance,
8    #[cfg(feature = "wire")]
9    pub(crate) wire_handle: Option<Arc<crate::wire_backend::WireBackendHandle>>,
10}
11
12impl DawnInstance {
13    pub(crate) fn from_instance(instance: Instance) -> Self {
14        Self {
15            inner: instance,
16            #[cfg(feature = "wire")]
17            wire_handle: None,
18        }
19    }
20}
21
22impl Clone for DawnInstance {
23    fn clone(&self) -> Self {
24        Self {
25            inner: self.inner.clone(),
26            #[cfg(feature = "wire")]
27            wire_handle: self.wire_handle.clone(),
28        }
29    }
30}
31
32impl fmt::Debug for DawnInstance {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        let mut dbg = f.debug_struct("DawnInstance");
35        dbg.field("inner", &self.inner);
36        #[cfg(feature = "wire")]
37        dbg.field("wire_handle", &self.wire_handle.is_some());
38        dbg.finish()
39    }
40}
41
42#[derive(Debug, Clone)]
43pub struct DawnAdapter {
44    pub(crate) inner: Adapter,
45}
46
47#[derive(Debug, Clone)]
48pub struct DawnDevice {
49    pub(crate) inner: Device,
50}
51
52#[derive(Debug, Clone)]
53pub struct DawnQueue {
54    pub(crate) inner: Queue,
55}
56
57#[derive(Debug, Clone)]
58pub struct DawnShaderModule {
59    pub(crate) inner: ShaderModule,
60}
61
62#[derive(Debug, Clone)]
63pub struct DawnBindGroupLayout {
64    pub(crate) inner: BindGroupLayout,
65}
66
67#[derive(Debug, Clone)]
68pub struct DawnBindGroup {
69    pub(crate) inner: BindGroup,
70}
71
72#[derive(Debug, Clone)]
73pub struct DawnTextureView {
74    pub(crate) inner: TextureView,
75}
76
77#[derive(Debug, Clone)]
78pub struct DawnSampler {
79    pub(crate) inner: Sampler,
80}
81
82#[derive(Debug, Clone)]
83pub struct DawnBuffer {
84    pub(crate) inner: Buffer,
85}
86
87#[derive(Debug, Clone)]
88pub struct DawnTexture {
89    pub(crate) inner: Texture,
90}
91
92#[derive(Debug, Clone)]
93pub struct DawnExternalTexture {
94    pub(crate) inner: ExternalTexture,
95}
96
97#[derive(Debug, Clone)]
98pub struct DawnQuerySet {
99    pub(crate) inner: QuerySet,
100}
101
102#[derive(Debug, Clone)]
103pub struct DawnPipelineLayout {
104    pub(crate) inner: PipelineLayout,
105}
106
107#[derive(Debug, Clone)]
108pub struct DawnRenderPipeline {
109    pub(crate) inner: RenderPipeline,
110}
111
112#[derive(Debug, Clone)]
113pub struct DawnComputePipeline {
114    pub(crate) inner: ComputePipeline,
115}
116
117#[derive(Debug)]
118pub struct DawnCommandEncoder {
119    pub(crate) inner: CommandEncoder,
120}
121
122#[derive(Debug)]
123pub struct DawnComputePass {
124    pub(crate) inner: ComputePassEncoder,
125    pub(crate) ended: bool,
126}
127
128#[derive(Debug)]
129pub struct DawnRenderPass {
130    pub(crate) inner: RenderPassEncoder,
131    pub(crate) ended: bool,
132}
133
134#[derive(Debug)]
135pub struct DawnCommandBuffer {
136    pub(crate) inner: CommandBuffer,
137}
138
139#[derive(Debug)]
140pub struct DawnRenderBundleEncoder {
141    pub(crate) inner: RenderBundleEncoder,
142}
143
144#[derive(Debug, Clone)]
145pub struct DawnRenderBundle {
146    pub(crate) inner: RenderBundle,
147}
148
149#[cfg(target_os = "macos")]
150#[derive(Debug)]
151pub struct MetalLayerHandle {
152    pub(crate) ptr: *mut std::ffi::c_void,
153}
154
155#[cfg(target_os = "macos")]
156unsafe impl Send for MetalLayerHandle {}
157#[cfg(target_os = "macos")]
158unsafe impl Sync for MetalLayerHandle {}
159
160#[cfg(target_os = "macos")]
161impl Drop for MetalLayerHandle {
162    fn drop(&mut self) {
163        if self.ptr.is_null() {
164            return;
165        }
166        unsafe {
167            let ptr = self.ptr.cast::<objc2_quartz_core::CAMetalLayer>();
168            let _ = objc2::rc::Retained::from_raw(ptr);
169        }
170    }
171}
172
173#[derive(Debug, Clone)]
174pub struct DawnSurface {
175    pub(crate) inner: Surface,
176    #[cfg(target_os = "macos")]
177    pub(crate) metal_layer: Option<Arc<MetalLayerHandle>>,
178}
179
180#[derive(Debug, Clone)]
181pub struct DawnSurfaceOutputDetail {
182    pub(crate) surface: Surface,
183}
184
185#[derive(Debug)]
186pub struct DawnQueueWriteBuffer {
187    pub(crate) inner: Vec<u8>,
188}
189
190#[derive(Debug)]
191pub struct DawnBufferMappedRange {
192    pub(crate) data: *mut u8,
193    pub(crate) size: usize,
194}
195
196unsafe impl Send for DawnBufferMappedRange {}
197unsafe impl Sync for DawnBufferMappedRange {}
198
199#[derive(Debug)]
200pub struct DawnPipelineCache;
201
202#[derive(Debug)]
203pub struct DawnBlas;
204
205#[derive(Debug)]
206pub struct DawnTlas;
207
208macro_rules! impl_deref_to_inner {
209    ($name:ident, $target:ty) => {
210        impl Deref for $name {
211            type Target = $target;
212
213            fn deref(&self) -> &Self::Target {
214                &self.inner
215            }
216        }
217    };
218}
219
220impl_deref_to_inner!(DawnInstance, Instance);
221impl_deref_to_inner!(DawnAdapter, Adapter);
222impl_deref_to_inner!(DawnDevice, Device);
223impl_deref_to_inner!(DawnQueue, Queue);
224impl_deref_to_inner!(DawnShaderModule, ShaderModule);
225impl_deref_to_inner!(DawnBindGroupLayout, BindGroupLayout);
226impl_deref_to_inner!(DawnBindGroup, BindGroup);
227impl_deref_to_inner!(DawnTextureView, TextureView);
228impl_deref_to_inner!(DawnSampler, Sampler);
229impl_deref_to_inner!(DawnBuffer, Buffer);
230impl_deref_to_inner!(DawnTexture, Texture);
231impl_deref_to_inner!(DawnExternalTexture, ExternalTexture);
232impl_deref_to_inner!(DawnQuerySet, QuerySet);
233impl_deref_to_inner!(DawnPipelineLayout, PipelineLayout);
234impl_deref_to_inner!(DawnRenderPipeline, RenderPipeline);
235impl_deref_to_inner!(DawnComputePipeline, ComputePipeline);
236impl_deref_to_inner!(DawnCommandEncoder, CommandEncoder);
237impl_deref_to_inner!(DawnComputePass, ComputePassEncoder);
238impl_deref_to_inner!(DawnRenderPass, RenderPassEncoder);
239impl_deref_to_inner!(DawnCommandBuffer, CommandBuffer);
240impl_deref_to_inner!(DawnRenderBundleEncoder, RenderBundleEncoder);
241impl_deref_to_inner!(DawnRenderBundle, RenderBundle);
242impl_deref_to_inner!(DawnSurface, Surface);