Skip to content

refactor(lit): align WGSL and GLSL clustered-light chunks#8740

Merged
mvaligursky merged 1 commit into
mainfrom
mv-clustered-light-align
May 18, 2026
Merged

refactor(lit): align WGSL and GLSL clustered-light chunks#8740
mvaligursky merged 1 commit into
mainfrom
mv-clustered-light-align

Conversation

@mvaligursky
Copy link
Copy Markdown
Contributor

Follow-up to #8733. Brings the GLSL clustered-light chunk in line with the WGSL refactor, applies the Samsung-precision workaround to WGSL that was previously only in GLSL, and tightens decoder helper signatures.

WGSL changes (`src/scene/shader-lib/wgsl/chunks/lit/frag/clusteredLight.js`):

  • `ClusterLightData` slimmed: removed `flags`, `anglesData`, `colorBFlagsData` from the struct; hoisted them to module-scope temporaries with the same comment that GLSL carries (Samsung precision / corruption issue, Clustered lighting not working on some devices #7800).
  • `ClusterLightData` members reordered so each `vec3f` packs with an adjacent 4-byte field into a 16-byte slot (minimises padding for compilers that don't reorder).
  • `decodeClusterLightProjectionMatrixData` now returns `mat4x4f` instead of mutating the module-level `lightProjectionMatrix` via side effect; call site assigns the result.
  • Remaining `decode*` helpers tightened to take only what they need (`lightIndex: i32` or `biasesData: f32`), or no args at all where they read from module-scope temps.
  • One-line comments added to `ClusterLightSpotData` / `ClusterLightAreaData` / `ClusterLightShadowData` explaining when each is decoded.
  • Removed four stale `// !!!!!!!!!!!` dev-comment leftovers from the original WGSL port. The code they annotated was already correct.

GLSL changes (`src/scene/shader-lib/glsl/chunks/lit/frag/clusteredLight.js`):

  • Same `ClusterLightData` slim-down (removed `halfWidth`, `halfHeight`, `omniAtlasViewport`, `cookieChannelMask`, `shadowBias`, `shadowNormalBias`, `innerConeAngleCos`, `outerConeAngleCos` — now in sub-structs decoded on demand).
  • Same `ClusterLightData` member reorder for minimal padding.
  • Same three new sub-structs (`ClusterLightSpotData`, `ClusterLightAreaData`, `ClusterLightShadowData`) with matching one-line comments.
  • All `decode*` helpers changed from `inout`-mutating to value-returning, taking `int lightIndex` / `float biasesData` / no-args as appropriate.
  • `decodeClusterLightCore` returns `ClusterLightData` by value; call site is now `ClusterLightData clusterLightData = decodeClusterLightCore(lightIndex);`.
  • `sampleLightTextureF(int lightIndex, int index)` — drops the struct parameter for symmetry with WGSL.

No public API changes. All changes are internal to the lit clustered-light shader chunks. The two backends now have near line-for-line equivalent structures, which makes cross-backend maintenance easier going forward.

Follow-up to #8733. Brings the GLSL clustered-light chunk in line with
the WGSL refactor, applies the Samsung-precision workaround to WGSL
that was previously only in GLSL, and tightens decoder helper
signatures.

WGSL changes:
- ClusterLightData slimmed: flags / anglesData / colorBFlagsData
  moved to module-scope temporaries (Samsung precision issue, #7800).
- ClusterLightData members reordered so each vec3f packs with an
  adjacent 4-byte field into a 16-byte slot.
- decodeClusterLightProjectionMatrixData returns mat4x4f instead of
  mutating a module global as a side effect.
- decode helpers tightened to take only what they need
  (lightIndex: i32 / biasesData: f32 / no args).
- One-line comments on ClusterLightSpotData / AreaData / ShadowData.
- Removed four obsolete dev comments from the original WGSL port.

GLSL changes:
- Same struct slim-down, member reorder, and three new sub-structs.
- decode helpers changed from inout-mutating to value-returning,
  taking int lightIndex / float biasesData / no args.
- decodeClusterLightCore returns ClusterLightData by value.
- sampleLightTextureF takes (int lightIndex, int index) for symmetry
  with WGSL.

No public API changes. The two backends now have near line-for-line
equivalent structures, easing cross-backend maintenance.
@mvaligursky mvaligursky self-assigned this May 18, 2026
@mvaligursky mvaligursky added the area: graphics Graphics related issue label May 18, 2026
@mvaligursky mvaligursky merged commit b4875f6 into main May 18, 2026
8 checks passed
@mvaligursky mvaligursky deleted the mv-clustered-light-align branch May 18, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant