Module swizzle_assign

Module swizzle_assign 

Source
Expand description

Pass: lower multi-component swizzle assignments to per-component writes.

HLSL accepts vec.xy = expr / vec.xy += expr / color.rgb = … verbatim. WGSL refuses with invalid left-hand side of assignment and the hint “WGSL does not support assignments to swizzles; consider assigning each component individually”. This is the dominant warp-side failure on the in-the-wild corpus (≈ 100 cases on the 2 000-sample).

Rewrite shape: lhs.SWIZ op= rhsfloatN _swztmp_K = (rhs); lhs.c0 op= _swztmp_K.x; lhs.c1 op= _swztmp_K.y; … where K is a per-pass counter so nested or chained rewrites don’t collide. We emit HLSL-shaped output (floatN) so the regex pipeline can lower it to vec<f32> like any other declaration. Single-component swizzle assigns (uv.x = …) are left alone — WGSL accepts them.

We deliberately skip:

  • swizzles with repeated components (uv.xx = …) — undefined in HLSL too, surface the WGSL error instead of synthesising a fake last-write.
  • assignments that sit inside a comma-chain (a.xy = …, b += 1;). The parser splits these into separate Stmt::Assigns but the intervening , would dangle if we expand one side into multiple statements. Conservative: leave the chain alone (rare in the corpus).

Structs§

RewriteState 🔒

Functions§

assign_op_str 🔒
components_unique 🔒
followed_by_comma 🔒
normalise_component 🔒
rewrite_swizzle_assigns 🔒
slice 🔒
try_emit 🔒
walk_block 🔒
walk_stmt 🔒