diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index edfb75547..9e5610ec1 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -324,7 +324,9 @@ impl Device { } else if (Bu::MAP_READ | Bu::COPY_DST).contains(desc.usage) { MemoryUsage::Staging { read_back: true } } else { - let is_native_only = false; + let is_native_only = self + .extensions + .contains(wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS); assert!( is_native_only, "MAP usage can only be combined with the opposite COPY, requested {:?}", diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 2b1d8bfa3..0ea5181a0 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -128,7 +128,7 @@ impl Adapter { fn new(raw: hal::adapter::Adapter, unsafe_extensions: wgt::UnsafeExtensions) -> Self { let adapter_features = raw.physical_device.features(); - let mut extensions = wgt::Extensions::default(); + let mut extensions = wgt::Extensions::default() | wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS; extensions.set( wgt::Extensions::ANISOTROPIC_FILTERING, adapter_features.contains(hal::Features::SAMPLER_ANISOTROPY), @@ -647,6 +647,13 @@ impl Global { ); enabled_features |= hal::Features::SAMPLER_ANISOTROPY; } + if desc + .extensions + .contains(wgt::Extensions::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"); + } let family = adapter .raw diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 172eb8c55..e55abe659 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -132,11 +132,22 @@ bitflags::bitflags! { #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct Extensions: u64 { + /// Allow anisotropic filtering in samplers. + /// /// This is a native only extension. Support is planned to be added to webgpu, /// but it is not yet implemented. /// /// https://github.com/gpuweb/gpuweb/issues/696 const ANISOTROPIC_FILTERING = 0x0000_0000_0001_0000; + /// 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. + /// + /// This is only beneficial on systems that share memory between CPU and GPU. If enabled + /// on a system that doesn't, this can severely hinder performance. Only use if you understand + /// the consequences. + /// + /// This is a native only extension. + const MAPPABLE_PRIMARY_BUFFERS = 0x0000_0000_0002_0000; /// Extensions which are part of the upstream webgpu standard const ALL_WEBGPU = 0x0000_0000_0000_FFFF; /// Extensions that require activating the unsafe extension flag