How to debug WGSL code with the changes BabylonJS introduces

When trying to compile something like,


// Attributes
attribute position : vec3<f32>;
attribute uv: vec2<f32>;

// Varying
varying vUV : vec2<f32>;

fn main(input : VertexInputs) -> FragmentInputs {
    gl_Position = scene.viewProjection * * position;

    vUV = uv;

I get a compile parser error,

1 error(s) generated while compiling the shader:
:21:9 error: expected ':' for struct member
  output.position = gl_Position;

Where is this output.position = gl_Position coming from, and is there anyway to dump what BabylonJS is actually trying to give to the WebGPU driver?

Seems like the validator is expecting a type declaration for gl_Position? Maybe required if its hoisting into a struct before codegen. If thats the case, could be for runtime or just validation (in which case disabling validation would work). You can disable validation by setting debug to false on some class, im on my phone atm and too hard to find in source or docs. There is also a compile hook you could try, its something like “processShaderCode”, definitely starts with the word process. Maybe wont make it that far though, in which case u’ll definitely have to disable validation

Unrelated to debugging, i think wgsl recently had some change for type inference like typescript where untyped lhs is ok when rhs is typed. Idk if that applies here or not.

cc @Evgeni_Popov who can share how he is going for it

This sample (from the doc) is working for me:

You can use engine.dbgShowShaderCode = true; to log the shader code in the browser console.

Note that in your code position is vec3 and gl_Position should be a vec4. So you probably need to use vec4<f32>(position, 1.0) instead of position.


@satya give this man a raise

1 Like

Many thanks @Evgeni_Popov , that will help me tracking down issues.

Yes the shader has bugs, however the engine blind rewrite is what was hindering me, being able to log the actual code is of great help.

The idea is to make a CYOS clone that can handle all versions (WebGL 1.0/2.0 and BabylonJS flavoured WGSL), so being able to see what the engine does with the code is quite relevant.

Thanks again for the support.