Skip to content

Commit 7e42040

Browse files
authored
Add validation tests ensuring destroyed textures and buffers cause submission to fail (gfx-rs#7181)
1 parent b5e32ce commit 7e42040

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

tests/validation_tests/api/buffer.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22
33
use core::num::NonZero;
44

5+
/// Ensures that submitting a command buffer referencing an already destroyed buffer
6+
/// results in an error.
7+
#[test]
8+
#[should_panic = "Buffer with '' label has been destroyed"]
9+
fn destroyed_buffer() {
10+
let (device, queue) = crate::request_noop_device();
11+
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
12+
label: None,
13+
size: 1024,
14+
usage: wgpu::BufferUsages::COPY_DST,
15+
mapped_at_creation: false,
16+
});
17+
18+
let mut encoder =
19+
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
20+
encoder.clear_buffer(&buffer, 0, None);
21+
22+
buffer.destroy();
23+
24+
queue.submit([encoder.finish()]);
25+
}
26+
527
mod buffer_slice {
628
use super::*;
729

tests/validation_tests/api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mod buffer;
2+
mod texture;

tests/validation_tests/api/texture.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Tests of [`wgpu::Texture`] and related.
2+
3+
/// Ensures that submitting a command buffer referencing an already destroyed texture
4+
/// results in an error.
5+
#[test]
6+
#[should_panic = "Texture with 'dst' label has been destroyed"]
7+
fn destroyed_texture() {
8+
let (device, queue) = crate::request_noop_device();
9+
let size = wgpu::Extent3d {
10+
width: 256,
11+
height: 256,
12+
depth_or_array_layers: 1,
13+
};
14+
let texture_src = device.create_texture(&wgpu::TextureDescriptor {
15+
label: Some("src"),
16+
size,
17+
mip_level_count: 1,
18+
sample_count: 1,
19+
dimension: wgpu::TextureDimension::D2,
20+
format: wgpu::TextureFormat::Rgba8Unorm,
21+
usage: wgpu::TextureUsages::COPY_SRC,
22+
view_formats: &[],
23+
});
24+
let texture_dst = device.create_texture(&wgpu::TextureDescriptor {
25+
label: Some("dst"),
26+
size,
27+
mip_level_count: 1,
28+
sample_count: 1,
29+
dimension: wgpu::TextureDimension::D2,
30+
format: wgpu::TextureFormat::Rgba8Unorm,
31+
usage: wgpu::TextureUsages::COPY_DST,
32+
view_formats: &[],
33+
});
34+
35+
let mut encoder =
36+
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
37+
encoder.copy_texture_to_texture(
38+
wgpu::TexelCopyTextureInfo {
39+
texture: &texture_src,
40+
mip_level: 0,
41+
origin: wgpu::Origin3d::ZERO,
42+
aspect: wgpu::TextureAspect::All,
43+
},
44+
wgpu::TexelCopyTextureInfo {
45+
texture: &texture_dst,
46+
mip_level: 0,
47+
origin: wgpu::Origin3d::ZERO,
48+
aspect: wgpu::TextureAspect::All,
49+
},
50+
size,
51+
);
52+
53+
texture_dst.destroy();
54+
55+
queue.submit([encoder.finish()]);
56+
}

0 commit comments

Comments
 (0)