fix(core): use BufferMapState::Active for any BufferUsages::MAP_* flags
#8426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
MAP_READbuffers that aremapped_at_creation.Description
For cases where a buffer is
mapped_at_creation, our current implementation ofBuffer::createinitializes the buffer's internal state withBufferMapState::Init(which contains a staging buffer underneath the hood) for a descriptor requestingMAP_READthat is copied to a host-backed buffer .MAP_WRITEworks a little differently, starting from the beginning with a host-backed buffer.Initdoes a buffer copy between the staging buffer and the host-backed buffer in the device's queue when the buffer isunmapped. However,Buffer::map_async(correctly) assumes that a host-backed buffer need not wait for anything in the queue. This results in a bug wheremap_asyncdoesn'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, makeMAP_READjust initialize its internal state in the same way as withMAP_WRITE.Testing
Added
webgpu:api,operation,buffers,map:mapAsync,read:*, which is expected to fail in the first commit, and is resolved with the second commit.Squash or Rebase?
Rebase.