mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 10:03:58 +01:00
121 lines
4.2 KiB
Rust
121 lines
4.2 KiB
Rust
use wgpu_test::{
|
|
apply, fail, gpu_test, valid, GpuTestConfiguration, GpuTestInitializer, TestParameters,
|
|
};
|
|
|
|
pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
|
|
vec.extend([BAD_BUFFER_MAP, BAD_TEXTURE_CREATE_VIEW, BAD_TEXTURE_WRITE]);
|
|
}
|
|
|
|
#[apply(gpu_test!)]
|
|
static BAD_BUFFER_MAP: GpuTestConfiguration = GpuTestConfiguration::new()
|
|
.parameters(TestParameters::default().enable_noop())
|
|
.run_sync(|ctx| {
|
|
// Create a buffer with bad parameters and call a few methods.
|
|
// Validation should fail but there should be not panic.
|
|
let buffer = fail(
|
|
&ctx.device,
|
|
|| {
|
|
ctx.device.create_buffer(&wgpu::BufferDescriptor {
|
|
label: None,
|
|
size: 99999999,
|
|
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::STORAGE,
|
|
mapped_at_creation: false,
|
|
})
|
|
},
|
|
Some("`map` usage can only be combined with the opposite `copy`"),
|
|
);
|
|
|
|
fail(
|
|
&ctx.device,
|
|
|| buffer.slice(..).map_async(wgpu::MapMode::Write, |_| {}),
|
|
Some("Buffer with '' label is invalid"),
|
|
);
|
|
valid(&ctx.device, || buffer.unmap());
|
|
valid(&ctx.device, || buffer.destroy());
|
|
valid(&ctx.device, || buffer.destroy());
|
|
});
|
|
|
|
#[apply(gpu_test!)]
|
|
static BAD_TEXTURE_CREATE_VIEW: GpuTestConfiguration = GpuTestConfiguration::new()
|
|
.parameters(TestParameters::default().enable_noop())
|
|
.run_sync(|ctx| {
|
|
let texture = fail(
|
|
&ctx.device,
|
|
|| {
|
|
ctx.device.create_texture(&wgpu::TextureDescriptor {
|
|
label: None,
|
|
size: wgpu::Extent3d {
|
|
width: 0,
|
|
height: 12345678,
|
|
depth_or_array_layers: 9001,
|
|
},
|
|
mip_level_count: 2000,
|
|
sample_count: 27,
|
|
dimension: wgpu::TextureDimension::D2,
|
|
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
|
usage: wgpu::TextureUsages::all(),
|
|
view_formats: &[],
|
|
})
|
|
},
|
|
Some("dimension x is zero"),
|
|
);
|
|
|
|
fail(
|
|
&ctx.device,
|
|
|| {
|
|
let _ = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
|
},
|
|
Some("Texture with '' label is invalid"),
|
|
);
|
|
valid(&ctx.device, || texture.destroy());
|
|
valid(&ctx.device, || texture.destroy());
|
|
});
|
|
|
|
#[apply(gpu_test!)]
|
|
static BAD_TEXTURE_WRITE: GpuTestConfiguration = GpuTestConfiguration::new()
|
|
.parameters(TestParameters::default().enable_noop())
|
|
.run_sync(|ctx| {
|
|
let texture = fail(
|
|
&ctx.device,
|
|
|| {
|
|
ctx.device.create_texture(&wgpu::TextureDescriptor {
|
|
label: None,
|
|
size: wgpu::Extent3d {
|
|
width: 256,
|
|
height: 256,
|
|
depth_or_array_layers: 1,
|
|
},
|
|
mip_level_count: 5888,
|
|
sample_count: 1,
|
|
dimension: wgpu::TextureDimension::D2,
|
|
format: wgpu::TextureFormat::Rgba8Unorm,
|
|
usage: wgpu::TextureUsages::COPY_DST,
|
|
view_formats: &[],
|
|
})
|
|
},
|
|
Some("mip level count"),
|
|
);
|
|
|
|
fail(
|
|
&ctx.device,
|
|
|| {
|
|
ctx.queue.write_texture(
|
|
wgpu::TexelCopyTextureInfo {
|
|
texture: &texture,
|
|
mip_level: 255,
|
|
origin: wgpu::Origin3d::ZERO,
|
|
aspect: wgpu::TextureAspect::All,
|
|
},
|
|
&[0u8; 4],
|
|
wgpu::TexelCopyBufferLayout::default(),
|
|
wgpu::Extent3d {
|
|
width: 1,
|
|
height: 1,
|
|
depth_or_array_layers: 1,
|
|
},
|
|
);
|
|
},
|
|
Some("Texture with '' label is invalid"),
|
|
);
|
|
});
|