Re: WGSL parser + reflection library (javascript)

Hi Brendan! Thanks for this!

I think this work is basically essential. I imagine you had to tackle uniform buffer layout on a personal WebGPU project, and then packaged up your existing solution to help other people. I've wound up doing something similar ( https://github.com/Rezmason/matrix/blob/master/lib/gpu-buffer.js <https://github.com/Rezmason/matrix/blob/master/lib/gpu-buffer.js> ), though I didn’t go as far as you did and extract bind group information.

The way I see it, a solution similar to gl-matrix ( https://glmatrix.net <https://glmatrix.net/> ) for composing data to send to the GPU will have a big impact on the rate of adoption of WebGPU by enthusiasts who work outside of ThreeJS, Babylon.js and so on. Having a common solution, the sooner the better, would be beneficial, because otherwise we’ll have a partially implemented library for every enthusiast! :D

I don’t know what your bandwidth and priorities are, but would you (and anyone else I suppose) be interested in collaborating on this? I’d also be interested in chatting with Brandon Jones about learning from the design and adoption of gl-matrix.

In the meantime, I’ll give your library a try in a branch before long. :)

-Jeremy Sachs


> On Nov 15, 2021, at 8:12 PM, Brendan Duncan <brendan.duncan@unity3d.com> wrote:
> 
> Hi WebGPU people,
> 
> I wanted to share a WebGPU utility project I wrote recently and put up on github, wgsl_reflect:
> https://github.com/brendan-duncan/wgsl_reflect <https://github.com/brendan-duncan/wgsl_reflect>
> 
> wgsl_reflect is a Javascript library for parsing and analyzing WGSL shaders. It has a custom WGSL parser which generates an AST for the shader. It can then analyze the AST and provide all sorts of static analysis and reflection information about the shader. For example, it can report all of the resource bind groups in the shader, tell you what uniform buffers it has, all of the members of those uniform buffers, the type, size, and offsets of those block members, etc.
> 
> I wrote it because I wanted a way to take in user authored WGSL shaders, without the user having to provide additional data for the layout of the uniform buffers in the shaders. Calculating buffer member offsets isn't the easiest thing to do, with all of the alignment rules. I wanted to be able to extract that information automatically from the shader itself.
> 
> It's still a work-in-progress, needs some polish, error handling, and documentation. I hope others find it useful.
> 
> Brendan Duncan

Received on Tuesday, 16 November 2021 22:21:51 UTC