Provide getSubData() as a sibling to setSubData() - #213
Conversation
|
How would this be beneficial over Note: |
|
The author doesn’t have to call unmap, and calling this function doesn’t cause future calls to map() to fail. This call doesn’t participate in the buffer lifecycle timeline; it’s a one-shot read. |
|
I would prefer not to have any API that generates garbage like this -- why not have the user pass in an ArrayBuffer which will get filled in instead? |
|
@magcius An implementation that has separate content and GPU processes and doesn't have a way to share CPU-visible driver-managed memory between those processes would have to make an extra copy of the data if it doesn't create the |
|
FWIW WebGL has a similar I don't know a great solution for @magcius's concern, but I agree that it will be important to try to avoid temporary I'm not sure if there is any precedent for using |
|
Let me file a separate bug about the GC concerns -- looking at the sketch.idl for the first time in a bit, it's certainly not the only offender. Sorry for the off-topic spam. |
|
Note that this entry point isn't a subject for high-performance code: like |
|
Yes, @kvark is totally right. |
|
I assume getSubDate would require the buffer to have the Overall I feel there is much less a need for this compared to function getSubData(device, buffer, offset, size) {
const readbackBuffer = device.createBuffer({size, usage: TRANSFER_DST | MAP_READ});
const commands = device.createCommandEncoder();
commands.copyBufferToBuffer(buffer, offset, readbackBuffer, 0, size);
device.getQueue().submit([commands.finish()]);
return readbackBuffer.mapReadAsync();
}Am I missing something? |
|
@Kangz wouldn't the same argument apply to function setSubData(device, buffer, offset, data) {
const (writeBuffer, writeArray) = device.createBufferMapped({size: data.size, usage: TRANSFER_SRC | MAP_WRITE});
writeArray.copyFrom(data); // or something like that...
writeBuffer.unmap(); //Note: missing from your `getSubData` code, would be on the user side
const commands = device.createCommandEncoder();
commands.copyBufferToBuffer(writeBuffer, 0, buffer, offset, data.size);
device.getQueue().submit([commands.finish()]);
} |
|
It does indeed, I didn't think of the newly added |
|
If these helper functions can be polyfilled in JavaScript without too much effort, I think it's better to remove them from the WebGPU IDL. |
|
@grovesNL I agree. It would be more useful to have set_buffer_sub_data on a command buffer timeline, in order for some of the backends to implement this more efficiently than a polyfill. |
kdashg
left a comment
There was a problem hiding this comment.
I think polyfills should handle this.
|
Discussed at the 11 Mar 2019 teleconference |
|
Discussed at 25 March teleconference |
|
Discussed at the 29 April 2019 meeting. |
|
We centered on not having this in the MVP, though we can always investigate things in more detail at a later point. |
We have
setSubData()so it makes sense to havegetSubData()for symmetry. It doesn't make much sense to have one without the other.