Skip to content

Commit 36ae215

Browse files
Fix image copy regressions (#8022)
* Restore allowance of unaligned buffer-texture copies This fixes a regression introduced by #7948. However, it makes it possible to reach a panic in initialize_buffer_memory if the copy requires initializing a region of memory that is not 4B aligned. * Fix CopyT2T of multi-layer depth/stencil textures * Adjust test list
1 parent 5089063 commit 36ae215

File tree

2 files changed

+40
-50
lines changed

2 files changed

+40
-50
lines changed

cts_runner/test.lst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
unittests:*
22
webgpu:api,operation,command_buffer,basic:*
33
webgpu:api,operation,command_buffer,copyBufferToBuffer:*
4+
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth24plus"
5+
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth24plus-stencil8"
6+
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth16unorm"
7+
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth32float"
8+
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth32float-stencil8"
9+
webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="stencil8"
10+
// Fails with OOM in CI.
11+
fails-if(dx12) webgpu:api,operation,command_buffer,image_copy:offsets_and_sizes:*
412
webgpu:api,operation,compute,basic:memcpy:*
513
//FAIL: webgpu:api,operation,compute,basic:large_dispatch:*
614
webgpu:api,operation,compute_pipeline,overrides:*
@@ -63,6 +71,8 @@ fails-if(dx12) webgpu:api,validation,image_copy,buffer_texture_copies:offset_and
6371
//mix of PASS and FAIL: other subtests of offset_and_bytesPerRow. Related bugs:
6472
// https://github.com/gfx-rs/wgpu/issues/7946, https://github.com/gfx-rs/wgpu/issues/7947
6573
webgpu:api,validation,image_copy,layout_related:copy_end_overflows_u64:*
74+
// Fails with OOM in CI.
75+
fails-if(dx12) webgpu:api,validation,image_copy,layout_related:offset_alignment:*
6676
webgpu:api,validation,image_copy,texture_related:format:dimension="1d";*
6777
webgpu:api,validation,queue,submit:command_buffer,device_mismatch:*
6878
webgpu:api,validation,queue,submit:command_buffer,duplicate_buffers:*
@@ -92,6 +102,9 @@ webgpu:api,validation,encoding,queries,general:occlusion_query,query_type:*
92102
webgpu:shader,execution,expression,call,builtin,textureSample:sampled_1d_coords:*
93103
webgpu:shader,execution,expression,call,builtin,textureSampleBaseClampToEdge:2d_coords:stage="c";textureType="texture_2d<f32>";*
94104
webgpu:shader,execution,flow_control,return:*
105+
// Many other vertex_buffer_access subtests also passing, but there are too many to enumerate.
106+
// Fails on Metal in CI only, not when running locally.
107+
fails-if(metal) webgpu:shader,execution,robust_access_vertex:vertex_buffer_access:indexed=true;indirect=false;drawCallTestParameter="baseVertex";type="float32x4";additionalBuffers=4;partialLastNumber=false;offsetVertexBuffer=true
95108
webgpu:shader,validation,expression,call,builtin,max:values:*
96109
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break"
97110
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break_if"

wgpu-core/src/command/transfer.rs

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloc::{format, string::String, sync::Arc, vec, vec::Vec};
1+
use alloc::{format, string::String, sync::Arc, vec::Vec};
22

33
use arrayvec::ArrayVec;
44
use thiserror::Error;
@@ -399,7 +399,7 @@ pub(crate) fn validate_texture_buffer_copy<T>(
399399
return Err(TransferError::CopyAspectNotOne);
400400
}
401401

402-
let mut offset_alignment = if desc.format.is_depth_stencil_format() {
402+
let offset_alignment = if desc.format.is_depth_stencil_format() {
403403
4
404404
} else {
405405
// The case where `block_copy_size` returns `None` is currently
@@ -411,17 +411,7 @@ pub(crate) fn validate_texture_buffer_copy<T>(
411411
.expect("non-copyable formats should have been rejected previously")
412412
};
413413

414-
// TODO(https://github.com/gfx-rs/wgpu/issues/7947): This does not match the spec.
415-
// The spec imposes no alignment requirement if `!aligned`, and otherwise
416-
// imposes only the `offset_alignment` as calculated above. wgpu currently
417-
// can panic on alignments <4B, so we reject them here to avoid a panic.
418-
if aligned {
419-
offset_alignment = offset_alignment.max(4);
420-
} else {
421-
offset_alignment = 4;
422-
}
423-
424-
if offset % u64::from(offset_alignment) != 0 {
414+
if aligned && offset % u64::from(offset_alignment) != 0 {
425415
return Err(TransferError::UnalignedBufferOffset(offset));
426416
}
427417

@@ -1347,45 +1337,32 @@ impl Global {
13471337
height: src_copy_size.height.min(dst_copy_size.height),
13481338
depth: src_copy_size.depth.min(dst_copy_size.depth),
13491339
};
1340+
1341+
let regions = (0..array_layer_count).map(|rel_array_layer| {
1342+
let mut src_base = src_tex_base.clone();
1343+
let mut dst_base = dst_tex_base.clone();
1344+
src_base.array_layer += rel_array_layer;
1345+
dst_base.array_layer += rel_array_layer;
1346+
hal::TextureCopy {
1347+
src_base,
1348+
dst_base,
1349+
size: hal_copy_size,
1350+
}
1351+
});
1352+
13501353
let regions = if dst_tex_base.aspect == hal::FormatAspects::DEPTH_STENCIL {
1351-
vec![
1352-
hal::TextureCopy {
1353-
src_base: hal::TextureCopyBase {
1354-
aspect: hal::FormatAspects::DEPTH,
1355-
..src_tex_base
1356-
},
1357-
dst_base: hal::TextureCopyBase {
1358-
aspect: hal::FormatAspects::DEPTH,
1359-
..dst_tex_base
1360-
},
1361-
size: hal_copy_size,
1362-
},
1363-
hal::TextureCopy {
1364-
src_base: hal::TextureCopyBase {
1365-
aspect: hal::FormatAspects::STENCIL,
1366-
..src_tex_base
1367-
},
1368-
dst_base: hal::TextureCopyBase {
1369-
aspect: hal::FormatAspects::STENCIL,
1370-
..dst_tex_base
1371-
},
1372-
size: hal_copy_size,
1373-
},
1374-
]
1375-
} else {
1376-
(0..array_layer_count)
1377-
.map(|rel_array_layer| {
1378-
let mut src_base = src_tex_base.clone();
1379-
let mut dst_base = dst_tex_base.clone();
1380-
src_base.array_layer += rel_array_layer;
1381-
dst_base.array_layer += rel_array_layer;
1382-
hal::TextureCopy {
1383-
src_base,
1384-
dst_base,
1385-
size: hal_copy_size,
1386-
}
1354+
regions
1355+
.flat_map(|region| {
1356+
let (mut depth, mut stencil) = (region.clone(), region);
1357+
depth.src_base.aspect = hal::FormatAspects::DEPTH;
1358+
depth.dst_base.aspect = hal::FormatAspects::DEPTH;
1359+
stencil.src_base.aspect = hal::FormatAspects::STENCIL;
1360+
stencil.dst_base.aspect = hal::FormatAspects::STENCIL;
1361+
[depth, stencil]
13871362
})
1388-
.collect()
1363+
.collect::<Vec<_>>()
1364+
} else {
1365+
regions.collect::<Vec<_>>()
13891366
};
13901367
let cmd_buf_raw = cmd_buf_data.encoder.open()?;
13911368
unsafe {

0 commit comments

Comments
 (0)