Skip to content

Commit 86e6b18

Browse files
committed
Tolerate destruction of textures used in immediate queue operations prior to submit
1 parent 26ca28e commit 86e6b18

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

cts_runner/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:bind_grou
4343
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:bind_groups_and_pipeline_layout_mismatch:encoderType="render%20pass";*
4444
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:buffer_binding,render_pipeline:*
4545
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:sampler_binding,render_pipeline:*
46+
webgpu:api,validation,image_copy,texture_related:format:dimension="1d";*
4647
webgpu:api,validation,queue,submit:command_buffer,device_mismatch:*
4748
webgpu:api,validation,queue,submit:command_buffer,duplicate_buffers:*
4849
webgpu:api,validation,queue,submit:command_buffer,submit_invalidates:*

tests/tests/wgpu-gpu/queue_transfer.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
11
//! Tests for buffer copy validation.
22
3+
use wgpu::PollType;
34
use wgpu_test::{fail, gpu_test, GpuTestConfiguration};
45

6+
#[gpu_test]
7+
static QUEUE_WRITE_TEXTURE_THEN_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new()
8+
.run_sync(|ctx| {
9+
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
10+
label: None,
11+
size: wgpu::Extent3d {
12+
width: 64,
13+
height: 32,
14+
depth_or_array_layers: 1,
15+
},
16+
mip_level_count: 1,
17+
sample_count: 1,
18+
dimension: wgpu::TextureDimension::D2,
19+
format: wgpu::TextureFormat::Rgba32Float,
20+
usage: wgpu::TextureUsages::COPY_DST,
21+
view_formats: &[],
22+
});
23+
24+
let data = vec![255; 1024];
25+
26+
ctx.queue.write_texture(
27+
wgpu::TexelCopyTextureInfo {
28+
texture: &texture,
29+
mip_level: 0,
30+
origin: wgpu::Origin3d { x: 0, y: 0, z: 0 },
31+
aspect: wgpu::TextureAspect::All,
32+
},
33+
&data,
34+
wgpu::TexelCopyBufferLayout {
35+
offset: 0,
36+
bytes_per_row: Some(1024),
37+
rows_per_image: Some(32),
38+
},
39+
wgpu::Extent3d {
40+
width: 64,
41+
height: 1,
42+
depth_or_array_layers: 1,
43+
},
44+
);
45+
46+
// Unlike textures used in a command buffer, which must not be destroyed prior to calling
47+
// submit, it is permissible to destroy a texture used in an immediate queue operation
48+
// before calling submit.
49+
texture.destroy();
50+
51+
ctx.queue.submit([]);
52+
ctx.device.poll(PollType::wait()).unwrap();
53+
});
54+
555
#[gpu_test]
656
static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration =
757
GpuTestConfiguration::new().run_sync(|ctx| {

wgpu-core/src/device/queue.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,11 @@ impl Queue {
13111311
.unwrap()
13121312
};
13131313
}
1314-
Err(e) => break 'error Err(e.into()),
1314+
// The texture must not have been destroyed when its usage here was
1315+
// encoded. If it was destroyed after that, then it was transferred
1316+
// to `pending_writes.temp_resources` at the time of destruction, so
1317+
// we are still okay to use it.
1318+
Err(DestroyedResourceError(_)) => {}
13151319
}
13161320
}
13171321

0 commit comments

Comments
 (0)