Re: WGSL parser + reflection library (javascript)

My library was just sitting on a dead branch of gpuweb/cts somewhere. I
finally just extracted it into a repo:
https://github.com/kainino0x/structured-accessor
The code needs a lot of work, but the ideas are there.

-Kai (he/they)


On Tue, Nov 16, 2021 at 8:48 AM Brendan Duncan <brendan.duncan@unity3d.com>
wrote:

> Thanks, Corentin!
>
> Good point about entry points, I just added that. `reflect.entry` will now
> have the map of entry points, where `reflect.entry.fragment.name` would
> be the name of the fragment entry point. When I get to more robust error
> checking, I'll have it let you know if there are any non-standard entry
> points, or an entry point defined more than once.
>
> Brendan
>
> On Tue, Nov 16, 2021 at 6:37 AM Corentin Wallez <cwallez@google.com>
> wrote:
>
>> 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 18:23:24 UTC