forked from gfx-rs/wgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework buffer_usage test to properly check every failure case using e…
…rror scopes (instead of accidentally just testing the first one).
- Loading branch information
1 parent
32febc5
commit f018e95
Showing
2 changed files
with
47 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,81 @@ | ||
//! Tests for buffer usages validation. | ||
use crate::common::{fail, initialize_test, valid, TestParameters}; | ||
use wgt::BufferAddress; | ||
|
||
use crate::common::{initialize_test, TestParameters}; | ||
const BUFFER_SIZE: BufferAddress = 1234; | ||
|
||
#[test] | ||
fn buffer_usage() { | ||
fn try_create( | ||
usages: &[wgpu::BufferUsages], | ||
enable_mappable_primary_buffers: bool, | ||
should_panic: bool, | ||
) { | ||
fn try_create(enable_mappable_primary_buffers: bool, usages: &[(bool, &[wgpu::BufferUsages])]) { | ||
let mut parameters = TestParameters::default(); | ||
if enable_mappable_primary_buffers { | ||
parameters = parameters.features(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS); | ||
} | ||
if should_panic { | ||
parameters = parameters.failure(); | ||
} | ||
|
||
initialize_test(parameters, |ctx| { | ||
for usage in usages.iter().copied() { | ||
let _buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: BUFFER_SIZE, | ||
usage, | ||
mapped_at_creation: false, | ||
}); | ||
for (expect_validation_error, usage) in | ||
usages | ||
.iter() | ||
.flat_map(|&(expect_validation_error, usages)| { | ||
usages | ||
.iter() | ||
.copied() | ||
.map(move |u| (expect_validation_error, u)) | ||
}) | ||
{ | ||
let create_buffer = || { | ||
let _buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: BUFFER_SIZE, | ||
usage, | ||
mapped_at_creation: false, | ||
}); | ||
}; | ||
if expect_validation_error { | ||
fail(&ctx.device, create_buffer); | ||
} else { | ||
valid(&ctx.device, create_buffer); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
use wgpu::BufferUsages as Bu; | ||
|
||
let always_valid = [ | ||
let always_valid = &[ | ||
Bu::MAP_READ, | ||
Bu::MAP_WRITE, | ||
Bu::MAP_READ | Bu::COPY_DST, | ||
Bu::MAP_WRITE | Bu::COPY_SRC, | ||
]; | ||
// MAP_READ can only be paired with COPY_DST and MAP_WRITE can only be paired with COPY_SRC | ||
// (unless Features::MAPPABlE_PRIMARY_BUFFERS is enabled). | ||
let needs_mappable_primary_buffers = [ | ||
let needs_mappable_primary_buffers = &[ | ||
Bu::MAP_READ | Bu::COPY_DST | Bu::COPY_SRC, | ||
Bu::MAP_WRITE | Bu::COPY_SRC | Bu::COPY_DST, | ||
Bu::MAP_READ | Bu::MAP_WRITE, | ||
Bu::MAP_WRITE | Bu::MAP_READ, | ||
Bu::MAP_READ | Bu::COPY_DST | Bu::STORAGE, | ||
Bu::MAP_WRITE | Bu::COPY_SRC | Bu::STORAGE, | ||
wgpu::BufferUsages::all(), | ||
Bu::all(), | ||
]; | ||
let always_fail = [Bu::empty()]; | ||
|
||
try_create(&always_valid, false, false); | ||
try_create(&always_valid, true, false); | ||
let always_fail = &[Bu::empty()]; | ||
|
||
try_create(&needs_mappable_primary_buffers, false, true); | ||
try_create(&needs_mappable_primary_buffers, true, false); | ||
|
||
try_create(&always_fail, false, true); | ||
try_create(&always_fail, true, true); | ||
try_create( | ||
false, | ||
&[ | ||
(false, always_valid), | ||
(true, needs_mappable_primary_buffers), | ||
(true, always_fail), | ||
], | ||
); | ||
try_create( | ||
true, | ||
&[ | ||
(false, always_valid), | ||
(false, needs_mappable_primary_buffers), | ||
(true, always_fail), | ||
], | ||
); | ||
} | ||
|
||
const BUFFER_SIZE: BufferAddress = 1234; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters