feat(core): Expose descriptor validation separately from request_device (#9967)

This commit is contained in:
Andy Leiserson authored and GitHub committed 2026-07-30 18:18:49 +00:00
1 parent c079e55f53
commit 7a655581ff
2 files changed
+36 -7

No files matched your search

+1
View File
@@ -47,6 +47,7 @@ Bottom level categories:
#### General
- 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).
- `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).
#### Hal
+35 -7
View File
@@ -1216,13 +1216,19 @@ impl Adapter {
Ok((device, queue))
}
pub fn request_device(
self: &Arc<Self>,
desc: &DeviceDescriptor,
) -> Result<(Arc<Device>, Arc<Queue>), RequestDeviceError> {
profiling::scope!("Adapter::request_device");
api_log!("Adapter::request_device");
let mut desc = desc.clone();
/// Validate a device descriptor.
///
/// This validates the provided device descriptor as if it were passed to
/// [`Self::request_device`]. If [`InstanceFlags::STRICT_WEBGPU_COMPLIANCE`] is active,
/// the requested extensions in the descriptor will be filtered to remove `wgpu`
/// extensions, except for those that are included in [`limits::EXEMPT_FEATURES`].
///
/// This may be useful when it is necessary to obtain the device itself from a raw hal
/// API, but the rest of the `request_device` validation is still desired.
pub fn validate_device_descriptor(
&self,
desc: &mut DeviceDescriptor,
) -> Result<(), RequestDeviceError> {
filter_features_and_limits(
self.instance_flags,
&mut desc.required_features,
@@ -1273,6 +1279,19 @@ impl Adapter {
return Err(RequestDeviceError::LimitsExceeded(failed));
}
Ok(())
}
pub fn request_device(
self: &Arc<Self>,
desc: &DeviceDescriptor,
) -> Result<(Arc<Device>, Arc<Queue>), RequestDeviceError> {
profiling::scope!("Adapter::request_device");
api_log!("Adapter::request_device");
let mut desc = desc.clone();
self.validate_device_descriptor(&mut desc)?;
let open = unsafe {
self.raw.adapter.open(
desc.required_features,
@@ -1605,6 +1624,15 @@ impl Global {
Ok((device_id, queue_id))
}
pub fn adapter_validate_device_descriptor(
&self,
adapter_id: AdapterId,
desc: &mut DeviceDescriptor,
) -> Result<(), RequestDeviceError> {
let adapter = self.hub.adapters.get(adapter_id);
adapter.validate_device_descriptor(desc)
}
/// # Safety
///
/// - `hal_device` must be created from `adapter_id` or its internal handle.