Extend texture tests with exhaust (#9172)

This commit is contained in:
TornaxO7 authored and GitHub committed 2026-03-24 13:52:54 -06:00
1 parent a53ffffe38
commit 098aaae40a
10 files changed
+170 -219

No files matched your search

+1
View File
@@ -24,6 +24,7 @@ skip = [
# Deno uses an old version
{ name = "bincode", version = "1.3.3" },
{ name = "which", version = "6.0.3" },
{ name = "itertools", version = "0.13.0" },
# Winit uses an old version via android-activity → jni
{ name = "windows-sys", version = "0.45" },
Generated
+32
View File
@@ -1275,6 +1275,29 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5692dd7b5a1978a5aeb0ce83b7655c58ca8efdcb79d21036ea249da95afec2c6"
[[package]]
name = "exhaust"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30b727ccdc10d28c68e775e7167048866fadcc1c39a31d489922cf9dc496becc"
dependencies = [
"exhaust-macros",
"itertools 0.14.0",
"mutants",
]
[[package]]
name = "exhaust-macros"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d9bba791cce787703541f40494aa1e0627394c6382b980850bb521a76ab1b80"
dependencies = [
"itertools 0.14.0",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "fastrand"
version = "2.3.0"
@@ -2321,6 +2344,12 @@ dependencies = [
"pxfm",
]
[[package]]
name = "mutants"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0287524726960e07b119cebd01678f852f147742ae0d925e6a520dca956126"
[[package]]
name = "naga"
version = "29.0.0"
@@ -4811,6 +4840,7 @@ dependencies = [
"anyhow",
"bitflags 2.11.0",
"env_logger",
"exhaust",
"hashbrown 0.16.1",
"pico-args",
"pollster",
@@ -4887,6 +4917,8 @@ version = "29.0.0"
dependencies = [
"bitflags 2.11.0",
"bytemuck",
"exhaust",
"hashbrown 0.16.1",
"js-sys",
"log",
"raw-window-handle",
+1
View File
@@ -124,6 +124,7 @@ diff = "0.1"
document-features = "0.2.10"
encase = "0.12"
env_logger = { version = "0.11", default-features = false }
exhaust = "0.2"
fern = "0.7"
flume = "0.12"
futures-lite = "2"
+2 -1
View File
@@ -14,12 +14,13 @@ rust-version.workspace = true
anyhow.workspace = true
bitflags.workspace = true
env_logger.workspace = true
exhaust.workspace = true
hashbrown = { workspace = true, features = ["serde"] }
pico-args.workspace = true
pollster.workspace = true
serde = { workspace = true, features = ["default"] }
serde_json.workspace = true
wgpu.workspace = true
wgpu = { workspace = true, features = ["exhaust"] }
[lints.clippy]
disallowed_types = "allow"
+4 -3
View File
@@ -1,11 +1,12 @@
use std::io;
use bitflags::Flags;
use exhaust::Exhaust;
use wgpu::AdapterInfo;
use crate::{
report::{AdapterReport, GpuReport},
texture::{self, TEXTURE_FORMAT_LIST},
texture,
};
trait FlagsExt: Flags {
@@ -288,7 +289,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize
write!(output, "\t\t {texture_format_whitespace}")?;
wgpu::TextureUsages::println_table_header(output)?;
for format in TEXTURE_FORMAT_LIST {
for format in wgpu::TextureFormat::exhaust() {
let features = texture_format_features[&format];
let format_name = texture::texture_format_name(format);
write!(output, "\t\t{format_name:>max_format_name_size$}")?;
@@ -316,7 +317,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize
write!(output, "\t\t {texture_format_whitespace}")?;
wgpu::TextureFormatFeatureFlags::println_table_header(output)?;
for format in TEXTURE_FORMAT_LIST {
for format in wgpu::TextureFormat::exhaust() {
let features = texture_format_features[&format];
let format_name = texture::texture_format_name(format);
+2 -4
View File
@@ -1,5 +1,6 @@
use std::io;
use exhaust::Exhaust;
use hashbrown::HashMap;
use serde::{Deserialize, Serialize};
use wgpu::{
@@ -7,8 +8,6 @@ use wgpu::{
TextureFormatFeatures,
};
use crate::texture;
/// Report specifying the capabilities of the GPUs on the system.
///
/// Must be synchronized with the definition on tests/src/report.rs.
@@ -33,8 +32,7 @@ impl GpuReport {
let features = adapter.features();
let limits = adapter.limits();
let downlevel_caps = adapter.get_downlevel_capabilities();
let texture_format_features = texture::TEXTURE_FORMAT_LIST
.into_iter()
let texture_format_features = wgpu::TextureFormat::exhaust()
.map(|format| (format, adapter.get_texture_format_features(format)))
.collect();
+3 -138
View File
@@ -1,142 +1,8 @@
// Lets keep these on one line
#[rustfmt::skip]
pub const TEXTURE_FORMAT_LIST: [wgpu::TextureFormat; 118] = [
wgpu::TextureFormat::R8Unorm,
wgpu::TextureFormat::R8Snorm,
wgpu::TextureFormat::R8Uint,
wgpu::TextureFormat::R8Sint,
wgpu::TextureFormat::R16Uint,
wgpu::TextureFormat::R16Sint,
wgpu::TextureFormat::R16Unorm,
wgpu::TextureFormat::R16Snorm,
wgpu::TextureFormat::R16Float,
wgpu::TextureFormat::Rg8Unorm,
wgpu::TextureFormat::Rg8Snorm,
wgpu::TextureFormat::Rg8Uint,
wgpu::TextureFormat::Rg8Sint,
wgpu::TextureFormat::R32Uint,
wgpu::TextureFormat::R32Sint,
wgpu::TextureFormat::R32Float,
wgpu::TextureFormat::Rg16Uint,
wgpu::TextureFormat::Rg16Sint,
wgpu::TextureFormat::Rg16Unorm,
wgpu::TextureFormat::Rg16Snorm,
wgpu::TextureFormat::Rg16Float,
wgpu::TextureFormat::Rgba8Unorm,
wgpu::TextureFormat::Rgba8UnormSrgb,
wgpu::TextureFormat::Rgba8Snorm,
wgpu::TextureFormat::Rgba8Uint,
wgpu::TextureFormat::Rgba8Sint,
wgpu::TextureFormat::Bgra8Unorm,
wgpu::TextureFormat::Bgra8UnormSrgb,
wgpu::TextureFormat::Rgb9e5Ufloat,
wgpu::TextureFormat::Rgb10a2Uint,
wgpu::TextureFormat::Rgb10a2Unorm,
wgpu::TextureFormat::Rg11b10Ufloat,
wgpu::TextureFormat::R64Uint,
wgpu::TextureFormat::Rg32Uint,
wgpu::TextureFormat::Rg32Sint,
wgpu::TextureFormat::Rg32Float,
wgpu::TextureFormat::Rgba16Uint,
wgpu::TextureFormat::Rgba16Sint,
wgpu::TextureFormat::Rgba16Unorm,
wgpu::TextureFormat::Rgba16Snorm,
wgpu::TextureFormat::Rgba16Float,
wgpu::TextureFormat::Rgba32Uint,
wgpu::TextureFormat::Rgba32Sint,
wgpu::TextureFormat::Rgba32Float,
wgpu::TextureFormat::Stencil8,
wgpu::TextureFormat::Depth16Unorm,
wgpu::TextureFormat::Depth24Plus,
wgpu::TextureFormat::Depth24PlusStencil8,
wgpu::TextureFormat::Depth32Float,
wgpu::TextureFormat::Depth32FloatStencil8,
wgpu::TextureFormat::NV12,
wgpu::TextureFormat::P010,
wgpu::TextureFormat::Bc1RgbaUnorm,
wgpu::TextureFormat::Bc1RgbaUnormSrgb,
wgpu::TextureFormat::Bc2RgbaUnorm,
wgpu::TextureFormat::Bc2RgbaUnormSrgb,
wgpu::TextureFormat::Bc3RgbaUnorm,
wgpu::TextureFormat::Bc3RgbaUnormSrgb,
wgpu::TextureFormat::Bc4RUnorm,
wgpu::TextureFormat::Bc4RSnorm,
wgpu::TextureFormat::Bc5RgUnorm,
wgpu::TextureFormat::Bc5RgSnorm,
wgpu::TextureFormat::Bc6hRgbUfloat,
wgpu::TextureFormat::Bc6hRgbFloat,
wgpu::TextureFormat::Bc7RgbaUnorm,
wgpu::TextureFormat::Bc7RgbaUnormSrgb,
wgpu::TextureFormat::Etc2Rgb8Unorm,
wgpu::TextureFormat::Etc2Rgb8UnormSrgb,
wgpu::TextureFormat::Etc2Rgb8A1Unorm,
wgpu::TextureFormat::Etc2Rgb8A1UnormSrgb,
wgpu::TextureFormat::Etc2Rgba8Unorm,
wgpu::TextureFormat::Etc2Rgba8UnormSrgb,
wgpu::TextureFormat::EacR11Unorm,
wgpu::TextureFormat::EacR11Snorm,
wgpu::TextureFormat::EacRg11Unorm,
wgpu::TextureFormat::EacRg11Snorm,
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B4x4, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B4x4, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B4x4, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x4, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x4, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x4, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x5, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x5, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B5x5, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x5, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x5, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x5, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x6, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x6, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B6x6, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x5, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x5, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x5, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x6, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x6, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x6, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x8, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x8, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B8x8, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x5, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x5, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x5, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x6, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x6, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x6, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x8, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x8, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x8, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x10, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x10, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B10x10, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x10, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x10, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x10, channel: wgpu::AstcChannel::Hdr },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x12, channel: wgpu::AstcChannel::Unorm },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x12, channel: wgpu::AstcChannel::UnormSrgb },
wgpu::TextureFormat::Astc { block: wgpu::AstcBlock::B12x12, channel: wgpu::AstcChannel::Hdr },
];
#[test]
fn test_uniqueness_in_texture_format_list() {
use std::collections::HashSet;
let uniq: HashSet<wgpu::TextureFormat> = TEXTURE_FORMAT_LIST.into_iter().collect();
let mut duplicated = TEXTURE_FORMAT_LIST.to_vec();
uniq.iter().for_each(|u| {
let first_occurrence = duplicated.iter().position(|el| u == el).unwrap();
duplicated.remove(first_occurrence);
});
assert_eq!(duplicated, vec![]);
}
use exhaust::Exhaust;
#[test]
fn test_compute_render_extent() {
for format in TEXTURE_FORMAT_LIST {
for format in wgpu::TextureFormat::exhaust() {
let desc = wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
@@ -211,8 +77,7 @@ fn test_compute_render_extent() {
}
pub fn max_texture_format_string_size() -> usize {
TEXTURE_FORMAT_LIST
.into_iter()
wgpu::TextureFormat::exhaust()
.map(|f| texture_format_name(f).len())
.max()
.unwrap()
+4
View File
@@ -47,10 +47,12 @@ counters = []
trace = ["std"]
# Enable web-specific dependencies for wasm.
web = ["dep:js-sys", "dep:web-sys"]
exhaust = ["dep:exhaust"]
[dependencies]
bitflags.workspace = true
bytemuck = { workspace = true, features = ["derive"] }
exhaust = { workspace = true, optional = true }
log.workspace = true
raw-window-handle.workspace = true
serde = { workspace = true, default-features = false, features = [
@@ -71,5 +73,7 @@ web-sys = { workspace = true, optional = true, default-features = false, feature
] }
[dev-dependencies]
exhaust.workspace = true
hashbrown.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
+116 -73
View File
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
pub enum AstcBlock {
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px).
B4x4,
@@ -44,6 +45,7 @@ pub enum AstcBlock {
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
pub enum AstcChannel {
/// 8 bit integer RGBA, [0, 255] converted to/from linear-color float [0, 1] in shader.
///
@@ -122,6 +124,7 @@ bitflags::bitflags! {
/// [sRGB transfer function]: https://en.wikipedia.org/wiki/SRGB#Transfer_function_(%22gamma%22)
#[repr(C)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(any(test, feature = "exhaust"), derive(exhaust::Exhaust))]
pub enum TextureFormat {
// Normal 8 bit formats
/// Red channel only. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader.
@@ -2000,6 +2003,8 @@ pub struct TextureFormatFeatures {
#[cfg(test)]
mod tests {
use super::*;
use exhaust::Exhaust;
use hashbrown::HashSet;
#[test]
fn texture_format_serialize() {
@@ -2606,129 +2611,167 @@ mod tests {
/// test if `TextureFormat::is_depth_stencil_format` is behaving correctly
#[test]
fn is_depth_stencil_format() {
let depth_stencil_formats = [
// the only valid formats
let depth_stencil_formats: HashSet<TextureFormat> = HashSet::from([
TextureFormat::Stencil8,
TextureFormat::Depth16Unorm,
TextureFormat::Depth24Plus,
TextureFormat::Depth24PlusStencil8,
TextureFormat::Depth32Float,
TextureFormat::Depth32FloatStencil8,
];
]);
for format in depth_stencil_formats {
assert!(format.is_depth_stencil_format());
}
// some non-depth-stencil-formats shouldn't be accepted
let non_depth_stencil_formats = [
TextureFormat::R8Unorm,
TextureFormat::Rgba8Unorm,
TextureFormat::Rg16Uint,
TextureFormat::NV12,
];
for format in non_depth_stencil_formats {
assert!(!format.is_depth_stencil_format());
for format in TextureFormat::exhaust() {
if depth_stencil_formats.contains(&format) {
assert!(format.is_depth_stencil_format());
} else {
assert!(!format.is_depth_stencil_format());
}
}
}
/// test if `TextureFormat::is_combined_depth_stencil_format` is behaving correctly
#[test]
fn is_combined_depth_stencil_format() {
// the only valid formats
let valid_formats = [
TextureFormat::Depth24PlusStencil8,
TextureFormat::Depth32FloatStencil8,
];
for format in valid_formats {
assert!(format.is_combined_depth_stencil_format());
}
let some_invalid_formats = [
TextureFormat::Depth16Unorm,
TextureFormat::Depth24Plus,
TextureFormat::Stencil8,
TextureFormat::Rgba8UnormSrgb,
TextureFormat::Rgba8Unorm,
];
for format in some_invalid_formats {
assert!(!format.is_combined_depth_stencil_format());
for format in TextureFormat::exhaust() {
if valid_formats.contains(&format) {
assert!(format.is_combined_depth_stencil_format());
} else {
assert!(!format.is_combined_depth_stencil_format());
}
}
}
/// test if `TextureFormat::has_color_aspect` is behaving correctly
#[test]
fn has_color_aspect() {
let some_valid_formats = [
// the only valid formats (without Astc)
let valid_formats: HashSet<TextureFormat> = HashSet::from([
TextureFormat::R8Unorm,
TextureFormat::R8Snorm,
TextureFormat::R8Uint,
TextureFormat::R8Sint,
TextureFormat::R16Uint,
TextureFormat::R16Sint,
TextureFormat::R16Unorm,
TextureFormat::R16Snorm,
TextureFormat::R16Float,
TextureFormat::Rg8Unorm,
TextureFormat::Bc7RgbaUnorm,
TextureFormat::Rg8Snorm,
TextureFormat::Rg8Uint,
TextureFormat::Rg8Sint,
TextureFormat::R32Uint,
TextureFormat::R32Sint,
TextureFormat::R32Float,
TextureFormat::Rg16Uint,
TextureFormat::Rg16Sint,
TextureFormat::Rg16Unorm,
TextureFormat::Rg16Snorm,
TextureFormat::Rg16Float,
TextureFormat::Rgba8Unorm,
];
TextureFormat::Rgba8UnormSrgb,
TextureFormat::Rgba8Snorm,
TextureFormat::Rgba8Uint,
TextureFormat::Rgba8Sint,
TextureFormat::Bgra8Unorm,
TextureFormat::Bgra8UnormSrgb,
TextureFormat::Rgb9e5Ufloat,
TextureFormat::Rgb10a2Uint,
TextureFormat::Rgb10a2Unorm,
TextureFormat::Rg11b10Ufloat,
TextureFormat::R64Uint,
TextureFormat::Rg32Uint,
TextureFormat::Rg32Sint,
TextureFormat::Rg32Float,
TextureFormat::Rgba16Uint,
TextureFormat::Rgba16Sint,
TextureFormat::Rgba16Unorm,
TextureFormat::Rgba16Snorm,
TextureFormat::Rgba16Float,
TextureFormat::Rgba32Uint,
TextureFormat::Rgba32Sint,
TextureFormat::Rgba32Float,
TextureFormat::Bc1RgbaUnorm,
TextureFormat::Bc1RgbaUnormSrgb,
TextureFormat::Bc2RgbaUnorm,
TextureFormat::Bc2RgbaUnormSrgb,
TextureFormat::Bc3RgbaUnorm,
TextureFormat::Bc3RgbaUnormSrgb,
TextureFormat::Bc4RUnorm,
TextureFormat::Bc4RSnorm,
TextureFormat::Bc5RgUnorm,
TextureFormat::Bc5RgSnorm,
TextureFormat::Bc6hRgbUfloat,
TextureFormat::Bc6hRgbFloat,
TextureFormat::Bc7RgbaUnorm,
TextureFormat::Bc7RgbaUnormSrgb,
TextureFormat::Etc2Rgb8Unorm,
TextureFormat::Etc2Rgb8UnormSrgb,
TextureFormat::Etc2Rgb8A1Unorm,
TextureFormat::Etc2Rgb8A1UnormSrgb,
TextureFormat::Etc2Rgba8Unorm,
TextureFormat::Etc2Rgba8UnormSrgb,
TextureFormat::EacR11Unorm,
TextureFormat::EacR11Snorm,
TextureFormat::EacRg11Unorm,
TextureFormat::EacRg11Snorm,
]);
for format in some_valid_formats {
assert!(format.has_color_aspect());
}
let some_invalid_formats = [
TextureFormat::NV12,
TextureFormat::Stencil8,
TextureFormat::Depth24PlusStencil8,
];
for format in some_invalid_formats {
assert!(!format.has_color_aspect());
for format in TextureFormat::exhaust() {
if let TextureFormat::Astc { .. } = format {
// can't add all `Astc` cases to the list above...
assert!(format.has_color_aspect(), "{:?} failed", format);
} else if valid_formats.contains(&format) {
assert!(format.has_color_aspect(), "{:?} failed", format);
} else {
assert!(!format.has_color_aspect(), "{:?} failed", format);
}
}
}
/// test if `TextureFormat::has_depth_aspect` is behaving correctly
#[test]
fn has_depth_aspect() {
let valid_formats = [
// the only valid formats
let valid_formats: HashSet<TextureFormat> = HashSet::from([
TextureFormat::Depth16Unorm,
TextureFormat::Depth24Plus,
TextureFormat::Depth24PlusStencil8,
TextureFormat::Depth32Float,
TextureFormat::Depth32FloatStencil8,
];
]);
for format in valid_formats {
assert!(format.has_depth_aspect());
}
let some_invalid_formats = [
TextureFormat::Rgba8Unorm,
TextureFormat::Bc7RgbaUnorm,
TextureFormat::Stencil8,
];
for format in some_invalid_formats {
assert!(!format.has_depth_aspect());
for format in TextureFormat::exhaust() {
if valid_formats.contains(&format) {
assert!(format.has_depth_aspect());
} else {
assert!(!format.has_depth_aspect());
}
}
}
/// test if `TextureFormat::has_stencil_aspect` is behaving correctly
#[test]
fn has_stencil_aspect() {
let valid_formats = [
// the only valid formats
let valid_formats: HashSet<TextureFormat> = HashSet::from([
TextureFormat::Stencil8,
TextureFormat::Depth24PlusStencil8,
TextureFormat::Depth32FloatStencil8,
];
]);
for format in valid_formats {
assert!(format.has_stencil_aspect());
}
let some_invalid_formats = [
TextureFormat::R8Unorm,
TextureFormat::Depth16Unorm,
TextureFormat::NV12,
];
for format in some_invalid_formats {
assert!(!format.has_stencil_aspect());
for format in TextureFormat::exhaust() {
if valid_formats.contains(&format) {
assert!(format.has_stencil_aspect());
} else {
assert!(!format.has_stencil_aspect());
}
}
}
}
+5
View File
@@ -190,6 +190,11 @@ std = [
## based on whether `std` is enabled or not.
parking_lot = ["dep:parking_lot"]
## Enables `exhaust` method for `TextureFormat` of `wgpu-types`.
##
## This is relevant for `wgpu-info`.
exhaust = ["wgpu-types/exhaust"]
#########################
# Standard Dependencies #
#########################