-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Have `prepare_staging_buffer` take a raw hal Device. This helps the borrow checker understand that we can borrow `pending_writes`'s encoder and the raw Device at the same time. * Always free staging buffers. We must ensure that the staging buffer is not leaked when an error occurs, so allocate it as late as possible, and free it explicitly when those fallible operations we can't move it past go awry. Fixes #2959. * Some tests for texture and buffer copies. * Add CHANGELOG.md entry.
- Loading branch information
Showing
5 changed files
with
176 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Tests for buffer copy validation. | ||
use wgt::BufferAddress; | ||
|
||
use crate::common::{initialize_test, TestParameters}; | ||
|
||
#[test] | ||
fn copy_alignment() { | ||
fn try_copy(offset: BufferAddress, size: BufferAddress, should_panic: bool) { | ||
let mut parameters = TestParameters::default(); | ||
if should_panic { | ||
parameters = parameters.failure(); | ||
} | ||
|
||
initialize_test(parameters, |ctx| { | ||
let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR); | ||
let data = vec![255; size as usize]; | ||
ctx.queue.write_buffer(&buffer, offset, &data); | ||
}); | ||
} | ||
|
||
try_copy(0, 0, false); | ||
try_copy(4, 16 + 1, true); | ||
try_copy(64, 20 + 2, true); | ||
try_copy(256, 44 + 3, true); | ||
try_copy(1024, 8 + 4, false); | ||
|
||
try_copy(0, 4, false); | ||
try_copy(4 + 1, 8, true); | ||
try_copy(64 + 2, 12, true); | ||
try_copy(256 + 3, 16, true); | ||
try_copy(1024 + 4, 4, false); | ||
} | ||
|
||
const BUFFER_SIZE: BufferAddress = 1234; | ||
|
||
const BUFFER_DESCRIPTOR: wgpu::BufferDescriptor = wgpu::BufferDescriptor { | ||
label: None, | ||
size: BUFFER_SIZE, | ||
usage: wgpu::BufferUsages::COPY_SRC.union(wgpu::BufferUsages::COPY_DST), | ||
mapped_at_creation: false, | ||
}; |
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,12 +1,14 @@ | ||
// All files containing tests | ||
mod common; | ||
|
||
mod buffer_copy; | ||
mod clear_texture; | ||
mod device; | ||
mod example_wgsl; | ||
mod instance; | ||
mod poll; | ||
mod resource_descriptor_accessor; | ||
mod shader_primitive_index; | ||
mod texture_bounds; | ||
mod vertex_indices; | ||
mod zero_init_texture_after_discard; |
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,61 @@ | ||
//! Tests for texture copy bounds checks. | ||
use crate::common::{initialize_test, TestParameters}; | ||
use std::num::NonZeroU32; | ||
|
||
#[test] | ||
fn bad_copy_origin() { | ||
fn try_origin(origin: wgpu::Origin3d, should_panic: bool) { | ||
let mut parameters = TestParameters::default(); | ||
if should_panic { | ||
parameters = parameters.failure(); | ||
} | ||
|
||
initialize_test(parameters, |ctx| { | ||
let texture = ctx.device.create_texture(&TEXTURE_DESCRIPTOR); | ||
let data = vec![255; BUFFER_SIZE as usize]; | ||
ctx.queue.write_texture( | ||
wgpu::ImageCopyTexture { | ||
texture: &texture, | ||
mip_level: 0, | ||
origin, | ||
aspect: wgpu::TextureAspect::All, | ||
}, | ||
&data, | ||
BUFFER_COPY_LAYOUT, | ||
TEXTURE_SIZE, | ||
); | ||
}); | ||
} | ||
|
||
try_origin(wgpu::Origin3d { x: 0, y: 0, z: 0 }, false); | ||
try_origin(wgpu::Origin3d { x: 1, y: 0, z: 0 }, true); | ||
try_origin(wgpu::Origin3d { x: 0, y: 1, z: 0 }, true); | ||
try_origin(wgpu::Origin3d { x: 0, y: 0, z: 1 }, true); | ||
} | ||
|
||
const TEXTURE_SIZE: wgpu::Extent3d = wgpu::Extent3d { | ||
width: 64, | ||
height: 64, | ||
depth_or_array_layers: 1, | ||
}; | ||
|
||
const TEXTURE_DESCRIPTOR: wgpu::TextureDescriptor = wgpu::TextureDescriptor { | ||
label: Some("CopyOrigin"), | ||
size: TEXTURE_SIZE, | ||
mip_level_count: 1, | ||
sample_count: 1, | ||
dimension: wgpu::TextureDimension::D2, | ||
format: wgpu::TextureFormat::Rgba8UnormSrgb, | ||
usage: wgpu::TextureUsages::COPY_DST.union(wgpu::TextureUsages::COPY_SRC), | ||
}; | ||
|
||
const BYTES_PER_PIXEL: u32 = 4; | ||
|
||
const BUFFER_SIZE: u32 = TEXTURE_SIZE.width * TEXTURE_SIZE.height * BYTES_PER_PIXEL; | ||
|
||
const BUFFER_COPY_LAYOUT: wgpu::ImageDataLayout = wgpu::ImageDataLayout { | ||
offset: 0, | ||
bytes_per_row: NonZeroU32::new(TEXTURE_SIZE.width * BYTES_PER_PIXEL), | ||
rows_per_image: None, | ||
}; |