[core] "consume" adapter on first succesful request_device if STRICT_WEBGPU_COMPLIANCE (#10444)

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Sam authored and GitHub committed 2026-09-24 13:34:16 +00:00
1 parent 94d9f2424e
commit 6293e039ca
3 files changed
+53 -2

No files matched your search

+1
View File
@@ -166,6 +166,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
- `wgpu::Error::Validation::description` from `Device::create_shader_module` no longer include the shader source text and detailed compiler messages, per the WebGPU specification. These details remain accessible via `ShaderModule::get_compilation_info`. By @beicause and @sagudev in [#10173](https://github.com/gfx-rs/wgpu/pull/10173).
- `BufferUsages` is now composed of `BufferUsagesWebGPU` and `BufferUsagesWGPU`, similarly to `Features`. In most cases this is not expected to be a breaking change, but changes might be required for converting `BufferUsages` to/from `u32`. By @sagudev in [#10195](https://github.com/gfx-rs/wgpu/pull/10195).
- `ShaderStages` is now composed of `ShaderStagesWebGPU` and `ShaderStagesWGPU`, similarly to `Features`. In most cases this is not expected to be a breaking change, but changes might be required for converting `ShaderStages` to/from `u32`. By @sagudev in [#10313](https://github.com/gfx-rs/wgpu/pull/10313).
- `request_adapter` will return error on `InstanceFlags::STRICT_WEBGPU_COMPLIANCE` if the adapter has already been consumed by a previous `request_device`. By @sagudev in [#10444](https://github.com/gfx-rs/wgpu/pull/10444).
#### naga
+29
View File
@@ -1,5 +1,6 @@
use std::sync::atomic::AtomicBool;
use wgpu::InstanceFlags;
use wgpu_test::{
apply, gpu_test, FailureCase, GpuTestConfiguration, GpuTestInitializer, TestParameters,
TestingContext,
@@ -52,6 +53,34 @@ static CROSS_DEVICE_BIND_GROUP_USAGE: GpuTestConfiguration = GpuTestConfiguratio
ctx.async_poll(wgpu::PollType::Poll).await.unwrap();
});
#[apply(gpu_test!)]
static SINGLE_DEVICES: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(
TestParameters::default()
.instance_flags(InstanceFlags::STRICT_WEBGPU_COMPLIANCE)
.enable_noop(),
)
.run_sync(|ctx| {
use pollster::FutureExt as _;
ctx.adapter
.request_device(&wgpu::DeviceDescriptor {
required_features: wgpu::Features::empty(),
required_limits: wgpu::Limits::downlevel_webgl2_defaults(),
..Default::default()
})
.block_on()
.expect("failed to create device");
assert!(ctx
.adapter
.request_device(&wgpu::DeviceDescriptor {
required_features: wgpu::Features::empty(),
required_limits: wgpu::Limits::downlevel_webgl2_defaults(),
..Default::default()
})
.block_on()
.is_err());
});
#[cfg(not(wasm_test))]
#[apply(gpu_test!)]
static MULTIPLE_DEVICES: GpuTestConfiguration = GpuTestConfiguration::new()
+23 -2
View File
@@ -1,5 +1,8 @@
use alloc::{borrow::ToOwned as _, boxed::Box, string::String, sync::Arc, vec, vec::Vec};
use core::fmt;
use core::{
fmt,
sync::atomic::{AtomicBool, Ordering},
};
use hashbrown::HashMap;
use thiserror::Error;
@@ -1047,11 +1050,16 @@ impl Drop for Surface {
pub struct Adapter {
pub(crate) raw: hal::DynExposedAdapter,
pub(crate) instance: Arc<Instance>,
consumed: AtomicBool,
}
impl Adapter {
pub(crate) fn new(raw: hal::DynExposedAdapter, instance: Arc<Instance>) -> Arc<Self> {
Arc::new(Self { raw, instance })
Arc::new(Self {
raw,
instance,
consumed: AtomicBool::new(false),
})
}
/// Returns the backend this adapter is using.
@@ -1193,6 +1201,15 @@ impl Adapter {
profiling::scope!("Adapter::create_device_and_queue_from_hal");
api_log!("Adapter::create_device_and_queue_from_hal");
if self
.instance
.flags
.contains(InstanceFlags::STRICT_WEBGPU_COMPLIANCE)
&& self.consumed.load(Ordering::SeqCst)
{
return Err(RequestDeviceError::AdapterConsumed);
}
let default_queue_desc = desc.default_queue.clone();
let device = Device::new(hal_device.device, self, desc, self.instance.flags)?;
@@ -1214,6 +1231,8 @@ impl Adapter {
self.instance.devices.push(&device);
self.consumed.store(true, Ordering::SeqCst);
Ok((device, queue))
}
@@ -1344,6 +1363,8 @@ pub enum RequestDeviceError {
"Some experimental features, {0}, were requested, but experimental features are not enabled"
)]
ExperimentalFeaturesNotEnabled(wgt::Features),
#[error("The adapter has already been consumed.")]
AdapterConsumed,
}
#[derive(Clone, Debug, Error)]