-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing BufferUsages mismatch check along with a test to ensure i…
…t works.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//! Tests for buffer usages validation. | ||
|
||
use wgt::BufferAddress; | ||
|
||
use crate::common::{initialize_test, TestParameters}; | ||
|
||
#[test] | ||
fn buffer_usage() { | ||
fn try_create( | ||
usage: wgpu::BufferUsages, | ||
enable_mappable_primary_buffers: bool, | ||
should_panic: bool, | ||
) { | ||
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| { | ||
let _buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: BUFFER_SIZE, | ||
usage, | ||
mapped_at_creation: false, | ||
}); | ||
//let data = vec![255; size as usize]; | ||
//ctx.queue.write_buffer(&buffer, offset, &data); | ||
}); | ||
} | ||
|
||
macro_rules! usage_consts { | ||
($($name:ident),*) => { | ||
$(const $name: wgpu::BufferUsages = wgpu::BufferUsages::$name;)* | ||
}; | ||
} | ||
usage_consts!(MAP_READ, MAP_WRITE, COPY_SRC, COPY_DST, STORAGE); | ||
|
||
// Buffers cannot have empty usage flags | ||
try_create(wgpu::BufferUsages::empty(), false, true); | ||
try_create(MAP_READ, false, false); | ||
try_create(MAP_WRITE, false, false); | ||
try_create(MAP_READ | COPY_DST, false, false); | ||
try_create(MAP_WRITE | COPY_SRC, false, false); | ||
// MAP_READ can only be paired with COPY_DST and MAP_WRITE can only be paired with COPY_SRC | ||
// without enabling Features::MAPPABlE_PRIMARY_BUFFER. | ||
try_create(MAP_READ | COPY_DST | COPY_SRC, false, true); | ||
try_create(MAP_WRITE | COPY_SRC | COPY_DST, false, true); | ||
try_create(MAP_READ | MAP_WRITE, false, true); | ||
try_create(MAP_WRITE | MAP_READ, false, true); | ||
try_create(MAP_READ | COPY_DST | STORAGE, false, true); | ||
try_create(MAP_WRITE | COPY_SRC | STORAGE, false, true); | ||
try_create(wgpu::BufferUsages::all(), false, true); | ||
|
||
// Enable MAPPABLE_PRIMARY_BUFFERS | ||
try_create(wgpu::BufferUsages::empty(), true, true); | ||
try_create(MAP_READ, true, false); | ||
try_create(MAP_WRITE, true, false); | ||
try_create(MAP_READ | COPY_DST, true, false); | ||
try_create(MAP_WRITE | COPY_SRC, true, false); | ||
try_create(MAP_READ | COPY_DST | COPY_SRC, true, false); | ||
try_create(MAP_WRITE | COPY_SRC | COPY_DST, true, false); | ||
try_create(MAP_READ | MAP_WRITE, true, false); | ||
try_create(MAP_WRITE | MAP_READ, true, false); | ||
try_create(MAP_READ | COPY_DST | STORAGE, true, false); | ||
try_create(MAP_WRITE | COPY_SRC | STORAGE, true, false); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
mod common; | ||
|
||
mod buffer_copy; | ||
mod buffer_usages; | ||
mod clear_texture; | ||
mod device; | ||
mod example_wgsl; | ||
|