Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: vertex_index_common: remove footguns in tests matrix init. #5840

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ getrandom = "0.2"
glam = "0.27"
heck = "0.5.0"
image = { version = "0.24", default-features = false, features = ["png"] }
itertools = { version = "0.10.5" }
ktx2 = "0.3"
libc = "0.2"
# libloading 0.8 switches from `winapi` to `windows-sys`; permit either
Expand Down Expand Up @@ -121,6 +122,7 @@ serde = "1"
serde_json = "1.0.116"
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" }
Expand Down
2 changes: 2 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bytemuck.workspace = true
cfg-if.workspace = true
ctor.workspace = true
futures-lite.workspace = true
itertools.workspace = true
libtest-mimic.workspace = true
log.workspace = true
parking_lot.workspace = true
Expand All @@ -35,6 +36,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"] }
Expand Down
64 changes: 18 additions & 46 deletions tests/tests/vertex_indices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

use std::{num::NonZeroU64, ops::Range};

use itertools::Itertools;
use strum::IntoEnumIterator;
use wgpu::util::{BufferInitDescriptor, DeviceExt, RenderEncoder};

use wgpu_test::{gpu_test, GpuTestConfiguration, TestParameters, TestingContext};
use wgt::RenderBundleDescriptor;

Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -148,38 +141,26 @@ impl TestCase {
}
}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, strum::EnumIter)]
enum IdSource {
/// Use buffers to load the vertex and instance index
Buffers,
/// Use builtins to load the vertex and instance index
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,
Expand Down Expand Up @@ -337,26 +318,17 @@ async fn vertex_index_common(ctx: TestingContext) {
)
.create_view(&wgpu::TextureViewDescriptor::default());

let mut tests = Vec::with_capacity(
TestCase::ARRAY.len()
* IdSource::ARRAY.len()
* DrawCallKind::ARRAY.len()
* EncoderKind::ARRAY.len(),
);
for case in TestCase::ARRAY {
for id_source in IdSource::ARRAY {
for draw_call_kind in DrawCallKind::ARRAY {
for encoder_kind in EncoderKind::ARRAY {
tests.push(Test {
case,
id_source,
draw_call_kind,
encoder_kind,
})
}
}
}
}
let tests = TestCase::iter()
.cartesian_product(IdSource::iter())
.cartesian_product(DrawCallKind::iter())
.cartesian_product(EncoderKind::iter())
.map(|(((case, id_source), draw_call_kind), encoder_kind)| Test {
case,
id_source,
draw_call_kind,
encoder_kind,
})
.collect::<Vec<_>>();

let features = ctx.adapter.features();

Expand All @@ -369,7 +341,7 @@ async fn vertex_index_common(ctx: TestingContext) {

let expected = test.expectation(&ctx);

let buffer_size = 4 * expected.len() as u64;
let buffer_size = (std::mem::size_of_val(&expected[0]) * expected.len()) as u64;
let cpu_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: buffer_size,
Expand Down
Loading