|
| 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