-
Notifications
You must be signed in to change notification settings - Fork 956
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Buffer usages mismatch check and documentation for mapped_at_creation…
… size requirement. (#3023) Co-authored-by: Connor Fitzgerald <[email protected]>
- Loading branch information
1 parent
44399bb
commit 41006d7
Showing
8 changed files
with
89 additions
and
4 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
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,5 +1,5 @@ | ||
( | ||
features: 0x0000_0004_0000_0000, | ||
features: 0x0000_0004_0001_0000, | ||
expectations: [ | ||
( | ||
name: "Quad", | ||
|
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,5 +1,5 @@ | ||
( | ||
features: 0x0, | ||
features: 0x1_0000, | ||
expectations: [ | ||
// Ensuring that mapping zero-inits buffers. | ||
( | ||
|
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
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,65 @@ | ||
//! Tests for buffer usages validation. | ||
use wgt::BufferAddress; | ||
|
||
use crate::common::{initialize_test, TestParameters}; | ||
|
||
#[test] | ||
fn buffer_usage() { | ||
fn try_create( | ||
usages: &[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| { | ||
for usage in usages.iter().copied() { | ||
let _buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: BUFFER_SIZE, | ||
usage, | ||
mapped_at_creation: false, | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
use wgpu::BufferUsages as Bu; | ||
|
||
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 = [ | ||
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(), | ||
]; | ||
let always_fail = [Bu::empty()]; | ||
|
||
try_create(&always_valid, false, false); | ||
try_create(&always_valid, true, false); | ||
|
||
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); | ||
} | ||
|
||
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; | ||
|