Skip to content

Commit 1ed6187

Browse files
cwfitzgeraldErichDonGubler
authored andcommitted
Remove wgpu_core::hal_api::HalApi
1 parent 0dbe5fb commit 1ed6187

File tree

24 files changed

+62
-92
lines changed

24 files changed

+62
-92
lines changed

wgpu-core/src/as_hal.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use hal::DynResource;
66
use crate::{
77
device::Device,
88
global::Global,
9-
hal_api::HalApi,
109
id::{
1110
AdapterId, BlasId, BufferId, CommandEncoderId, DeviceId, QueueId, SurfaceId, TextureId,
1211
TextureViewId, TlasId,
@@ -226,7 +225,7 @@ impl Global {
226225
/// # Safety
227226
///
228227
/// - The raw buffer handle must not be manually destroyed
229-
pub unsafe fn buffer_as_hal<A: HalApi>(
228+
pub unsafe fn buffer_as_hal<A: hal::Api>(
230229
&self,
231230
id: BufferId,
232231
) -> Option<impl Deref<Target = A::Buffer>> {
@@ -242,7 +241,7 @@ impl Global {
242241
/// # Safety
243242
///
244243
/// - The raw texture handle must not be manually destroyed
245-
pub unsafe fn texture_as_hal<A: HalApi>(
244+
pub unsafe fn texture_as_hal<A: hal::Api>(
246245
&self,
247246
id: TextureId,
248247
) -> Option<impl Deref<Target = A::Texture>> {
@@ -258,7 +257,7 @@ impl Global {
258257
/// # Safety
259258
///
260259
/// - The raw texture view handle must not be manually destroyed
261-
pub unsafe fn texture_view_as_hal<A: HalApi>(
260+
pub unsafe fn texture_view_as_hal<A: hal::Api>(
262261
&self,
263262
id: TextureViewId,
264263
) -> Option<impl Deref<Target = A::TextureView>> {
@@ -274,7 +273,7 @@ impl Global {
274273
/// # Safety
275274
///
276275
/// - The raw adapter handle must not be manually destroyed
277-
pub unsafe fn adapter_as_hal<A: HalApi>(
276+
pub unsafe fn adapter_as_hal<A: hal::Api>(
278277
&self,
279278
id: AdapterId,
280279
) -> Option<impl Deref<Target = A::Adapter>> {
@@ -291,7 +290,7 @@ impl Global {
291290
/// # Safety
292291
///
293292
/// - The raw device handle must not be manually destroyed
294-
pub unsafe fn device_as_hal<A: HalApi>(
293+
pub unsafe fn device_as_hal<A: hal::Api>(
295294
&self,
296295
id: DeviceId,
297296
) -> Option<impl Deref<Target = A::Device>> {
@@ -305,7 +304,7 @@ impl Global {
305304
/// # Safety
306305
///
307306
/// - The raw fence handle must not be manually destroyed
308-
pub unsafe fn device_fence_as_hal<A: HalApi>(
307+
pub unsafe fn device_fence_as_hal<A: hal::Api>(
309308
&self,
310309
id: DeviceId,
311310
) -> Option<impl Deref<Target = A::Fence>> {
@@ -318,7 +317,7 @@ impl Global {
318317

319318
/// # Safety
320319
/// - The raw surface handle must not be manually destroyed
321-
pub unsafe fn surface_as_hal<A: HalApi>(
320+
pub unsafe fn surface_as_hal<A: hal::Api>(
322321
&self,
323322
id: SurfaceId,
324323
) -> Option<impl Deref<Target = A::Surface>> {
@@ -335,7 +334,7 @@ impl Global {
335334
///
336335
/// - The raw command encoder handle must not be manually destroyed
337336
pub unsafe fn command_encoder_as_hal_mut<
338-
A: HalApi,
337+
A: hal::Api,
339338
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
340339
R,
341340
>(
@@ -363,7 +362,7 @@ impl Global {
363362
/// # Safety
364363
///
365364
/// - The raw queue handle must not be manually destroyed
366-
pub unsafe fn queue_as_hal<A: HalApi>(
365+
pub unsafe fn queue_as_hal<A: hal::Api>(
367366
&self,
368367
id: QueueId,
369368
) -> Option<impl Deref<Target = A::Queue>> {
@@ -377,7 +376,7 @@ impl Global {
377376
/// # Safety
378377
///
379378
/// - The raw blas handle must not be manually destroyed
380-
pub unsafe fn blas_as_hal<A: HalApi>(
379+
pub unsafe fn blas_as_hal<A: hal::Api>(
381380
&self,
382381
id: BlasId,
383382
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
@@ -393,7 +392,7 @@ impl Global {
393392
/// # Safety
394393
///
395394
/// - The raw tlas handle must not be manually destroyed
396-
pub unsafe fn tlas_as_hal<A: HalApi>(
395+
pub unsafe fn tlas_as_hal<A: hal::Api>(
397396
&self,
398397
id: TlasId,
399398
) -> Option<impl Deref<Target = A::AccelerationStructure>> {

wgpu-core/src/device/global.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{
1313
conv,
1414
device::{bgl, life::WaitIdleError, DeviceError, DeviceLostClosure},
1515
global::Global,
16-
hal_api::HalApi,
1716
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
1817
instance::{self, Adapter, Surface},
1918
pipeline::{
@@ -386,7 +385,7 @@ impl Global {
386385
/// - `hal_buffer` must be created respecting `desc`
387386
/// - `hal_buffer` must be initialized
388387
/// - `hal_buffer` must not have zero size.
389-
pub unsafe fn create_buffer_from_hal<A: HalApi>(
388+
pub unsafe fn create_buffer_from_hal<A: hal::Api>(
390389
&self,
391390
hal_buffer: A::Buffer,
392391
device_id: DeviceId,

wgpu-core/src/global.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use alloc::{borrow::ToOwned as _, sync::Arc};
22
use core::fmt;
33

44
use crate::{
5-
hal_api::HalApi,
65
hub::{Hub, HubReport},
76
instance::{Instance, Surface},
87
registry::{Registry, RegistryReport},
@@ -44,7 +43,7 @@ impl Global {
4443
/// # Safety
4544
///
4645
/// Refer to the creation of wgpu-hal Instance for every backend.
47-
pub unsafe fn from_hal_instance<A: HalApi>(name: &str, hal_instance: A::Instance) -> Self {
46+
pub unsafe fn from_hal_instance<A: hal::Api>(name: &str, hal_instance: A::Instance) -> Self {
4847
profiling::scope!("Global::new");
4948

5049
Self {
@@ -57,7 +56,7 @@ impl Global {
5756
/// # Safety
5857
///
5958
/// - The raw instance handle returned must not be manually destroyed.
60-
pub unsafe fn instance_as_hal<A: HalApi>(&self) -> Option<&A::Instance> {
59+
pub unsafe fn instance_as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
6160
unsafe { self.instance.as_hal::<A>() }
6261
}
6362

wgpu-core/src/hal_api.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

wgpu-core/src/instance.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::{
1515
api_log, api_log_debug,
1616
device::{queue::Queue, resource::Device, DeviceDescriptor, DeviceError},
1717
global::Global,
18-
hal_api::HalApi,
1918
id::{markers, AdapterId, DeviceId, QueueId, SurfaceId},
2019
lock::{rank, Mutex},
2120
present::Presentation,
@@ -117,7 +116,7 @@ impl Instance {
117116
}
118117

119118
/// Helper for `Instance::new()`; attempts to add a single `wgpu-hal` backend to this instance.
120-
fn try_add_hal<A: HalApi>(&mut self, _: A, instance_desc: &wgt::InstanceDescriptor) {
119+
fn try_add_hal<A: hal::Api>(&mut self, _: A, instance_desc: &wgt::InstanceDescriptor) {
121120
// Whether or not the backend was requested, and whether or not it succeeds,
122121
// note that we *could* try it.
123122
self.supported_backends |= A::VARIANT.into();
@@ -151,7 +150,7 @@ impl Instance {
151150
}
152151
}
153152

154-
pub(crate) fn from_hal_instance<A: HalApi>(
153+
pub(crate) fn from_hal_instance<A: hal::Api>(
155154
name: String,
156155
hal_instance: <A as hal::Api>::Instance,
157156
) -> Self {
@@ -175,7 +174,7 @@ impl Instance {
175174
/// # Safety
176175
///
177176
/// - The raw instance handle returned must not be manually destroyed.
178-
pub unsafe fn as_hal<A: HalApi>(&self) -> Option<&A::Instance> {
177+
pub unsafe fn as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
179178
self.raw(A::VARIANT).map(|instance| {
180179
instance
181180
.as_any()

wgpu-core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ mod conv;
7272
pub mod device;
7373
pub mod error;
7474
pub mod global;
75-
pub mod hal_api;
7675
mod hash_utils;
7776
pub mod hub;
7877
pub mod id;

wgpu-hal/src/dx12/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ impl D3DBlob {
397397
pub struct Api;
398398

399399
impl crate::Api for Api {
400+
const VARIANT: wgt::Backend = wgt::Backend::Dx12;
401+
400402
type Instance = Instance;
401403
type Surface = Surface;
402404
type Adapter = Adapter;

wgpu-hal/src/gles/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ const MAX_PUSH_CONSTANTS: usize = 64;
141141
const MAX_PUSH_CONSTANT_COMMANDS: usize = MAX_PUSH_CONSTANTS * crate::MAX_CONCURRENT_SHADER_STAGES;
142142

143143
impl crate::Api for Api {
144+
const VARIANT: wgt::Backend = wgt::Backend::Gl;
145+
144146
type Instance = Instance;
145147
type Surface = Surface;
146148
type Adapter = Adapter;

wgpu-hal/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ impl InstanceError {
472472
}
473473
}
474474

475-
pub trait Api: Clone + fmt::Debug + Sized {
475+
pub trait Api: Clone + fmt::Debug + Sized + WasmNotSendSync + 'static {
476+
const VARIANT: wgt::Backend;
477+
476478
type Instance: DynInstance + Instance<A = Self>;
477479
type Surface: DynSurface + Surface<A = Self>;
478480
type Adapter: DynAdapter + Adapter<A = Self>;

wgpu-hal/src/metal/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct Api;
4747
type ResourceIndex = u32;
4848

4949
impl crate::Api for Api {
50+
const VARIANT: wgt::Backend = wgt::Backend::Metal;
51+
5052
type Instance = Instance;
5153
type Surface = Surface;
5254
type Adapter = Adapter;

0 commit comments

Comments
 (0)