Add validation tests ensuring destroyed textures and buffers cause submission to fail (#7181)

This commit is contained in:
Jamie Nicol 2025-02-19 15:09:17 +00:00 committed by GitHub
parent b5e32cec58
commit 7e42040fa5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 79 additions and 0 deletions

View File

@ -2,6 +2,28 @@
use core::num::NonZero;
/// Ensures that submitting a command buffer referencing an already destroyed buffer
/// results in an error.
#[test]
#[should_panic = "Buffer with '' label has been destroyed"]
fn destroyed_buffer() {
let (device, queue) = crate::request_noop_device();
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: 1024,
usage: wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.clear_buffer(&buffer, 0, None);
buffer.destroy();
queue.submit([encoder.finish()]);
}
mod buffer_slice {
use super::*;

View File

@ -1 +1,2 @@
mod buffer;
mod texture;

View File

@ -0,0 +1,56 @@
//! Tests of [`wgpu::Texture`] and related.
/// Ensures that submitting a command buffer referencing an already destroyed texture
/// results in an error.
#[test]
#[should_panic = "Texture with 'dst' label has been destroyed"]
fn destroyed_texture() {
let (device, queue) = crate::request_noop_device();
let size = wgpu::Extent3d {
width: 256,
height: 256,
depth_or_array_layers: 1,
};
let texture_src = device.create_texture(&wgpu::TextureDescriptor {
label: Some("src"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
});
let texture_dst = device.create_texture(&wgpu::TextureDescriptor {
label: Some("dst"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.copy_texture_to_texture(
wgpu::TexelCopyTextureInfo {
texture: &texture_src,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
wgpu::TexelCopyTextureInfo {
texture: &texture_dst,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
size,
);
texture_dst.destroy();
queue.submit([encoder.finish()]);
}