-
Couldn't load subscription status.
- Fork 1.1k
fix(core): use BufferMapState::Active for any BufferUsages::MAP_* flags
#8426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
fix(core): use BufferMapState::Active for any BufferUsages::MAP_* flags
#8426
Conversation
BufferMapState::Active for any BufferUsages::MAP_* flagsBufferMapState::Active for any BufferUsages::MAP_* flags
|
Hmmm…I'm not immediately sure how to fix the CI errors, which all seem to be on GL backends (incl. WebGL). I'm not familiar with GL backends, so I'm sure I'm doing something wrong with bookkeeping there, but not what that might be. |
60bd075 to
10d652f
Compare
|
Going to mark this as ready for review. I'm not sure how to resolve CI yet, but at least the approach can be validated, and maybe a reviewer will know more than I do about how to resolve this. 😖 |
| let buffer = Buffer { | ||
| raw: Snatchable::new(buffer), | ||
| device: self.clone(), | ||
| usage: desc.usage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To address the GL error: I don't think we are passing the right usage to HAL, when we create the buffer its usage should include MAP_WRITE if mapped_at_creation == true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this'll do it: ac38c82
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we need to set the MAP_WRITE flag only when MAP_READ and mapped_at_creation are present. So that we don't set it on GPU-backed buffers.
10d652f to
146f37e
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
Hmm, some WebGL tests failed with ac38c82 with recursive snatch log errors, but I'm not sure that they're related to this PR. Dump of the error log:I guess we'll see if they reproduce with 34a3316, which should be the same repository state. EDIT: It does. Ugh. 😩 |
… flags 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`.
34a3316 to
684859e
Compare
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.