tc39 / proposal-structs

JavaScript Structs: Fixed Layout Objects
http://tc39.es/proposal-structs/
622 stars 11 forks source link

Potential use case in webGPU #18

Open bakkot opened 1 year ago

bakkot commented 1 year ago

The WebGPU proposal has mentioned that they want something like this:

This should allow for example for GPUTextures created on one worker to be instantly visible to other workers.

The v1 of that proposal does not have multithreading, but it may become relevant to a future version.

7ombie commented 1 week ago

There's an interesting language called Shadeup that compiles to a mix of JavaScript and WGSL. It lets you write shaders inline, and "close over" the shader code from the CPU code to access data and types without having to explicitly set up buffers and descriptors etc. They have structs that can be defined on the CPU or GPU (which automatically map to array buffers via typed arrays on the JS-side). Having Shadeup-style structs in JavaScript would make working with WGSL much nicer.

Ideally, we should be able to pretty much copy and paste a WGSL struct into JS, instantiate it in JS (or Wasm), and pass it over to WGSL with all the bytes in the expected locations.

WebAssembly is important, but WGSL already has structs, so JS and WebAssembly should take their lead from WebGPU.