diff --git a/player/src/main.rs b/player/src/main.rs index 91740cb00..f5e1b437e 100644 --- a/player/src/main.rs +++ b/player/src/main.rs @@ -491,7 +491,7 @@ fn main() { #[cfg(not(feature = "winit"))] compatible_surface: None, }, - unsafe { wgt::UnsafeExtensions::allow() }, + unsafe { wgt::UnsafeFeatures::allow() }, wgc::instance::AdapterInputs::IdSet( &[wgc::id::TypedId::zip(0, 0, backend)], |id| id.backend(), diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 33e0cc75b..e8584ff67 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -20,8 +20,7 @@ use std::borrow::Borrow; #[derive(Clone, Debug)] pub enum BindGroupLayoutError { ConflictBinding(u32), - MissingExtension(wgt::Extensions), - MissingCapability(wgt::Capabilities), + MissingFeature(wgt::Features), /// Arrays of bindings can't be 0 elements long ZeroCount, /// Arrays of bindings unsupported for this type of binding diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index c5392af4f..c802cc501 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -196,8 +196,7 @@ pub struct Device { pub(crate) hal_limits: hal::Limits, pub(crate) private_features: PrivateFeatures, limits: wgt::Limits, - extensions: wgt::Extensions, - capabilities: wgt::Capabilities, + features: wgt::Features, //TODO: move this behind another mutex. This would allow several methods to switch // to borrow Device immutably, such as `write_buffer`, `write_texture`, and `buffer_unmap`. pending_writes: queue::PendingWrites, @@ -214,7 +213,6 @@ impl Device { hal_limits: hal::Limits, private_features: PrivateFeatures, desc: &wgt::DeviceDescriptor, - capabilities: wgt::Capabilities, trace_path: Option<&std::path::Path>, ) -> Self { let com_allocator = command::CommandAllocator::new(queue_group.family, &raw); @@ -269,8 +267,7 @@ impl Device { hal_limits, private_features, limits: desc.limits.clone(), - extensions: desc.extensions.clone(), - capabilities: capabilities.clone(), + features: desc.features.clone(), pending_writes: queue::PendingWrites::new(), } } @@ -407,8 +404,8 @@ impl Device { MemoryUsage::Staging { read_back: true } } else { let is_native_only = self - .extensions - .contains(wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS); + .features + .contains(wgt::Features::MAPPABLE_PRIMARY_BUFFERS); assert!( is_native_only, "MAP usage can only be combined with the opposite COPY, requested {:?}", @@ -636,15 +633,15 @@ impl Device { } impl Global { - pub fn device_extensions(&self, device_id: id::DeviceId) -> wgt::Extensions { - span!(_guard, INFO, "Device::extensions"); + pub fn device_features(&self, device_id: id::DeviceId) -> wgt::Features { + span!(_guard, INFO, "Device::features"); let hub = B::hub(self); let mut token = Token::root(); let (device_guard, _) = hub.devices.read(&mut token); let device = &device_guard[device_id]; - device.extensions + device.features } pub fn device_limits(&self, device_id: id::DeviceId) -> wgt::Limits { @@ -658,17 +655,6 @@ impl Global { device.limits.clone() } - pub fn device_capabilities(&self, device_id: id::DeviceId) -> wgt::Capabilities { - span!(_guard, INFO, "Device::capabilities"); - - let hub = B::hub(self); - let mut token = Token::root(); - let (device_guard, _) = hub.devices.read(&mut token); - let device = &device_guard[device_id]; - - device.capabilities - } - pub fn device_create_buffer( &self, device_id: id::DeviceId, @@ -1108,17 +1094,20 @@ impl Global { let (device_guard, mut token) = hub.devices.read(&mut token); let device = &device_guard[device_id]; - if let Some(clamp) = desc.anisotropy_clamp { - assert!( - device.extensions.contains(wgt::Extensions::ANISOTROPIC_FILTERING), - "Anisotropic clamp may only be used when the anisotropic filtering extension is enabled" - ); + let actual_clamp = if let Some(clamp) = desc.anisotropy_clamp { let valid_clamp = clamp <= MAX_ANISOTROPY && conv::is_power_of_two(clamp as u32); assert!( valid_clamp, "Anisotropic clamp must be one of the values: 1, 2, 4, 8, or 16" ); - } + if device.private_features.anisotropic_filtering { + Some(clamp) + } else { + None + } + } else { + None + }; let info = hal::image::SamplerDesc { min_filter: conv::map_filter(desc.min_filter), @@ -1134,7 +1123,7 @@ impl Global { comparison: desc.compare.and_then(conv::map_compare_function), border: hal::image::PackedColor(0), normalized: true, - anisotropy_clamp: desc.anisotropy_clamp, + anisotropy_clamp: actual_clamp, }; let sampler = resource::Sampler { @@ -1237,11 +1226,11 @@ impl Global { match binding.ty { wgt::BindingType::SampledTexture { .. } => { if !device - .capabilities - .contains(wgt::Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY) + .features + .contains(wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY) { - return Err(binding_model::BindGroupLayoutError::MissingCapability( - wgt::Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY, + return Err(binding_model::BindGroupLayoutError::MissingFeature( + wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY, )); } } @@ -1664,8 +1653,8 @@ impl Global { } Br::TextureViewArray(ref bindings_array) => { assert!( - device.capabilities.contains(wgt::Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY), - "Capability SAMPLED_TEXTURE_BINDING_ARRAY must be supported to use TextureViewArrays in a bind group" + device.features.contains(wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY), + "Feature SAMPLED_TEXTURE_BINDING_ARRAY must be enabled to use TextureViewArrays in a bind group" ); if let Some(count) = decl.count { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index a2e62b941..0ec7e9382 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -122,33 +122,37 @@ pub struct Surface { #[derive(Debug)] pub struct Adapter { pub(crate) raw: hal::adapter::Adapter, - extensions: wgt::Extensions, + features: wgt::Features, limits: wgt::Limits, - capabilities: wgt::Capabilities, - unsafe_extensions: wgt::UnsafeExtensions, + unsafe_features: wgt::UnsafeFeatures, life_guard: LifeGuard, } impl Adapter { - fn new(raw: hal::adapter::Adapter, unsafe_extensions: wgt::UnsafeExtensions) -> Self { + fn new(raw: hal::adapter::Adapter, unsafe_features: wgt::UnsafeFeatures) -> Self { span!(_guard, INFO, "Adapter::new"); let adapter_features = raw.physical_device.features(); - let mut extensions = wgt::Extensions::default() | wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS; - extensions.set( - wgt::Extensions::ANISOTROPIC_FILTERING, - adapter_features.contains(hal::Features::SAMPLER_ANISOTROPY), + let mut features = wgt::Features::default() | wgt::Features::MAPPABLE_PRIMARY_BUFFERS; + features.set( + wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY, + adapter_features.contains(hal::Features::TEXTURE_DESCRIPTOR_ARRAY), ); - extensions.set( - wgt::Extensions::BINDING_INDEXING, - adapter_features.intersects( - hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING - | hal::Features::UNSIZED_DESCRIPTOR_ARRAY, - ), + features.set( + wgt::Features::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING, + adapter_features.contains(hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING), ); - if unsafe_extensions.allowed() { - // Unsafe extensions go here + features.set( + wgt::Features::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, + adapter_features.contains(hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING), + ); + features.set( + wgt::Features::UNSIZED_BINDING_ARRAY, + adapter_features.contains(hal::Features::UNSIZED_DESCRIPTOR_ARRAY), + ); + if unsafe_features.allowed() { + // Unsafe features go here } let adapter_limits = raw.physical_device.limits(); @@ -159,31 +163,11 @@ impl Adapter { _non_exhaustive: unsafe { wgt::NonExhaustive::new() }, }; - let mut capabilities = wgt::Capabilities::empty(); - - capabilities.set( - wgt::Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY, - adapter_features.contains(hal::Features::TEXTURE_DESCRIPTOR_ARRAY), - ); - capabilities.set( - wgt::Capabilities::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING, - adapter_features.contains(hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING), - ); - capabilities.set( - wgt::Capabilities::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, - adapter_features.contains(hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING), - ); - capabilities.set( - wgt::Capabilities::UNSIZED_BINDING_ARRAY, - adapter_features.contains(hal::Features::UNSIZED_DESCRIPTOR_ARRAY), - ); - Adapter { raw, - extensions, + features, limits, - capabilities, - unsafe_extensions, + unsafe_features, life_guard: LifeGuard::new(), } } @@ -310,7 +294,7 @@ impl Global { pub fn enumerate_adapters( &self, - unsafe_extensions: wgt::UnsafeExtensions, + unsafe_features: wgt::UnsafeFeatures, inputs: AdapterInputs>, ) -> Vec { span!(_guard, INFO, "Instance::enumerate_adapters"); @@ -324,7 +308,7 @@ impl Global { if let Some(inst) = instance_field { if let Some(id_backend) = inputs.find(backend) { for raw in inst.enumerate_adapters() { - let adapter = Adapter::new(raw, unsafe_extensions); + let adapter = Adapter::new(raw, unsafe_features); log::info!("Adapter {} {:?}", backend_info, adapter.raw.info); adapters.push(backend_hub(self).adapters.register_identity( id_backend.clone(), @@ -352,7 +336,7 @@ impl Global { pub fn pick_adapter( &self, desc: &RequestAdapterOptions, - unsafe_extensions: wgt::UnsafeExtensions, + unsafe_features: wgt::UnsafeFeatures, inputs: AdapterInputs>, ) -> Option { span!(_guard, INFO, "Instance::pick_adapter"); @@ -465,7 +449,7 @@ impl Global { backends_map! { let map = |(info_adapter, id_backend, mut adapters_backend, backend_hub)| { if selected < adapters_backend.len() { - let adapter = Adapter::new(adapters_backend.swap_remove(selected), unsafe_extensions); + let adapter = Adapter::new(adapters_backend.swap_remove(selected), unsafe_features); log::info!("Adapter {} {:?}", info_adapter, adapter.raw.info); let id = backend_hub(self).adapters.register_identity( id_backend.take().unwrap(), @@ -508,15 +492,15 @@ impl Global { AdapterInfo::from_gfx(adapter.raw.info.clone(), adapter_id.backend()) } - pub fn adapter_extensions(&self, adapter_id: AdapterId) -> wgt::Extensions { - span!(_guard, INFO, "Adapter::extensions"); + pub fn adapter_features(&self, adapter_id: AdapterId) -> wgt::Features { + span!(_guard, INFO, "Adapter::features"); let hub = B::hub(self); let mut token = Token::root(); let (adapter_guard, _) = hub.adapters.read(&mut token); let adapter = &adapter_guard[adapter_id]; - adapter.extensions + adapter.features } pub fn adapter_limits(&self, adapter_id: AdapterId) -> wgt::Limits { @@ -530,17 +514,6 @@ impl Global { adapter.limits.clone() } - pub fn adapter_capabilities(&self, adapter_id: AdapterId) -> wgt::Capabilities { - span!(_guard, INFO, "Adapter::capabilities"); - - let hub = B::hub(self); - let mut token = Token::root(); - let (adapter_guard, _) = hub.adapters.read(&mut token); - let adapter = &adapter_guard[adapter_id]; - - adapter.capabilities - } - pub fn adapter_destroy(&self, adapter_id: AdapterId) { span!(_guard, INFO, "Adapter::drop"); @@ -579,27 +552,27 @@ impl Global { let adapter = &adapter_guard[adapter_id]; let phd = &adapter.raw.physical_device; - // Verify all extensions were exposed by the adapter - if !adapter.unsafe_extensions.allowed() { + // Verify all features were exposed by the adapter + if !adapter.unsafe_features.allowed() { assert!( - !desc.extensions.intersects(wgt::Extensions::ALL_UNSAFE), - "Cannot enable unsafe extensions without passing UnsafeExtensions::allow() when getting an adapter. Enabled unsafe extensions: {:?}", - desc.extensions & wgt::Extensions::ALL_UNSAFE + !desc.features.intersects(wgt::Features::ALL_UNSAFE), + "Cannot enable unsafe features without passing UnsafeFeatures::allow() when getting an adapter. Enabled unsafe extensions: {:?}", + desc.features & wgt::Features::ALL_UNSAFE ) } assert!( - adapter.extensions.contains(desc.extensions), - "Cannot enable extensions that adapter doesn't support. Unsupported extensions: {:?}", - desc.extensions - adapter.extensions + adapter.features.contains(desc.features), + "Cannot enable features that adapter doesn't support. Unsupported extensions: {:?}", + desc.features - adapter.features ); - // Verify extension preconditions + // Verify feature preconditions if desc - .extensions - .contains(wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS) + .features + .contains(wgt::Features::MAPPABLE_PRIMARY_BUFFERS) && adapter.raw.info.device_type == hal::adapter::DeviceType::DiscreteGpu { - log::warn!("Extension MAPPABLE_PRIMARY_BUFFERS enabled on a discrete gpu. This is a massive performance footgun and likely not what you wanted"); + log::warn!("Feature MAPPABLE_PRIMARY_BUFFERS enabled on a discrete gpu. This is a massive performance footgun and likely not what you wanted"); } let available_features = adapter.raw.physical_device.features(); @@ -607,7 +580,8 @@ impl Global { // Check features that are always needed let wishful_features = hal::Features::VERTEX_STORES_AND_ATOMICS | hal::Features::FRAGMENT_STORES_AND_ATOMICS - | hal::Features::NDC_Y_UP; + | hal::Features::NDC_Y_UP + | hal::Features::SAMPLER_ANISOTROPY; let mut enabled_features = available_features & wishful_features; if enabled_features != wishful_features { log::warn!( @@ -616,46 +590,37 @@ impl Global { ); } - // Extensions - enabled_features.set( - hal::Features::SAMPLER_ANISOTROPY, - desc.extensions - .contains(wgt::Extensions::ANISOTROPIC_FILTERING), - ); - - let mut enabled_capabilities = adapter.capabilities & wgt::Capabilities::ALL_BUILT_IN; - - // Capabilities without extension gates + // Features enabled_features.set( hal::Features::TEXTURE_DESCRIPTOR_ARRAY, adapter - .capabilities - .contains(wgt::Capabilities::SAMPLED_TEXTURE_BINDING_ARRAY), + .features + .contains(wgt::Features::SAMPLED_TEXTURE_BINDING_ARRAY), ); enabled_features.set( hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING, adapter - .capabilities - .contains(wgt::Capabilities::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING), + .features + .contains(wgt::Features::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING), + ); + enabled_features.set( + hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING, + adapter + .features + .contains(wgt::Features::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING), + ); + enabled_features.set( + hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING, + adapter + .features + .contains(wgt::Features::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING), + ); + enabled_features.set( + hal::Features::UNSIZED_DESCRIPTOR_ARRAY, + adapter + .features + .contains(wgt::Features::UNSIZED_BINDING_ARRAY), ); - - // Capabilities behind BINDING_INDEXING - if desc.extensions.contains(wgt::Extensions::BINDING_INDEXING) { - enabled_capabilities - .insert(adapter.capabilities & wgt::Capabilities::ALL_BINDING_INDEXING); - enabled_features.set( - hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING, - adapter - .capabilities - .contains(wgt::Capabilities::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING), - ); - enabled_features.set( - hal::Features::UNSIZED_DESCRIPTOR_ARRAY, - adapter - .capabilities - .contains(wgt::Capabilities::UNSIZED_BINDING_ARRAY), - ); - } let family = adapter .raw @@ -691,6 +656,7 @@ impl Global { } let private_features = PrivateFeatures { shader_validation: desc.shader_validation, + anisotropic_filtering: enabled_features.contains(hal::Features::SAMPLER_ANISOTROPY), texture_d24_s8: phd .format_properties(Some(hal::format::Format::D24UnormS8Uint)) .optimal_tiling @@ -708,7 +674,6 @@ impl Global { limits, private_features, desc, - enabled_capabilities, trace_path, ) }; diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 4b4f50889..93e2390b1 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -171,6 +171,7 @@ struct Stored { #[derive(Clone, Copy, Debug)] struct PrivateFeatures { shader_validation: bool, + anisotropic_filtering: bool, texture_d24_s8: bool, } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index dd78f820f..4d6a3f231 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -126,30 +126,17 @@ impl NonExhaustive { } bitflags::bitflags! { - /// Extensions to the webgpu standard that are supported by wgpu. + /// Features that are not guarenteed to be supported. These are either part of the webgpu standard, + /// or are extension features supported by wgpu when targeting native. /// - /// If you want to use an extension, you need to first verify that the adapter supports - /// the extension. If the adapter does not support the extension, requesting a device with it enabled + /// If you want to use a feature, you need to first verify that the adapter supports + /// the feature. If the adapter does not support the feature, requesting a device with it enabled /// will panic. #[repr(transparent)] #[derive(Default)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] - pub struct Extensions: u64 { - /// Allow anisotropic filtering in samplers. - /// - /// Supported platforms: - /// - OpenGL 4.6+ (or 1.2+ with widespread GL_EXT_texture_filter_anisotropic) - /// - DX11/12 - /// - Metal - /// - Vulkan - /// - /// Provided Capabilities: - /// - None - /// - /// This is a native only extension. Support is planned to be added to webgpu, - /// but it is not yet implemented. - const ANISOTROPIC_FILTERING = 0x0000_0000_0001_0000; + pub struct Features: u64 { /// Webgpu only allows the MAP_READ and MAP_WRITE buffer usage to be matched with /// COPY_DST and COPY_SRC respectively. This removes this requirement. /// @@ -160,72 +147,105 @@ bitflags::bitflags! { /// Supported platforms: /// - All /// - /// Provided Capabilities: - /// - None + /// This is a native only feature. + const MAPPABLE_PRIMARY_BUFFERS = 0x0000_0000_0001_0000; + /// Allows the user to create uniform arrays of sampled textures in shaders: /// - /// This is a native only extension. - const MAPPABLE_PRIMARY_BUFFERS = 0x0000_0000_0002_0000; - /// Allows shaders to index arrays of bindings with dynamically non-uniform values: + /// eg. `uniform texture2D textures[10]`. + /// + /// This capability allows them to exist and to be indexed by compile time constant + /// values. + /// + /// Supported platforms: + /// - DX12 + /// - Metal (with MSL 2.0+ on macOS 10.13+) + /// - Vulkan + /// + /// This is a native only feature. + const SAMPLED_TEXTURE_BINDING_ARRAY = 0x0000_0000_0002_0000; + /// Allows shaders to index sampled texture arrays with dynamically uniform values: + /// + /// eg. `texture_array[uniform_value]` + /// + /// This capability means the hardware will also support SAMPLED_TEXTURE_BINDING_ARRAY. + /// + /// Supported platforms: + /// - DX12 + /// - Metal (with MSL 2.0+ on macOS 10.13+) + /// - Vulkan's shaderSampledImageArrayDynamicIndexing feature + /// + /// This is a native only feature. + const SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING = 0x0000_0000_0004_0000; + /// Allows shaders to index sampled texture arrays with dynamically non-uniform values: /// /// eg. `texture_array[vertex_data]` /// - /// In order to use this extension, the corresponding GLSL extension must be enabled like so: + /// In order to use this capability, the corresponding GLSL extension must be enabled like so: /// /// `#extension GL_EXT_nonuniform_qualifier : require` /// /// HLSL does not need any extension. /// + /// This capability means the hardware will also support SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING + /// and SAMPLED_TEXTURE_BINDING_ARRAY. + /// /// Supported platforms: /// - DX12 /// - Metal (with MSL 2.0+ on macOS 10.13+) - /// - Vulkan 1.2+ (or via VK_EXT_descriptor_indexing) + /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s shaderSampledImageArrayNonUniformIndexing feature) /// - /// Provided Capabilities: - /// - [`SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING`] - /// - [`UNSIZED_BINDING_ARRAY`] + /// This is a native only feature. + const SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING = 0x0000_0000_0008_0000; + /// Allows the user to create unsized uniform arrays of bindings: /// - /// This is a native only extension. + /// eg. `uniform texture2D textures[]`. /// - /// [`SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING`]: struct.Capabilities.html#associatedconstant.SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING - /// [`UNSIZED_BINDING_ARRAY`]: struct.Capabilities.html#associatedconstant.UNSIZED_BINDING_ARRAY - const BINDING_INDEXING = 0x0000_0000_0004_0000; - /// Extensions which are part of the upstream webgpu standard + /// If this capability is supported, SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING is very likely + /// to also be supported + /// + /// Supported platforms: + /// - DX12 + /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s runtimeDescriptorArray feature + /// + /// This is a native only feature. + const UNSIZED_BINDING_ARRAY = 0x0000_0000_0010_0000; + /// Features which are part of the upstream webgpu standard const ALL_WEBGPU = 0x0000_0000_0000_FFFF; - /// Extensions that require activating the unsafe extension flag + /// Features that require activating the unsafe feature flag const ALL_UNSAFE = 0xFFFF_0000_0000_0000; - /// Extensions that are only available when targeting native (not web) + /// Features that are only available when targeting native (not web) const ALL_NATIVE = 0xFFFF_FFFF_FFFF_0000; } } -/// Marker type signalling if unsafe extensions are allowed to be enabled. +/// Marker type signalling if unsafe features are allowed to be enabled. /// -/// This doesn't enable any unsafe extensions, but must be set to `allow` if -/// an unsafe extension is enabled. +/// This doesn't enable any unsafe features, but must be set to `allow` if +/// an unsafe features is enabled. /// /// The safety contract of safe Rust is that it is impossible to cause Undefined Behavior (UB) -/// from safe Rust. If an extension would allow UB to happen, it must preset an unsafe interface. -/// Enabling unsafe extensions is therefore an inherently unsafe operation. +/// from safe Rust. If a feature would allow UB to happen, it must preset an unsafe interface. +/// Enabling unsafe features is therefore an inherently unsafe operation. #[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Hash)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] -pub struct UnsafeExtensions { +pub struct UnsafeFeatures { allow_unsafe: bool, } -impl UnsafeExtensions { - /// Allow unsafe extensions to be enabled. This is an unsafe function and by calling this - /// function, you assert that even with these extensions on, it is impossible to cause UB +impl UnsafeFeatures { + /// Allow unsafe features to be enabled. This is an unsafe function and by calling this + /// function, you assert that even with these features on, it is impossible to cause UB /// from within safe Rust. pub unsafe fn allow() -> Self { Self { allow_unsafe: true } } - /// Disallow unsafe extensions. + /// Disallow unsafe features. pub fn disallow() -> Self { Self { allow_unsafe: false, } } - /// Does this marker allow unsafe extensions. + /// Does this marker allow unsafe features. pub fn allowed(self) -> bool { self.allow_unsafe } @@ -263,98 +283,15 @@ impl Default for Limits { } } -bitflags::bitflags! { - /// Capabilities of devices/adapters. - /// - /// These can be used if they are enabled and will be enabled either automatically, or by the extension - /// that provides them. - #[repr(transparent)] - #[derive(Default)] - #[cfg_attr(feature = "trace", derive(Serialize))] - #[cfg_attr(feature = "replay", derive(Deserialize))] - pub struct Capabilities: u64 { - /// Allows the user to create uniform arrays of sampled textures in shaders: - /// - /// eg. `uniform texture2D textures[10]`. - /// - /// This capability allows them to exist and to be indexed by compile time constant - /// values. - /// - /// Supported platforms: - /// - DX12 - /// - Metal (with MSL 2.0+ on macOS 10.13+) - /// - Vulkan - const SAMPLED_TEXTURE_BINDING_ARRAY = 0x0000_0000_0000_0001; - /// Allows shaders to index sampled texture arrays with dynamically uniform values: - /// - /// eg. `texture_array[uniform_value]` - /// - /// This capability means the hardware will also support SAMPLED_TEXTURE_BINDING_ARRAY. - /// - /// Supported platforms: - /// - DX12 - /// - Metal (with MSL 2.0+ on macOS 10.13+) - /// - Vulkan's shaderSampledImageArrayDynamicIndexing feature - const SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING = 0x0000_0000_0000_0002; - /// Allows shaders to index sampled texture arrays with dynamically non-uniform values: - /// - /// eg. `texture_array[vertex_data]` - /// - /// In order to use this capability, the corresponding GLSL extension must be enabled like so: - /// - /// `#extension GL_EXT_nonuniform_qualifier : require` - /// - /// HLSL does not need any extension. - /// - /// This capability means the hardware will also support SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING - /// and SAMPLED_TEXTURE_BINDING_ARRAY. - /// - /// Supported platforms: - /// - DX12 - /// - Metal (with MSL 2.0+ on macOS 10.13+) - /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s shaderSampledImageArrayNonUniformIndexing feature) - /// - /// Provided by the [`BINDING_INDEXING`] extension. This extension must be enabled for this capability - /// to be anything but false. - /// - /// [`BINDING_INDEXING`]: struct.Extensions.html#associatedconstant.BINDING_INDEXING - const SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING = 0x0000_0000_0000_0004; - /// Allows the user to create unsized uniform arrays of bindings: - /// - /// eg. `uniform texture2D textures[]`. - /// - /// If this capability is supported, SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING is very likely - /// to also be supported - /// - /// Supported platforms: - /// - DX12 - /// - Vulkan 1.2+ (or VK_EXT_descriptor_indexing)'s runtimeDescriptorArray feature - /// - /// Provided by the [`BINDING_INDEXING`] extension. This extension must be enabled for this capability - /// to be anything but false. - /// - /// [`BINDING_INDEXING`]: struct.Extensions.html#associatedconstant.BINDING_INDEXING - const UNSIZED_BINDING_ARRAY = 0x0000_0000_0000_0008; - /// All capabilities that are not provided by an extension - const ALL_BUILT_IN = - Self::SAMPLED_TEXTURE_BINDING_ARRAY.bits | - Self::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING.bits; - /// All capabilities that are provided by the BINDING_INDEXING extension - const ALL_BINDING_INDEXING = - Self::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING.bits | - Self::UNSIZED_BINDING_ARRAY.bits; - } -} - /// Describes a [`Device`]. #[repr(C)] #[derive(Clone, Debug, Default)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct DeviceDescriptor { - /// Extensions that the device should support. If any extension is not supported by + /// Features that the device should support. If any feature is not supported by /// the adapter, creating a device will panic. - pub extensions: Extensions, + 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, @@ -968,13 +905,13 @@ bitflags::bitflags! { /// Allow a buffer to be mapped for reading using [`Buffer::map_async`] + [`Buffer::get_mapped_range`]. /// This does not include creating a buffer with [`BufferDescriptor::mapped_at_creation`] set. /// - /// If [`Extensions::MAPPABLE_PRIMARY_BUFFERS`] isn't enabled, the only other usage a buffer + /// If [`Features::MAPPABLE_PRIMARY_BUFFERS`] isn't enabled, the only other usage a buffer /// may have is COPY_DST. const MAP_READ = 1; /// Allow a buffer to be mapped for writing using [`Buffer::map_async`] + [`Buffer::get_mapped_range_mut`]. /// This does not include creating a buffer with `mapped_at_creation` set. /// - /// If [`Extensions::MAPPABLE_PRIMARY_BUFFERS`] extension isn't enabled, the only other usage a buffer + /// If [`Features::MAPPABLE_PRIMARY_BUFFERS`] feature isn't enabled, the only other usage a buffer /// may have is COPY_SRC. const MAP_WRITE = 2; /// Allow a buffer to be the source buffer for a [`CommandEncoder::copy_buffer_to_buffer`] or [`CommandEncoder::copy_buffer_to_texture`] @@ -1461,9 +1398,6 @@ pub struct SamplerDescriptor { pub lod_max_clamp: f32, /// If this is enabled, this is a comparison sampler using the given comparison function. pub compare: Option, - /// Anisotropic filtering extension must be enabled if this value is - /// anything other than 0 or 1. - /// /// Valid values: 1, 2, 4, 8, and 16. pub anisotropy_clamp: Option, /// This struct must be partially constructed from its default