Compare commits

..

4 Commits

Author SHA1 Message Date
Peterino2 97517cc5b1 SPIR-V: selection controls from [branch] and [flatten]
[branch] and [flatten] on if and switch were dropped: every
OpSelectionMerge had selection control None, leaving the driver to
flatten or keep the branch by its own heuristics. They now become
DontFlatten and Flatten, as in dxc (the Hyperion engine's shaders use
them 21 times). The IR keeps them on the header block; unrolling and
inlining carry them over.
2026-11-02 08:00:54 +00:00
Peterino2 d39ee30a4c SPIR-V: promote locals to SSA values; inline top-down
ir/ssa.zig, after inlining:

1. A local struct or array accessed only whole and with constant
   indices is split into one local per leaf member / element (scalar
   replacement, up to 64 leaves): whole reads construct the value,
   whole writes store each part. Promoting whole aggregates instead
   made each member write a copy of the aggregate; on the Glide shader
   that has many of them RADV then spilled ten times as many scalar
   registers.
2. Locals loaded and stored only whole (no resources) become SSA
   values: semi-pruned phi placement over dominance frontiers,
   renaming over the dominator tree, trivial phis folded, dead phis
   (cycles included) dropped. Reads before any write are the new IR
   `undef` (OpUndef). Phis take one value per predecessor the emitter
   writes, unreachable merge and continue targets included.

Constants that were behind locals fold afterwards. The SPIR-V emitter
emits OpPhi, patching operands emitted after the phi.

The inliner now works top-down from the entry points (each call gets a
copy of the callee's own body, whose calls are inlined as the scan
reaches them), copies only instructions in the callee's blocks (and
locals on first use), and remaps only instructions naming a call
result; scans use a non-allocating operand visitor (opt.eachOperand).

On Glide: loads 115040 -> 20322, stores 63644 -> 5832 (dxc: 11423,
2498), SPIR-V 12.0 -> 13.2 MB (callee bodies copied); compile time
587 -> 771 ms on 327 shaders (dxc: 8.6 s). Two more corpus files
compile (texel offsets that are constants once promoted).
2026-11-02 07:54:10 +00:00
Peterino2 afc4587596 SPIR-V: inline calls in the IR
dxc's SPIR-V gets its calls inlined by legalization; zdxc emitted every
function and left inlining to the driver, with 10361 calls across the
Hyperion engine's Glide shaders. ir/inline.zig now inlines bottom-up
before emission:

- The calling block is split at the call: it branches to a copy of the
  callee, and the rest of the block (terminator and merge included)
  moves to a continuation block. Parameters become the arguments.
- A callee with one return outside every construct branches from it to
  the continuation. Returns inside selections or switches become
  breaks out of a loop that runs once around the callee, the return
  value going through a local.
- Callees that return from inside a loop, [noinline] ones, ones with
  RayQuery or by-reference resource parameters, and ones returning a
  resource from several places stay functions (resource arguments then
  still get specializations).
- Functions nothing reaches any more are marked dead and not emitted.

Only modules with vertex, pixel and compute entry points and no
rasterizer-ordered views for now (the emitter treats the others'
functions specially). -Od and the new -zdxc-no-opt skip it; -zdxc-ir
prints the IR after the SPIR-V passes.

On Glide: 37 calls left; the SPIR-V grows (517k to 838k instructions,
callee bodies copied, one-trip loops) until promotion to SSA values
removes the locals; compile time 597 to 765 ms. The driver's own
statistics barely move, except one compute shader passing float4[28]
arrays by value, whose copies now take more scratch.
2026-11-02 07:10:23 +00:00
Peterino2 2ed08b08e1 SPIR-V: loop controls from [unroll] and [loop]
Loops the IR keeps (its unrolling gave up, or [loop] asked it not to)
lost their attribute: every OpLoopMerge had loop control None. The
driver now gets Unroll for [unroll] and DontUnroll for [loop], as from
dxc.

On the Hyperion engine's Glide shaders this is what made its half
resolution Glimmer irradiance pass about 5% slower than with dxc: an
[unroll] loop over a run-time count that RADV unrolls for dxc's output
stayed a loop for zdxc's (2381 instructions against dxc's 5765; now
5856).
2026-11-02 06:55:33 +00:00

Diff Content Not Available