-
Notifications
You must be signed in to change notification settings - Fork 5
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
WebGPU use case #17
Comments
In WebGPU, there's a concept called "mapping" which allows a chunk of memory (owned by a GPUBuffer) to be exclusively transferred to the CPU (for access from JS/Wasm in the VM), and then exclusively transferred back so the GPU can use it. This ownership transfer model allows implementing with or without memory copies - it makes the difference unobservable. From the JS standpoint what this looks like now is mapping give you an ArrayBuffer (which could even point directly at GPU memory), and unmapping detaches that ArrayBuffer so that JS can't read or write it anymore. Additionally one of the things we are hoping to be able to do with GPUBuffer mapping (but cannot do yet) is mmap-style mapping of pages of GPUBuffer memory into the Wasm heap so it can be accessed directly from Wasm. (Right now we return a new ArrayBuffer which means only JS can access it.) Mappings are always one way, either:
The latter is the case that we could improve with read-only ArrayBuffers. The proposed read-only mapping could be used when you need to "download" data from the GPU to the CPU, i.e. get the result of some on-GPU computation. So in summary we want an ArrayBuffer:
(I've written all this off the top of my head but I think that should be it.) Thanks for investigating! |
Hi! Thank you for the explanation! I believe with the new design, it is possible to provide a read-only view (a But it is impossible to:
I tried to write some pseudo code to explain, hope it works. // memory state: CPU r/w GPU r/o
var m1 = getMem();
// m1 is a normal ArrayBuffer
modify(m1);
commit();
// now m1 is detached
// memory state: CPU r/o GPU r/w
var m2 = getMem();
assert(m2 instanceof Uint8Array && m2.buffer === undefined);
var m2_i8 = new Int8Array(m2); // adjust how we view it
var m2_dv = new DataView(m2); // not possible today, but proposed
some_host_api_that_receives_an_array_buffer(m2); // may throws
stop_and_get_back_memory_control();
// now m2, m2_i8, m2_dv is detached
// memory state: CPU r/w GPU r/o I'm not going to propose a read-only |
hi @kainino0x I believe this proposal fits the need of WebGPU than the immutable array buffer proposal (tc39/proposal-immutable-arraybuffer#25), but I'd like to know more backgrounds about the WebGPU use case.
I'll re-design this proposal recently, so I hope I'll satisfy the WebGPU use case.
The text was updated successfully, but these errors were encountered: