Re: WGSL parser + reflection library (javascript)

Thanks for sharing Brendan, I'm sure a lot of people will find the library
super useful! Kai made a library (which I can find anymore) that abuses
Javascript getters and setters to allow building data that looks like
objects but internally modify an ArrayBuffer that has the same layout as
WGSL. The combination of the two libs would feel like magic :)

One side note, it seems that the lib doesn't allow getting reflection for a
specific entrypoint. The list of bindings is per-entrypoint of the shader,
so I think that would be useful to developers too when they have shaders
with multiple entrypoints.

Cheers,

Corentin

On Tue, Nov 16, 2021 at 10:28 AM 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
>
> 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 14:37:19 UTC