From 889eea9505665d2812ec008f5f2a5560a49ca924 Mon Sep 17 00:00:00 2001 From: KOGA Mitsuhiro Date: Tue, 13 Oct 2026 10:54:39 +0900 Subject: [PATCH] fix(types): Exclude SURFACE_VIEW_FORMATS from compliant() (#10425) Co-authored-by: Andy Leiserson --- wgpu-core/src/instance.rs | 14 ++++++++++++++ wgpu-types/src/limits.rs | 20 ++++++++++++++++++-- wgpu-types/src/surface.rs | 16 ++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 6b84c0d17..4e19aa74d 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -1622,6 +1622,20 @@ mod tests { )); } + #[test] + fn missing_surface_view_formats_allowed_with_strict_compliance() { + let downlevel = wgt::DownlevelCapabilities { + flags: wgt::DownlevelFlags::all() - wgt::DownlevelFlags::SURFACE_VIEW_FORMATS, + ..Default::default() + }; + assert!(adapter_allowed( + InstanceFlags::STRICT_WEBGPU_COMPLIANCE, + &"", + &wgt::Limits::defaults(), + &downlevel + )); + } + #[test] fn fully_compliant_adapter_always_allowed() { assert!(adapter_allowed( diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index 48b0fd5e2..0b33cbf97 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize}; #[cfg(doc)] use crate::{Features, TextureFormat}; +use naga_types::link_to_wgpu_item; + /// Invoke a macro for each of the limits. /// /// The supplied macro should take two arguments. The first is a limit name, as @@ -1304,13 +1306,27 @@ bitflags::bitflags! { } impl DownlevelFlags { - /// All flags that indicate if the backend is WebGPU compliant + /// Returns the set of flags required for an adapter to be considered WebGPU compliant. + /// + /// The only downlevel flags that are not required on a compliant adapter are: + /// - [`Self::ANISOTROPIC_FILTERING`], because the filtering behavior is + /// implementation-defined, so performing no filtering at all is allowed. + /// - [`Self::SURFACE_VIEW_FORMATS`], because [`Surface`] does not exactly + /// correspond to a WebGPU canvas, and most users of `wgpu` desiring + /// strict WebGPU compliance implement canvas view formats by means + /// other than [`Surface`]. + /// + #[doc = link_to_wgpu_item!(struct Surface)] #[must_use] pub const fn compliant() -> Self { // We use manual bit twiddling to make this a const fn as `Sub` and `.remove` aren't const // WebGPU doesn't actually require aniso - Self::from_bits_truncate(Self::all().bits() & !Self::ANISOTROPIC_FILTERING.bits()) + // or surface view formats, which only apply to `wgpu::Surface` + Self::from_bits_truncate( + Self::all().bits() + & !(Self::ANISOTROPIC_FILTERING.bits() | Self::SURFACE_VIEW_FORMATS.bits()), + ) } } diff --git a/wgpu-types/src/surface.rs b/wgpu-types/src/surface.rs index 591a03527..f024a1b0c 100644 --- a/wgpu-types/src/surface.rs +++ b/wgpu-types/src/surface.rs @@ -902,7 +902,8 @@ pub struct SurfaceConfiguration { /// The usage of the swap chain. The only usage guaranteed to be supported is [`TextureUsages::RENDER_ATTACHMENT`]. pub usage: TextureUsages, /// The texture format of the swap chain. The only formats that are guaranteed are - /// [`TextureFormat::Bgra8Unorm`] and [`TextureFormat::Bgra8UnormSrgb`]. + /// [`TextureFormat::Bgra8Unorm`] and [`TextureFormat::Bgra8UnormSrgb`]. Unlike + /// WebGPU canvases, `wgpu` supports sRGB surface formats. pub format: TextureFormat, /// The color space in which the presentation engine interprets the values /// written to the swap chain. @@ -970,11 +971,18 @@ pub struct SurfaceConfiguration { pub desired_maximum_frame_latency: u32, /// Specifies how the alpha channel of the textures should be handled during compositing. pub alpha_mode: CompositeAlphaMode, - /// Specifies what view formats will be allowed when calling `Texture::create_view` on the texture returned by `Surface::get_current_texture`. + /// Specifies what view formats will be allowed when calling `Texture::create_view` on + /// the texture returned by `Surface::get_current_texture`. /// - /// View formats of the same format as the texture are always allowed. + /// Views with the same format as the texture are always allowed. Views with a different + /// format than the texture require [`crate::DownlevelFlags::SURFACE_VIEW_FORMATS`]. + /// Note that `wgpu` treats adapters as [WebGPU-compliant][`crate::DownlevelFlags::compliant`] + /// even if they lack [`crate::DownlevelFlags::SURFACE_VIEW_FORMATS`]. /// - /// Note: currently, only the srgb-ness is allowed to change. (ex: `Rgba8Unorm` texture + `Rgba8UnormSrgb` view) + /// Currently, a view format may only differ from the surface in srgb-ness (ex: `Rgba8Unorm` + /// texture + `Rgba8UnormSrgb` view). + /// + /// Unlike WebGPU canvases, `wgpu` supports sRGB surface formats. pub view_formats: V, }