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
Add explainer document for BufferOperations #147
Conversation
design/BufferOperations.md
Outdated
Assuming there is a single queue, there are two types of commands in WebGPU: | ||
|
||
- "Buffered commands": commands stored inside `WebGPUCommandBuffer` like `setVertexBuffers` or `draw`. | ||
- "Unbuffered commands": Other commands like creating objects, `WebGPUBuffer.setSubData` and `WebGPUQueue.submit`. |
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.
It's great to finally have terminology for this distinction - it's been getting confusing.
Multiqueue is going to change a lot though.
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.
Yep but I expect to have a similar concept of ordering (just as a general DAG instead of a line) for multi-queue.
design/BufferOperations.md
Outdated
- **Available**: the content of the buffer is visible. | ||
In that state `pointer` is an `ArrayBuffer` representing the content of the buffer, `isPending` is `false` and `promise` is resolved. | ||
- **Invalidated**: the content of the buffer is no longer visible. | ||
In that state `pointer` is `null`, `isPending` is `false` and `promise` is rejected. |
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.
Consider calling this state "invalid" instead of "invalidated". I've always associated the term 'invalidated' with a display region that needs to be repainted or that something was invalid in the past. 'Invalid', on the other hand, implies something about the current state of the object. Since invalid WebGPUMappedMemory
objects can never go from the invalid state to any other state, this also lends a degree of finalness to the name.
PTAL again at the "Buffer mapping" section that changed heavily to use The "examples" section is new too. |
On the topic of promises, I'm pretty sure that having only a regular promise (even without polling api) should be technically okay for the main thread as long as it doesn't impact latency. We already have a restriction that the mapping "can only change state on task boundary", so I don't think it would impact latency, and the following code is equivalent to what we would do internally to the browser anyway: function pollableMapWriteAsync(buffer, offset, size) { // [edited]
const mapping = { pointer: null };
buffer.mapWriteAsync(offset, size).then(ab => { mapping.pointer = ab; });
// edit: probably add .catch(e => { mapping.error = e; }); or something
return mapping;
} (pending = I think it only becomes a problem on Workers if we lift the "can only change state on task boundary" restriction (i.e. allow spin polling). Although with the nested event loop thing I was prototyping, it's not technically necessary because promises can resolve "synchronously" (latency could be higher though, I'm not sure). |
@kainino0x I think you meant |
This was discussed at the 14 Jan 2019 Teleconference |
0b54ea1
to
820c369
Compare
PTAL again @RafaelCintron @litherum @kvark, squashed and rebased after the WebGPU -> GPU change. |
```webidl | ||
partial interface GPUDevice { | ||
(GPUBuffer, ArrayBuffer) createBufferMapped(GPUBufferDescriptor descriptor); | ||
Promise<(GPUBuffer, ArrayBuffer)> createBufferMappedAsync(GPUBufferDescriptor descriptor); |
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.
why are we promising the buffer here? We could allow the user to start recording some operations on the buffer at this point
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.
It is a bit less elegant but could be useful. Do you have a usecase in mind?
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 suppose there aren't that many use-cases that wouldn't be happy with either sync or async version of this call, so I'm fine with it.
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.
We agreed on the general approach at the F2F and only minor comments on this PR. If there are no big concerns, I think we should merge this and iterate with issues / PR. |
No big concerns from me, other than the ones I explained at F2F 🤐 |
There hasn't been any comment on this for a week, I'll land it and we can iterate more in follow-up pull requests. |
This follows discussions on #138
PTAL all! @kainino0x @kvark @jdashg @litherum @RafaelCintron