diff --git a/CHANGELOG.md b/CHANGELOG.md index 6506ee1e0c..f12d789821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ Previously, `DeviceExt::create_texture_with_data` only allowed data to be provid - Rename of `DispatchIndirect`, `DrawIndexedIndirect`, and `DrawIndirect` types in the `wgpu::util` module to `DispatchIndirectArgs`, `DrawIndexedIndirectArgs`, and `DrawIndirectArgs`. By @cwfitzgerald in [#4723](https://github.com/gfx-rs/wgpu/pull/4723). - Make the size parameter of `encoder.clear_buffer` an `Option` instead of `Option>`. By @nical in [#4737](https://github.com/gfx-rs/wgpu/pull/4737) - Reduce the `info` log level noise. By @nical in [#4769](https://github.com/gfx-rs/wgpu/pull/4769), [#4711](https://github.com/gfx-rs/wgpu/pull/4711) and [#4772](https://github.com/gfx-rs/wgpu/pull/4772) +- Rename `features` & `limits` fields of `DeviceDescriptor` to `required_features` & `required_limits`. By @teoxoy in [#4803](https://github.com/gfx-rs/wgpu/pull/4803) #### Safe `Surface` creation diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index bf1c246ad2..b69157df52 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -657,8 +657,8 @@ pub async fn op_webgpu_request_device( let descriptor = wgpu_types::DeviceDescriptor { label: Some(Cow::Owned(label)), - features: required_features.into(), - limits: required_limits.unwrap_or_default(), + required_features: required_features.into(), + required_limits: required_limits.unwrap_or_default(), }; let (device, _queue, maybe_err) = gfx_select!(adapter => instance.adapter_request_device( diff --git a/examples/src/framework.rs b/examples/src/framework.rs index 555fb3cb7b..a014495171 100644 --- a/examples/src/framework.rs +++ b/examples/src/framework.rs @@ -317,8 +317,8 @@ impl ExampleContext { .request_device( &wgpu::DeviceDescriptor { label: None, - features: (optional_features & adapter_features) | required_features, - limits: needed_limits, + required_features: (optional_features & adapter_features) | required_features, + required_limits: needed_limits, }, trace_dir.ok().as_ref().map(std::path::Path::new), ) diff --git a/examples/src/hello_compute/mod.rs b/examples/src/hello_compute/mod.rs index d93d804ef1..beffdc7bbc 100644 --- a/examples/src/hello_compute/mod.rs +++ b/examples/src/hello_compute/mod.rs @@ -48,8 +48,8 @@ async fn execute_gpu(numbers: &[u32]) -> Option> { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/hello_synchronization/mod.rs b/examples/src/hello_synchronization/mod.rs index 476db4d965..4b1dc6a871 100644 --- a/examples/src/hello_synchronization/mod.rs +++ b/examples/src/hello_synchronization/mod.rs @@ -17,8 +17,8 @@ async fn run() { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index e810cc1a19..40cb805c28 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -28,9 +28,9 @@ async fn run(event_loop: EventLoop<()>, window: Window) { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), + required_features: wgpu::Features::empty(), // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the swapchain. - limits: wgpu::Limits::downlevel_webgl2_defaults() + required_limits: wgpu::Limits::downlevel_webgl2_defaults() .using_resolution(adapter.limits()), }, None, diff --git a/examples/src/hello_windows/mod.rs b/examples/src/hello_windows/mod.rs index 1b4bbdc934..9a42b9afbd 100644 --- a/examples/src/hello_windows/mod.rs +++ b/examples/src/hello_windows/mod.rs @@ -82,8 +82,8 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Arc, wgpu::Color .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/hello_workgroups/mod.rs b/examples/src/hello_workgroups/mod.rs index 933364a6f8..8334de5b35 100644 --- a/examples/src/hello_workgroups/mod.rs +++ b/examples/src/hello_workgroups/mod.rs @@ -30,8 +30,8 @@ async fn run() { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 820618f6e5..2bd831cc12 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -19,8 +19,8 @@ async fn run(_path: Option) { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/repeated_compute/mod.rs b/examples/src/repeated_compute/mod.rs index 735ebb9588..fa80b69652 100644 --- a/examples/src/repeated_compute/mod.rs +++ b/examples/src/repeated_compute/mod.rs @@ -167,8 +167,8 @@ impl WgpuContext { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/storage_texture/mod.rs b/examples/src/storage_texture/mod.rs index 0fac837e2a..6498670817 100644 --- a/examples/src/storage_texture/mod.rs +++ b/examples/src/storage_texture/mod.rs @@ -33,8 +33,8 @@ async fn run(_path: Option) { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 0f53d18b34..877659e697 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -214,8 +214,8 @@ async fn run() { .request_device( &wgpu::DeviceDescriptor { label: None, - features, - limits: wgpu::Limits::downlevel_defaults(), + required_features: features, + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index fdb6a5f854..de71ce5067 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -113,8 +113,8 @@ impl WgpuContext { .request_device( &wgpu::DeviceDescriptor { label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::downlevel_defaults(), + required_features: wgpu::Features::empty(), + required_limits: wgpu::Limits::downlevel_defaults(), }, None, ) diff --git a/player/tests/test.rs b/player/tests/test.rs index e5c2a0b51d..76983ec2fc 100644 --- a/player/tests/test.rs +++ b/player/tests/test.rs @@ -89,8 +89,8 @@ impl Test<'_> { adapter, &wgt::DeviceDescriptor { label: None, - features: self.features, - limits: wgt::Limits::default(), + required_features: self.features, + required_limits: wgt::Limits::default(), }, None, device_id, diff --git a/tests/src/init.rs b/tests/src/init.rs index 9ff2d08a6e..4615516b50 100644 --- a/tests/src/init.rs +++ b/tests/src/init.rs @@ -85,8 +85,8 @@ pub async fn initialize_device( .request_device( &wgpu::DeviceDescriptor { label: None, - features, - limits, + required_features: features, + required_limits: limits, }, None, ) diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 18f5b1d4a9..1154520d14 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -79,8 +79,8 @@ async fn request_device_error_message() { .request_device( &wgpu::DeviceDescriptor { // Force a failure by requesting absurd limits. - features: wgpu::Features::all(), - limits: wgpu::Limits { + required_features: wgpu::Features::all(), + required_limits: wgpu::Limits { max_texture_dimension_1d: u32::MAX, max_texture_dimension_2d: u32::MAX, max_texture_dimension_3d: u32::MAX, diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 6d2e140a8b..fb48115ca8 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -192,8 +192,6 @@ impl Device { raw_device: A::Device, raw_queue: &A::Queue, adapter: &Arc>, - alignments: hal::Alignments, - downlevel: wgt::DownlevelCapabilities, desc: &DeviceDescriptor, trace_path: Option<&std::path::Path>, instance_flags: wgt::InstanceFlags, @@ -243,6 +241,9 @@ impl Device { })); } + let alignments = adapter.raw.capabilities.alignments.clone(); + let downlevel = adapter.raw.capabilities.downlevel.clone(); + Ok(Self { raw: Some(raw_device), adapter: adapter.clone(), @@ -272,8 +273,8 @@ impl Device { } })), alignments, - limits: desc.limits.clone(), - features: desc.features, + limits: desc.required_limits.clone(), + features: desc.required_features, downlevel, instance_flags, pending_writes: Mutex::new(Some(pending_writes)), diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 6bc0abdb16..b8340cd659 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -309,13 +309,10 @@ impl Adapter { ) -> Result<(Device, Queue), RequestDeviceError> { api_log!("Adapter::create_device"); - let caps = &self.raw.capabilities; if let Ok(device) = Device::new( hal_device.device, &hal_device.queue, self, - caps.alignments.clone(), - caps.downlevel.clone(), desc, trace_path, instance_flags, @@ -337,9 +334,9 @@ impl Adapter { trace_path: Option<&std::path::Path>, ) -> Result<(Device, Queue), RequestDeviceError> { // Verify all features were exposed by the adapter - if !self.raw.features.contains(desc.features) { + if !self.raw.features.contains(desc.required_features) { return Err(RequestDeviceError::UnsupportedFeature( - desc.features - self.raw.features, + desc.required_features - self.raw.features, )); } @@ -358,7 +355,7 @@ impl Adapter { // Verify feature preconditions if desc - .features + .required_features .contains(wgt::Features::MAPPABLE_PRIMARY_BUFFERS) && self.raw.info.device_type == wgt::DeviceType::DiscreteGpu { @@ -372,17 +369,20 @@ impl Adapter { //TODO } - if let Some(failed) = check_limits(&desc.limits, &caps.limits).pop() { + if let Some(failed) = check_limits(&desc.required_limits, &caps.limits).pop() { return Err(RequestDeviceError::LimitsExceeded(failed)); } - let open = unsafe { self.raw.adapter.open(desc.features, &desc.limits) }.map_err( - |err| match err { - hal::DeviceError::Lost => RequestDeviceError::DeviceLost, - hal::DeviceError::OutOfMemory => RequestDeviceError::OutOfMemory, - hal::DeviceError::ResourceCreationFailed => RequestDeviceError::Internal, - }, - )?; + let open = unsafe { + self.raw + .adapter + .open(desc.required_features, &desc.required_limits) + } + .map_err(|err| match err { + hal::DeviceError::Lost => RequestDeviceError::DeviceLost, + hal::DeviceError::OutOfMemory => RequestDeviceError::OutOfMemory, + hal::DeviceError::ResourceCreationFailed => RequestDeviceError::Internal, + })?; self.create_device_and_queue_from_hal(open, desc, instance_flags, trace_path) } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 3e9ab37a24..56b8ee4d0c 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1651,12 +1651,18 @@ pub struct AdapterInfo { pub struct DeviceDescriptor { /// Debug label for the device. pub label: L, - /// Features that the device should support. If any feature is not supported by - /// the adapter, creating a device will panic. - pub features: Features, - /// Limits that the device should support. If any limit is "better" than the limit exposed by - /// the adapter, creating a device will panic. - pub limits: Limits, + /// Specifies the features that are required by the device request. + /// The request will fail if the adapter cannot provide these features. + /// + /// Exactly the specified set of features, and no more or less, + /// will be allowed in validation of API calls on the resulting device. + pub required_features: Features, + /// Specifies the limits that are required by the device request. + /// The request will fail if the adapter cannot provide these limits. + /// + /// Exactly the specified limits, and no better or worse, + /// will be allowed in validation of API calls on the resulting device. + pub required_limits: Limits, } impl DeviceDescriptor { @@ -1664,8 +1670,8 @@ impl DeviceDescriptor { pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> DeviceDescriptor { DeviceDescriptor { label: fun(&self.label), - features: self.features, - limits: self.limits.clone(), + required_features: self.required_features, + required_limits: self.required_limits.clone(), } } } diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 1e9701634b..b1ed365a8c 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -122,7 +122,7 @@ impl Context { let device = Device { id: device_id, error_sink: error_sink.clone(), - features: desc.features, + features: desc.required_features, }; let queue = Queue { id: queue_id, @@ -646,7 +646,7 @@ impl crate::Context for Context { let device = Device { id: device_id, error_sink: error_sink.clone(), - features: desc.features, + features: desc.required_features, }; let queue = Queue { id: queue_id, diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index d89e024c92..05e05db8de 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1151,7 +1151,7 @@ impl crate::context::Context for Context { // TODO: Migrate to a web_sys api. // See https://github.com/rustwasm/wasm-bindgen/issues/3587 - let limits_object = map_js_sys_limits(&desc.limits); + let limits_object = map_js_sys_limits(&desc.required_limits); js_sys::Reflect::set( &mapped_desc, @@ -1164,7 +1164,7 @@ impl crate::context::Context for Context { .iter() .copied() .flat_map(|(flag, value)| { - if desc.features.contains(flag) { + if desc.required_features.contains(flag) { Some(JsValue::from(value)) } else { None diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 639d02e728..9069b8758b 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -2383,18 +2383,12 @@ impl Adapter { ) } - /// List all features that are supported with this adapter. - /// - /// Features must be explicitly requested in [`Adapter::request_device`] in order - /// to use them. + /// The features which can be used to create devices on this adapter. pub fn features(&self) -> Features { DynContext::adapter_features(&*self.context, &self.id, self.data.as_ref()) } - /// List the "best" limits that are supported by this adapter. - /// - /// Limits must be explicitly requested in [`Adapter::request_device`] to set - /// the values that you are allowed to use. + /// The best limits which can be used to create devices on this adapter. pub fn limits(&self) -> Limits { DynContext::adapter_limits(&*self.context, &self.id, self.data.as_ref()) } @@ -2462,16 +2456,16 @@ impl Device { DynContext::device_poll(&*self.context, &self.id, self.data.as_ref(), maintain) } - /// List all features that may be used with this device. + /// The features which can be used on this device. /// - /// Functions may panic if you use unsupported features. + /// No additional features can be used, even if the underlying adapter can support them. pub fn features(&self) -> Features { DynContext::device_features(&*self.context, &self.id, self.data.as_ref()) } - /// List all limits that were requested of this device. + /// The limits which can be used on this device. /// - /// If any of these limits are exceeded, functions may panic. + /// No better limits can be used, even if the underlying adapter can support them. pub fn limits(&self) -> Limits { DynContext::device_limits(&*self.context, &self.id, self.data.as_ref()) }