`varying` cause shader error when shadow is enabled in WebGPU

Dear BJS team,

I wish you a happy holiday. :smiling_face_with_three_hearts:

I am able to reproduce my issue in a PG. It looks like a bug in BJS code. First this PG works fine with WebGL engine: https://playground.babylonjs.com/#KY0N7T#29

But failed in WebGPU engine: https://playground.babylonjs.com?webgpu#KY0N7T#29

If you remove lines 70-75, the PG should work again. The problem is these internally computed values that pass from vertex shader to fragment shader are tagged with location (<#>) with a number > 15.

It would also work if you comment out addShadowCaster at line 46 and 50. It seems enabling shadow triggers location tag added to the varying. And then the location number is increased in a way that exceeds the underlying system limit.

Update: lines 70-75 need to be deleted to make it work again. If you comment out them, the error still occurs.

1 Like

probably exceeding limits cc @Evgeni_Popov

Yes, the number of varying is not very high in WebGPU at the time. It has been raised in Chrome Canary (122.0.6182.0), so the PG works in Canary (I don’t know when this will be available in Chrome retail, though).

1 Like

Thanks @Evgeni_Popov ,

The initial PG works in canary. But my project still fails for the same error. Also, if I increase the number of varying declaration in the PG to 17, it will still fail in canary.

Does it work if I combine multiple float type varying to a vec4 varying?

It should help packing 4 varyings into a single one, yes.

There are two limits, one for the number of varying, and one for the total number of components (floats) you can pass through varyings, but I think you hit the first limit right now.

On my computer, in Chrome:
image

In Canary:
image

Thanks @Evgeni_Popov

The problem is solved after combining 4 float varyings to a single vec4. It even worked in regular chrome. So I didn’t further optimize. I actually did the same before. It didn’t work because I left the 4 float varyings as comments. I guess BJS preprocess still picked the commented varyings?

What is this limitation you mentioned? one for the total number of components (floats), is it the same as varyings but flatten to total number of floats?

Yes, we have a simple parser, so we don’t account for comments (maybe // would work - not sure, but I’m sure /* ... */ would not).

Yes, it is the total number of components (float, bool, int) you can pass through varyings. A vec4 count for 4, for eg (as well as ivec4).

1 Like