Skip to content

Commit 60bd075

Browse files
WIP: fix(core): use BufferMapState::Active for any BufferUsages::MAP_* flags
TODO: figure out GL failures For cases where a buffer is `mapped_at_creation`, our current implementation of `Buffer::create` initializes the buffer's internal state with `BufferMapState::Init` (which contains a staging buffer underneath the hood) for a descriptor requesting `MAP_READ` that is copied to a host-backed buffer . `MAP_WRITE` works a little differently, starting from the beginning with a host-backed buffer. `Init` does a buffer copy between the staging buffer and the host-backed buffer in the device's queue when the buffer is `unmap`ped. However, `Buffer::map_async` (correctly) assumes that a host-backed buffer need not wait for anything in the queue. This results in a bug where `map_async` doesn't actually wait long enough for the device queue to complete its operations before resolving. Oops! Up to the point where a buffer is unmapped after being mapped at creation, `MAP_READ`, `MAP_WRITE`, and even _non_-`MAP_*` buffers' capabilities are the same. That is, we should be able to get mutable slices for mapped ranges, no matter what. So, make `MAP_READ` just initialize its internal state in the same way as with `MAP_WRITE`.
1 parent 73a1a40 commit 60bd075

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

cts_runner/test.lst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// ```
55
unittests:*
66
webgpu:api,operation,buffers,createBindGroup:buffer_binding_resource:*
7-
fails-if(vulkan,dx12,metal): webgpu:api,operation,buffers,map:mapAsync,read:*
7+
webgpu:api,operation,buffers,map:mapAsync,read:*
88
webgpu:api,operation,command_buffer,basic:*
99
webgpu:api,operation,command_buffer,copyBufferToBuffer:*
1010
fails-if(vulkan) webgpu:api,operation,command_buffer,copyTextureToTexture:copy_depth_stencil:format="depth24plus"

wgpu-core/src/device/resource.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,10 @@ impl Device {
990990

991991
let buffer_use = if !desc.mapped_at_creation {
992992
wgt::BufferUses::empty()
993-
} else if desc.usage.contains(wgt::BufferUsages::MAP_WRITE) {
993+
} else if desc
994+
.usage
995+
.intersects(wgt::BufferUsages::MAP_WRITE | wgt::BufferUsages::MAP_READ)
996+
{
994997
// buffer is mappable, so we are just doing that at start
995998
let map_size = buffer.size;
996999
let mapping = if map_size == 0 {

0 commit comments

Comments
 (0)