BabylonJS / BabylonJS/BabylonNative

ShaderCompiler: uniform widening crashes when the uniform's parent AST node is a loop or switch

Open
#1,818 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
919
Forks
162
Avg merge
1d 15h
Merged PRs (30d)
19

Description

## Summary

`UniformTypeChangeTraverser` widens loose scalar/`vec2`/`vec3` uniforms to `vec4`, then inserts a shape conversion at each use. `injectShapeConversion` locates the node by switching on its parent's type — it handles `TIntermAggregate`, `TIntermBinary`, `TIntermUnary`, `TIntermSelection` and (since #1816) `TIntermBranch`, then throws.

A uniform that is the **direct child** of a loop or switch still fails shader compilation, surfacing to JS as `Error: [object Object]` with no shader location or uniform name.

## Measured

Win32 D3D11 `RelWithDebInfo`, via `engine.createEffect`:

| shader | parent node | result |
| --- | --- | --- |
| `while (flag) { ... }` | `TIntermLoop` | **fails** |
| `switch (mode) { ... }` | `TIntermSwitch` | **fails** |
| `vec3 f() { return tint; }` | `TIntermBranch` | fixed by #1816 |
| `while (flag == true)` | `TIntermBinary` | ok |
| ESSL 300, uniform under a binary op | `TIntermBinary` | ok |

The last row is the control for `switch` — that case fails on the node type, not the GLSL version. `tints.length()` was also checked and does not trigger.

## Notes for the fix

`TIntermBranch` exposed `setExpression`, which is what made #1816's fix possible. `TIntermLoop` and `TIntermSwitch` expose no setter for their child (`getTest()` / `getCondition()` are read-only), so covering them needs `setTest()` / `setCondition()` in the `BabylonJS/glslang` fork plus a `GIT_TAG` bump.

The remaining `throw` should name the uniform and the unsupported construct.

---

[Filed by Copilot on behalf of @bghgary]

Contributor guide

Open the contributing guide

Research direction

Start at UniformTypeChangeTraverser and injectShapeConversion, then inspect the BabylonJS/glslang fork APIs for TIntermLoop and TIntermSwitch. Verify the while and switch shader cases through engine.createEffect, update the fork reference via GIT_TAG, and confirm unsupported-node errors include the uniform name and construct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.