WGSL parser + reflection library (javascript)

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

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 09:27:23 UTC