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 tests to be feature flag bit-width agnostic #5155

Merged
merged 1 commit into from
Jan 28, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Bottom level categories:
#### Tests

- Fix intermittent crashes on Linux in the `multithreaded_compute` test. By @jimblandy in [#5129](https://github.com/gfx-rs/wgpu/pull/5129).
- Refactor tests to read feature flags by name instead of a hardcoded hexadecimal u64. By @rodolphito in [#5155](https://github.com/gfx-rs/wgpu/pull/5155).

## v0.19.0 (2024-01-17)

Expand Down Expand Up @@ -193,7 +194,7 @@ let surface = instance.create_surface(my_window.clone())?;
```

All platform specific surface creation using points have moved into `SurfaceTargetUnsafe` as well.
For example:
For example:

Safety by @daxpedda in [#4597](https://github.com/gfx-rs/wgpu/pull/4597)
Unification by @wumpf in [#4984](https://github.com/gfx-rs/wgpu/pull/4984)
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/bind-group.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0,
features: [],
expectations: [], //not crash!
actions: [
CreateBuffer(Id(0, 1, Empty), (
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/buffer-copy.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS
features: ["MAPPABLE_PRIMARY_BUFFERS"],
expectations: [
(
name: "basic",
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/clear-buffer-texture.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0004_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS | CLEAR_TEXTURE
features: ["MAPPABLE_PRIMARY_BUFFERS", "CLEAR_TEXTURE"],
expectations: [
(
name: "Quad",
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/pipeline-statistics-query.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0005_0000_0000, // MAPPABLE_PRIMARY_BUFFERS | PIPELINE_STATISTICS_QUERY
features: ["MAPPABLE_PRIMARY_BUFFERS", "PIPELINE_STATISTICS_QUERY"],
expectations: [
(
name: "Queried number of compute invocations is correct",
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/quad.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0,
features: [],
expectations: [
(
name: "Quad",
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-buffer.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0000_0004_0000_0000, // MAPPABLE_PRIMARY_BUFFERS
features: ["MAPPABLE_PRIMARY_BUFFERS"],
expectations: [
// Ensuring that mapping zero-inits buffers.
(
Expand Down
4 changes: 2 additions & 2 deletions player/tests/data/zero-init-texture-binding.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0,
features: [],
expectations: [
(
name: "Sampled Texture",
Expand Down Expand Up @@ -56,7 +56,7 @@
format: "rgba8unorm",
usage: 9, // STORAGE + COPY_SRC
view_formats: [],
)),
)),
CreateTextureView(
id: Id(1, 1, Empty),
parent_id: Id(1, 1, Empty),
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-texture-copytobuffer.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0,
features: [],
expectations: [
(
name: "Copy to Buffer",
Expand Down
2 changes: 1 addition & 1 deletion player/tests/data/zero-init-texture-rendertarget.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: 0x0,
features: [],
expectations: [
(
name: "Render Target",
Expand Down
26 changes: 24 additions & 2 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct Expectation {
data: ExpectedData,
}

#[derive(serde::Deserialize)]
struct Test<'a> {
features: wgt::Features,
expectations: Vec<Expectation>,
Expand All @@ -72,7 +71,30 @@ impl Test<'_> {
_ => unreachable!(),
};
let string = read_to_string(path).unwrap().replace("Empty", backend_name);
ron::de::from_str(&string).unwrap()

#[derive(serde::Deserialize)]
struct SerializedTest<'a> {
features: Vec<String>,
expectations: Vec<Expectation>,
actions: Vec<wgc::device::trace::Action<'a>>,
}
let SerializedTest {
features,
expectations,
actions,
} = ron::de::from_str(&string).unwrap();
let features = features
.iter()
.map(|feature| {
wgt::Features::from_name(feature)
.unwrap_or_else(|| panic!("Invalid feature flag {}", feature))
})
.fold(wgt::Features::empty(), |a, b| a | b);
Test {
features,
expectations,
actions,
}
}

fn run(
Expand Down