Skip to content

Commit 0dbe5fb

Browse files
cwfitzgeraldErichDonGubler
authored andcommitted
Add annotations for the types hal types return
1 parent 81b3e7c commit 0dbe5fb

File tree

13 files changed

+237
-14
lines changed

13 files changed

+237
-14
lines changed

wgpu-hal/src/gles/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ pub use fence::Fence;
101101
#[cfg(not(any(windows, webgl)))]
102102
pub use self::egl::{AdapterContext, AdapterContextLock};
103103
#[cfg(not(any(windows, webgl)))]
104-
use self::egl::{Instance, Surface};
104+
pub use self::egl::{Instance, Surface};
105105

106106
#[cfg(webgl)]
107107
pub use self::web::AdapterContext;
108108
#[cfg(webgl)]
109-
use self::web::{Instance, Surface};
109+
pub use self::web::{Instance, Surface};
110110

111111
#[cfg(windows)]
112112
use self::wgl::AdapterContext;
113113
#[cfg(windows)]
114-
use self::wgl::{Instance, Surface};
114+
pub use self::wgl::{Instance, Surface};
115115

116116
use alloc::{boxed::Box, string::String, string::ToString as _, sync::Arc, vec::Vec};
117117
use core::{

wgpu/src/api/adapter.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ impl Adapter {
6666
}
6767
}
6868

69-
/// Create a wgpu [`Device`] and [`Queue`] from a wgpu-hal `OpenDevice`
69+
/// Create a wgpu [`Device`] and [`Queue`] from a wgpu-hal [`hal::OpenDevice`].
7070
///
7171
/// # Safety
7272
///
7373
/// - `hal_device` must be created from this adapter internal handle.
74-
/// - `desc.features` must be a subset of `hal_device` features.
74+
/// - `desc.features` must be a subset of `hal_device`'s supported features.
7575
#[cfg(wgpu_core)]
7676
pub unsafe fn create_device_from_hal<A: wgc::hal_api::HalApi>(
7777
&self,
@@ -103,6 +103,15 @@ impl Adapter {
103103
/// Returns a guard that dereferences to the type of the hal backend
104104
/// which implements [`A::Adapter`].
105105
///
106+
/// # Types
107+
///
108+
/// The returned type depends on the backend:
109+
///
110+
#[doc = crate::hal_type_vulkan!("Adapter")]
111+
#[doc = crate::hal_type_metal!("Adapter")]
112+
#[doc = crate::hal_type_dx12!("Adapter")]
113+
#[doc = crate::hal_type_gles!("Adapter")]
114+
///
106115
/// # Errors
107116
///
108117
/// This method will return None if:

wgpu/src/api/blas.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ impl Blas {
162162
/// Returns a guard that dereferences to the type of the hal backend
163163
/// which implements [`A::AccelerationStructure`].
164164
///
165+
/// # Types
166+
///
167+
/// The returned type depends on the backend:
168+
///
169+
#[doc = crate::hal_type_vulkan!("AccelerationStructure")]
170+
#[doc = crate::hal_type_metal!("AccelerationStructure")]
171+
#[doc = crate::hal_type_dx12!("AccelerationStructure")]
172+
#[doc = crate::hal_type_gles!("AccelerationStructure")]
173+
///
165174
/// # Deadlocks
166175
///
167176
/// - The returned guard holds a read-lock on a device-local "destruction"

wgpu/src/api/buffer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ impl Buffer {
208208
/// Returns a guard that dereferences to the type of the hal backend
209209
/// which implements [`A::Buffer`].
210210
///
211+
/// # Types
212+
///
213+
/// The returned type depends on the backend:
214+
///
215+
#[doc = crate::hal_type_vulkan!("Buffer")]
216+
#[doc = crate::hal_type_metal!("Buffer")]
217+
#[doc = crate::hal_type_dx12!("Buffer")]
218+
#[doc = crate::hal_type_gles!("Buffer")]
219+
///
211220
/// # Deadlocks
212221
///
213222
/// - The returned guard holds a read-lock on a device-local "destruction"

wgpu/src/api/command_encoder.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,31 @@ impl CommandEncoder {
232232
);
233233
}
234234

235-
/// Returns the inner hal CommandEncoder using a callback. The hal command encoder will be `None` if the
236-
/// backend type argument does not match with this wgpu CommandEncoder
235+
/// Get the [`wgpu_hal`] command encoder from this `CommandEncoder`.
237236
///
238-
/// This method will start the wgpu_core level command recording.
237+
/// The returned command encoder will be ready to record onto.
238+
///
239+
/// # Errors
240+
///
241+
/// This method will pass in [`None`] if:
242+
/// - The encoder is not from the backend specified by `A`.
243+
/// - The encoder is from the `webgpu` or `custom` backend.
244+
///
245+
/// # Types
246+
///
247+
/// The callback argument depends on the backend:
248+
///
249+
#[doc = crate::hal_type_vulkan!("CommandEncoder")]
250+
#[doc = crate::hal_type_metal!("CommandEncoder")]
251+
#[doc = crate::hal_type_dx12!("CommandEncoder")]
252+
#[doc = crate::hal_type_gles!("CommandEncoder")]
239253
///
240254
/// # Safety
241255
///
242-
/// - The raw handle obtained from the hal CommandEncoder must not be manually destroyed
256+
/// - The raw handle obtained from the `A::CommandEncoder` must not be manually destroyed.
257+
/// - You must not end the command buffer; wgpu will do it when you call finish.
258+
/// - The wgpu command encoder must not be interacted with in any way while recording is
259+
/// happening to the wgpu_hal or backend command encoder.
243260
#[cfg(wgpu_core)]
244261
pub unsafe fn as_hal_mut<
245262
A: wgc::hal_api::HalApi,

wgpu/src/api/device.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ impl Device {
289289

290290
/// Creates a [`Texture`] from a wgpu-hal Texture.
291291
///
292+
/// # Types
293+
///
294+
/// The type of `A::Texture` depends on the backend:
295+
///
296+
#[doc = crate::hal_type_vulkan!("Texture")]
297+
#[doc = crate::hal_type_metal!("Texture")]
298+
#[doc = crate::hal_type_dx12!("Texture")]
299+
#[doc = crate::hal_type_gles!("Texture")]
300+
///
292301
/// # Safety
293302
///
294303
/// - `hal_texture` must be created from this device internal handle
@@ -319,6 +328,15 @@ impl Device {
319328

320329
/// Creates a [`Buffer`] from a wgpu-hal Buffer.
321330
///
331+
/// # Types
332+
///
333+
/// The type of `A::Buffer` depends on the backend:
334+
///
335+
#[doc = crate::hal_type_vulkan!("Buffer")]
336+
#[doc = crate::hal_type_metal!("Buffer")]
337+
#[doc = crate::hal_type_dx12!("Buffer")]
338+
#[doc = crate::hal_type_gles!("Buffer")]
339+
///
322340
/// # Safety
323341
///
324342
/// - `hal_buffer` must be created from this device internal handle
@@ -473,6 +491,15 @@ impl Device {
473491
/// Returns a guard that dereferences to the type of the hal backend
474492
/// which implements [`A::Device`].
475493
///
494+
/// # Types
495+
///
496+
/// The returned type depends on the backend:
497+
///
498+
#[doc = crate::hal_type_vulkan!("Device")]
499+
#[doc = crate::hal_type_metal!("Device")]
500+
#[doc = crate::hal_type_dx12!("Device")]
501+
#[doc = crate::hal_type_gles!("Device")]
502+
///
476503
/// # Errors
477504
///
478505
/// This method will return None if:

wgpu/src/api/instance.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,24 @@ impl Instance {
307307
/// Interop with wgpu-hal.
308308
#[cfg(wgpu_core)]
309309
impl Instance {
310-
/// Create an new instance of wgpu from a wgpu-hal instance.
310+
/// Create an new instance of wgpu from a wgpu-hal instance. This is often useful
311+
/// when you need to do backend specific logic, or interop with an existing backend
312+
/// instance.
311313
///
312-
/// # Arguments
314+
/// # Types
315+
///
316+
/// The type of `A::Instance` depends on the backend:
313317
///
314-
/// - `hal_instance` - wgpu-hal instance.
318+
#[doc = crate::hal_type_vulkan!("Instance")]
319+
#[doc = crate::hal_type_metal!("Instance")]
320+
#[doc = crate::hal_type_dx12!("Instance")]
321+
#[doc = crate::hal_type_gles!("Instance")]
315322
///
316323
/// # Safety
317324
///
318-
/// Refer to the creation of wgpu-hal Instance for every backend.
325+
/// - The `hal_instance` must be a valid and usable instance of the backend specified by `A`.
326+
/// - wgpu will act like it has complete ownership of this instance, and will destroy it
327+
/// when the last reference to the instance, internal or external, is dropped.
319328
pub unsafe fn from_hal<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self {
320329
Self {
321330
inner: unsafe {
@@ -332,6 +341,13 @@ impl Instance {
332341
/// Returns a guard that dereferences to the type of the hal backend
333342
/// which implements [`A::Instance`].
334343
///
344+
/// # Types
345+
///
346+
#[doc = crate::hal_type_vulkan!("Instance")]
347+
#[doc = crate::hal_type_metal!("Instance")]
348+
#[doc = crate::hal_type_dx12!("Instance")]
349+
#[doc = crate::hal_type_gles!("Instance")]
350+
///
335351
/// # Errors
336352
///
337353
/// This method will return None if:
@@ -352,7 +368,16 @@ impl Instance {
352368
.and_then(|ctx| unsafe { ctx.instance_as_hal::<A>() })
353369
}
354370

355-
/// Converts a wgpu-hal `ExposedAdapter` to a wgpu [`Adapter`].
371+
/// Converts a wgpu-hal [`hal::ExposedAdapter`] to a wgpu [`Adapter`].
372+
///
373+
/// # Types
374+
///
375+
/// The type of `hal_adapter.adapter` depends on the backend:
376+
///
377+
#[doc = crate::hal_type_vulkan!("Adapter")]
378+
#[doc = crate::hal_type_metal!("Adapter")]
379+
#[doc = crate::hal_type_dx12!("Adapter")]
380+
#[doc = crate::hal_type_gles!("Adapter")]
356381
///
357382
/// # Safety
358383
///

wgpu/src/api/queue.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ impl Queue {
288288
/// Returns a guard that dereferences to the type of the hal backend
289289
/// which implements [`A::Queue`].
290290
///
291+
/// # Types
292+
///
293+
/// The returned type depends on the backend:
294+
///
295+
#[doc = crate::hal_type_vulkan!("Queue")]
296+
#[doc = crate::hal_type_metal!("Queue")]
297+
#[doc = crate::hal_type_dx12!("Queue")]
298+
#[doc = crate::hal_type_gles!("Queue")]
299+
///
291300
/// # Errors
292301
///
293302
/// This method will return None if:

wgpu/src/api/surface.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ impl Surface<'_> {
158158
/// Returns a guard that dereferences to the type of the hal backend
159159
/// which implements [`A::Surface`].
160160
///
161+
/// # Types
162+
///
163+
/// The returned type depends on the backend:
164+
///
165+
#[doc = crate::hal_type_vulkan!("Surface")]
166+
#[doc = crate::hal_type_metal!("Surface")]
167+
#[doc = crate::hal_type_dx12!("Surface")]
168+
#[doc = crate::hal_type_gles!("Surface")]
169+
///
161170
/// # Errors
162171
///
163172
/// This method will return None if:

wgpu/src/api/texture.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ impl Texture {
2727
/// Returns a guard that dereferences to the type of the hal backend
2828
/// which implements [`A::Texture`].
2929
///
30+
/// # Types
31+
///
32+
/// The returned type depends on the backend:
33+
///
34+
#[doc = crate::hal_type_vulkan!("Texture")]
35+
#[doc = crate::hal_type_metal!("Texture")]
36+
#[doc = crate::hal_type_dx12!("Texture")]
37+
#[doc = crate::hal_type_gles!("Texture")]
38+
///
3039
/// # Deadlocks
3140
///
3241
/// - The returned guard holds a read-lock on a device-local "destruction"

0 commit comments

Comments
 (0)