mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 14:31:08 +01:00
fix(types): Exclude SURFACE_VIEW_FORMATS from compliant() (#10425)
Co-authored-by: Andy Leiserson <aleiserson@mozilla.com>
This commit is contained in:
1 parent
a504aad247
commit
889eea9505
3 files changed
+44
-6
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -902,7 +902,8 @@ pub struct SurfaceConfiguration<V> {
|
||||
/// 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<V> {
|
||||
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,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user