From 2ed08b08e1e8e32fc9479fddb3b56f5231b1cc60 Mon Sep 17 00:00:00 2001 From: Peterino2 Date: Mon, 2 Nov 2026 06:55:33 +0000 Subject: [PATCH] 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). --- src/spirv/emit.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/spirv/emit.zig b/src/spirv/emit.zig index a695b55..f2829cb 100644 --- a/src/spirv/emit.zig +++ b/src/spirv/emit.zig @@ -2189,7 +2189,14 @@ const Emitter = struct { switch (blk.merge) { .none => {}, .selection => |mb| try e.b.emit(.functions, .selection_merge, &.{ labels[mb.index()], 0 }), - .loop => |l| try e.b.emit(.functions, .loop_merge, &.{ labels[l.merge.index()], labels[l.@"continue".index()], 0 }), + // [unroll] / [loop] the IR could not act on are the + // driver's to honor (LoopControl Unroll / DontUnroll), as + // in dxc. + .loop => |l| try e.b.emit(.functions, .loop_merge, &.{ labels[l.merge.index()], labels[l.@"continue".index()], switch (l.unroll) { + .auto => 0, + .unroll => 1, + .dont => 2, + } }), } switch (blk.term) { .none, .@"unreachable" => try e.b.emit(.functions, .@"unreachable", &.{}),