Re: WGSL parser + reflection library (javascript)

Uniform Buffers are very similar in WebGL and WebGPU. The point was WebGPU
doesn't provide the reflection but if your library is providing the
reflection then the same techniques will work as in TWGL.

On Tue, Nov 16, 2021 at 4:52 PM Brendan Duncan <brendan.duncan@unity3d.com>
wrote:

> That’s a nice looking library. WebGL uniform structures aren’t the same
> since they map to individual uniforms and you get the reflection info for
> glsl shaders from WebGL (what active uniforms it has, their location
> handles), and WebGPU doesn’t have an equivalent of that. From the couple
> minutes I looked at it, it wasn’t clear if twgljs tells you what’s in a
> uniform buffer object, which would be closest to wgsl uniform buffers.
> Still, a nice looking library for WebGL.
>
> Sent from my iPhone
>
> On Nov 16, 2021, at 3:42 PM, Gregg Tavares <gman@google.com> wrote:
>
> 
> I don't know if this is similar or not but twgl has structure setters
>
> https://twgljs.org/#setting-uniform-and-uniformblock-structures-and-arrays
>
> It does the same for uniform blocks given reflection data for a uniform
> block
>
>
> On Tue, Nov 16, 2021 at 2:22 PM Jeremy Sachs <jeremysachs@rezmason.net>
> wrote:
>
>> 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 ),
>> 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 )
>> 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
>>
>> 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 Wednesday, 17 November 2021 02:16:11 UTC