Skip to content

Commit

Permalink
clean up bitflag serde
Browse files Browse the repository at this point in the history
  • Loading branch information
atlv24 committed Dec 2, 2024
1 parent 246ed3e commit 632c478
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 127 deletions.
2 changes: 1 addition & 1 deletion player/tests/data/all.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
backends: 0x3E,
backends: "VULKAN | GL | METAL | DX12 | BROWSER_WEBGPU",
tests: [
"bind-group.ron",
"buffer-copy.ron",
Expand Down
6 changes: 3 additions & 3 deletions player/tests/data/bind-group.ron
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(
features: [],
features: "",
expectations: [], //not crash!
actions: [
CreateBuffer(Id(0, 1), (
label: None,
size: 16,
usage: 64,
usage: "UNIFORM",
mapped_at_creation: false,
)),
CreateBindGroupLayout(Id(0, 1), (
label: None,
entries: [
(
binding: 0,
visibility: 0x3,
visibility: "VERTEX | FRAGMENT",
ty: Buffer(
ty: Uniform,
),
Expand Down
4 changes: 2 additions & 2 deletions player/tests/data/buffer-copy.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: ["MAPPABLE_PRIMARY_BUFFERS"],
features: "MAPPABLE_PRIMARY_BUFFERS",
expectations: [
(
name: "basic",
Expand All @@ -14,7 +14,7 @@
(
label: Some("dummy"),
size: 16,
usage: 41,
usage: "MAP_READ | COPY_DST | VERTEX",
mapped_at_creation: false,
),
),
Expand Down
8 changes: 4 additions & 4 deletions player/tests/data/clear-buffer-texture.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: ["MAPPABLE_PRIMARY_BUFFERS", "CLEAR_TEXTURE"],
features: "MAPPABLE_PRIMARY_BUFFERS | CLEAR_TEXTURE",
expectations: [
(
name: "Quad",
Expand Down Expand Up @@ -30,7 +30,7 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 27,
usage: "COPY_SRC | COPY_DST | STORAGE_BINDING | RENDER_ATTACHMENT",
view_formats: [],
)),
// First fill the texture to ensure it wasn't just zero initialized or "happened" to be zero.
Expand All @@ -56,7 +56,7 @@
(
label: Some("Output Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand All @@ -66,7 +66,7 @@
(
label: Some("Buffer to be cleared"),
size: 16,
usage: 41,
usage: "MAP_READ | COPY_DST | VERTEX",
mapped_at_creation: false,
),
),
Expand Down
6 changes: 3 additions & 3 deletions player/tests/data/pipeline-statistics-query.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: ["MAPPABLE_PRIMARY_BUFFERS", "PIPELINE_STATISTICS_QUERY"],
features: "MAPPABLE_PRIMARY_BUFFERS | PIPELINE_STATISTICS_QUERY",
expectations: [
(
name: "Queried number of compute invocations is correct",
Expand Down Expand Up @@ -41,15 +41,15 @@
desc: (
label: Some("Compute Invocation QuerySet"),
count: 2,
ty: PipelineStatistics(0x18), // FRAGMENT_SHADER_INVOCATIONS | COMPUTE_SHADER_INVOCATIONS
ty: PipelineStatistics("FRAGMENT_SHADER_INVOCATIONS | COMPUTE_SHADER_INVOCATIONS"),
),
),
CreateBuffer(
Id(0, 1),
(
label: Some("Compute Invocation Result Buffer"),
size: 16,
usage: 0b1000001001, // COPY_DST | MAP_READ
usage: "COPY_DST | MAP_READ | QUERY_RESOLVE",
mapped_at_creation: false,
),
),
Expand Down
6 changes: 3 additions & 3 deletions player/tests/data/quad.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: [],
features: "",
expectations: [
(
name: "Quad",
Expand Down Expand Up @@ -27,7 +27,7 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 27,
usage: "COPY_SRC | COPY_DST | STORAGE_BINDING | RENDER_ATTACHMENT",
view_formats: [],
)),
CreateTextureView(
Expand All @@ -40,7 +40,7 @@
(
label: Some("Output Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand Down
12 changes: 6 additions & 6 deletions player/tests/data/zero-init-buffer.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: ["MAPPABLE_PRIMARY_BUFFERS"],
features: "MAPPABLE_PRIMARY_BUFFERS",
expectations: [
// Ensuring that mapping zero-inits buffers.
(
Expand Down Expand Up @@ -43,7 +43,7 @@
(
label: Some("mapped_at_creation: false, with MAP_WRITE"),
size: 16,
usage: 131, // STORAGE + MAP_READ + MAP_WRITE
usage: "STORAGE | MAP_READ | MAP_WRITE",
mapped_at_creation: false,
),
),
Expand All @@ -52,7 +52,7 @@
(
label: Some("mapped_at_creation: false, without MAP_WRITE"),
size: 16,
usage: 129, // STORAGE + MAP_READ
usage: "STORAGE | MAP_READ",
mapped_at_creation: false,
),
),
Expand All @@ -61,7 +61,7 @@
(
label: Some("partially written"),
size: 24,
usage: 9, // MAP_READ + COPY_DST
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand All @@ -85,15 +85,15 @@
CreateBuffer(Id(3, 1), (
label: Some("used in binding"),
size: 16,
usage: 129, // STORAGE + MAP_READ
usage: "STORAGE | MAP_READ",
mapped_at_creation: false,
)),
CreateBindGroupLayout(Id(0, 1), (
label: None,
entries: [
(
binding: 0,
visibility: 4,
visibility: "COMPUTE",
ty: Buffer(
ty: Storage(
read_only: false,
Expand Down
14 changes: 7 additions & 7 deletions player/tests/data/zero-init-texture-binding.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: [],
features: "",
expectations: [
(
name: "Sampled Texture",
Expand Down Expand Up @@ -27,7 +27,7 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 5, // SAMPLED + COPY_SRC
usage: "TEXTURE_BINDING | COPY_SRC",
view_formats: [],
)),
CreateTextureView(
Expand All @@ -40,7 +40,7 @@
(
label: Some("Sampled Texture Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand All @@ -54,7 +54,7 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 9, // STORAGE + COPY_SRC
usage: "STORAGE_BINDING | COPY_SRC",
view_formats: [],
)),
CreateTextureView(
Expand All @@ -67,7 +67,7 @@
(
label: Some("Storage Texture Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand All @@ -78,7 +78,7 @@
entries: [
(
binding: 0,
visibility: 4, // COMPUTE
visibility: "COMPUTE",
ty: Texture (
sample_type: Float(filterable: true),
view_dimension: r#2d,
Expand All @@ -88,7 +88,7 @@
),
(
binding: 1,
visibility: 4, // COMPUTE
visibility: "COMPUTE",
ty: StorageTexture (
access: r#write-only,
format: "rgba8unorm",
Expand Down
6 changes: 3 additions & 3 deletions player/tests/data/zero-init-texture-copytobuffer.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: [],
features: "",
expectations: [
(
name: "Copy to Buffer",
Expand All @@ -20,15 +20,15 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 1, // COPY_SRC
usage: "COPY_SRC",
view_formats: [],
)),
CreateBuffer(
Id(0, 1),
(
label: Some("Copy to Buffer Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand Down
6 changes: 3 additions & 3 deletions player/tests/data/zero-init-texture-rendertarget.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(
features: [],
features: "",
expectations: [
(
name: "Render Target",
Expand All @@ -20,7 +20,7 @@
sample_count: 1,
dimension: r#2d,
format: "rgba8unorm",
usage: 17, // RENDER_ATTACHMENT + COPY_SRC
usage: "RENDER_ATTACHMENT | COPY_SRC",
view_formats: [],
)),
CreateTextureView(
Expand All @@ -33,7 +33,7 @@
(
label: Some("Render Target Buffer"),
size: 16384,
usage: 9,
usage: "MAP_READ | COPY_DST",
mapped_at_creation: false,
),
),
Expand Down
30 changes: 5 additions & 25 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct Expectation {
data: ExpectedData,
}

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

#[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,
}
let string = read_to_string(path.clone())
.unwrap()
.replace("Empty", backend_name);
ron::de::from_str(&string).expect(format!("{path:?}").as_str())
}

fn run(
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl Device {
self.require_downlevel_flags(wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER)?;
}

if desc.usage.is_empty() || desc.usage.contains_invalid_bits() {
if desc.usage.is_empty() || desc.usage.intersects(!wgt::BufferUsages::all()) {
return Err(resource::CreateBufferError::InvalidUsage(desc.usage));
}

Expand Down Expand Up @@ -731,7 +731,7 @@ impl Device {

self.check_is_valid()?;

if desc.usage.is_empty() || desc.usage.contains_invalid_bits() {
if desc.usage.is_empty() || desc.usage.intersects(!wgt::TextureUsages::all()) {
return Err(CreateTextureError::InvalidUsage(desc.usage));
}

Expand Down Expand Up @@ -1803,7 +1803,7 @@ impl Device {
})?;
}

if entry.visibility.contains_invalid_bits() {
if entry.visibility.intersects(!wgt::ShaderStages::all()) {
return Err(
binding_model::CreateBindGroupLayoutError::InvalidVisibility(entry.visibility),
);
Expand Down Expand Up @@ -2968,7 +2968,7 @@ impl Device {
if let Some(cs) = cs.as_ref() {
target_specified = true;
let error = 'error: {
if cs.write_mask.contains_invalid_bits() {
if cs.write_mask.intersects(!wgt::ColorWrites::all()) {
break 'error Some(pipeline::ColorStateError::InvalidWriteMask(
cs.write_mask,
));
Expand Down
Loading

0 comments on commit 632c478

Please sign in to comment.