Skip to content

Commit 7a65558

Browse files
feat(core): Expose descriptor validation separately from request_device (#9967)
1 parent c079e55 commit 7a65558

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Bottom level categories:
4747
#### General
4848

4949
- Support the `wasm64-unknown-unknown` target for the web backend. Building for wasm64 requires a nightly toolchain with `-Z build-std=std,panic_abort`. By @nickbabcock in [#9836](https://github.com/gfx-rs/wgpu/pull/9836).
50+
- `wgpu-core` now exposes a `validate_device_descriptor` function that validates a device descriptor as `request_device` would. This may be useful in conjunction with `create_device_from_hal`. By @andyleiserson in [#9967](https://github.com/gfx-rs/wgpu/pull/9967).
5051

5152
#### Hal
5253

wgpu-core/src/instance.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,19 @@ impl Adapter {
12161216
Ok((device, queue))
12171217
}
12181218

1219-
pub fn request_device(
1220-
self: &Arc<Self>,
1221-
desc: &DeviceDescriptor,
1222-
) -> Result<(Arc<Device>, Arc<Queue>), RequestDeviceError> {
1223-
profiling::scope!("Adapter::request_device");
1224-
api_log!("Adapter::request_device");
1225-
let mut desc = desc.clone();
1219+
/// Validate a device descriptor.
1220+
///
1221+
/// This validates the provided device descriptor as if it were passed to
1222+
/// [`Self::request_device`]. If [`InstanceFlags::STRICT_WEBGPU_COMPLIANCE`] is active,
1223+
/// the requested extensions in the descriptor will be filtered to remove `wgpu`
1224+
/// extensions, except for those that are included in [`limits::EXEMPT_FEATURES`].
1225+
///
1226+
/// This may be useful when it is necessary to obtain the device itself from a raw hal
1227+
/// API, but the rest of the `request_device` validation is still desired.
1228+
pub fn validate_device_descriptor(
1229+
&self,
1230+
desc: &mut DeviceDescriptor,
1231+
) -> Result<(), RequestDeviceError> {
12261232
filter_features_and_limits(
12271233
self.instance_flags,
12281234
&mut desc.required_features,
@@ -1273,6 +1279,19 @@ impl Adapter {
12731279
return Err(RequestDeviceError::LimitsExceeded(failed));
12741280
}
12751281

1282+
Ok(())
1283+
}
1284+
1285+
pub fn request_device(
1286+
self: &Arc<Self>,
1287+
desc: &DeviceDescriptor,
1288+
) -> Result<(Arc<Device>, Arc<Queue>), RequestDeviceError> {
1289+
profiling::scope!("Adapter::request_device");
1290+
api_log!("Adapter::request_device");
1291+
1292+
let mut desc = desc.clone();
1293+
self.validate_device_descriptor(&mut desc)?;
1294+
12761295
let open = unsafe {
12771296
self.raw.adapter.open(
12781297
desc.required_features,
@@ -1605,6 +1624,15 @@ impl Global {
16051624
Ok((device_id, queue_id))
16061625
}
16071626

1627+
pub fn adapter_validate_device_descriptor(
1628+
&self,
1629+
adapter_id: AdapterId,
1630+
desc: &mut DeviceDescriptor,
1631+
) -> Result<(), RequestDeviceError> {
1632+
let adapter = self.hub.adapters.get(adapter_id);
1633+
adapter.validate_device_descriptor(desc)
1634+
}
1635+
16081636
/// # Safety
16091637
///
16101638
/// - `hal_device` must be created from `adapter_id` or its internal handle.

0 commit comments

Comments
 (0)