refactor: vertex_index_common: use strum enum iter.

Replace manual enumerations of various `enum`s with `derive`d ones via
`strum::{EnumIter, IntoEnumIterator}`.
This commit is contained in:
Erich Gubler 2024-06-18 15:53:56 -04:00
parent 9f34acd567
commit 7600c61b72
4 changed files with 19 additions and 29 deletions

1
Cargo.lock generated
View File

@ -4394,6 +4394,7 @@ dependencies = [
"profiling",
"serde",
"serde_json",
"strum",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",

View File

@ -121,6 +121,7 @@ serde = "1"
serde_json = "1.0.119"
smallvec = "1"
static_assertions = "1.1.0"
strum = { version = "0.25.0", features = ["derive"] }
tracy-client = "0.17"
thiserror = "1"
wgpu = { version = "0.20.0", path = "./wgpu", default-features = false }

View File

@ -35,6 +35,7 @@ pollster.workspace = true
profiling.workspace = true
serde_json.workspace = true
serde.workspace = true
strum = { workspace = true, features = ["derive"] }
wgpu-macros.workspace = true
wgpu.workspace = true
wgt = { workspace = true, features = ["serde"] }

View File

@ -5,6 +5,7 @@
use std::{num::NonZeroU64, ops::Range};
use strum::IntoEnumIterator;
use wgpu::util::{BufferInitDescriptor, DeviceExt, RenderEncoder};
use wgpu_test::{gpu_test, GpuTestConfiguration, TestParameters, TestingContext};
@ -79,7 +80,7 @@ impl Draw {
}
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, strum::EnumIter)]
enum TestCase {
/// A single draw call with 6 vertices
Draw,
@ -94,14 +95,6 @@ enum TestCase {
}
impl TestCase {
const ARRAY: [Self; 5] = [
Self::Draw,
Self::DrawNonZeroFirstVertex,
Self::DrawBaseVertex,
Self::DrawInstanced,
Self::DrawNonZeroFirstInstance,
];
// Get the draw calls for this test case
fn draws(&self) -> &'static [Draw] {
match self {
@ -148,7 +141,7 @@ impl TestCase {
}
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, strum::EnumIter)]
enum IdSource {
/// Use buffers to load the vertex and instance index
Buffers,
@ -156,30 +149,18 @@ enum IdSource {
Builtins,
}
impl IdSource {
const ARRAY: [Self; 2] = [Self::Buffers, Self::Builtins];
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, strum::EnumIter)]
enum DrawCallKind {
Direct,
Indirect,
}
impl DrawCallKind {
const ARRAY: [Self; 2] = [Self::Direct, Self::Indirect];
}
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, strum::EnumIter)]
enum EncoderKind {
RenderPass,
RenderBundle,
}
impl EncoderKind {
const ARRAY: [Self; 2] = [Self::RenderPass, Self::RenderBundle];
}
struct Test {
case: TestCase,
id_source: IdSource,
@ -356,11 +337,17 @@ async fn vertex_index_common(ctx: TestingContext) {
)
.create_view(&wgpu::TextureViewDescriptor::default());
let mut tests = Vec::with_capacity(5 * 2 * 2 * 2);
for case in TestCase::ARRAY {
for id_source in IdSource::ARRAY {
for draw_call_kind in DrawCallKind::ARRAY {
for encoder_kind in EncoderKind::ARRAY {
let mut tests = Vec::with_capacity(
TestCase::iter().count()
* IdSource::iter().count()
* DrawCallKind::iter().count()
* EncoderKind::iter().count()
* [false, true].iter().count(),
);
for case in TestCase::iter() {
for id_source in IdSource::iter() {
for draw_call_kind in DrawCallKind::iter() {
for encoder_kind in EncoderKind::iter() {
for vertex_pulling_transform in [false, true] {
tests.push(Test {
case,