Skip to content

agx: apply kills at the end when a discarding shader uses subgroup ops - #245

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
gpucts/g13-ballot-count-demote
Nov 12, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
gpucts/g13-ballot-count-demote

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 12, 2026 •

Copy link
Copy Markdown

On G13/G14, agx_nir_lower_sample_mask() kills demoted samples where the demote happens. Once a quad has no non-helper lane left, the kill ends the quad, and its rasterizer helper lanes go with it although they never demoted. Non-quad subgroup operations that the remaining lanes run afterwards then miss those helpers. dEQP-VK.reconvergence.terminate_invocation.bit_count checks terminated + alive == all with ballots taken before and after terminateInvocation, and failed on every run.

A per-pixel probe (same shader, counts written to an RGBA32UI target) shows it: in subgroups that hold 3 or 6 helper lanes, the post-terminate ballot counts 14 or 12 lanes instead of 16. Subgroups without helpers count correctly.

Shaders that discard and also use non-quad subgroup operations now take the deferred lowering. Demotes accumulate into a kill mask that is applied at the end of the shader, and no dead-quad kill is inserted before it. Every other shader keeps the immediate kill. The gallium driver uses the same entry point, so GL shaders get the same treatment.

New unit test DemoteEarlyKill.ImmediateLoweringDefersKillsForSubgroupOperations; agx_tests 957/957 pass.

CTS 1.4.7.0, user-space overlays, base = aurora-wip 8135d4d:

M1 Pro (G13S) base M1 Pro fix M2 (G14G) base M2 fix
reconvergence.terminate_invocation.bit_count Fail 3/3 Pass 3/3 Fail Pass
fragment subgroup / reconvergence / demote / discard / terminate list (6,847) 3,937 Pass, 1 Fail 3,938 Pass, 0 Fail 3,937 Pass, 1 Fail 3,938 Pass, 0 Fail
vk-broad (36,127) 14,888 Pass, 0 Fail identical 14,888 Pass, 0 Fail identical
GL broad (13,223) 12,620 Pass, 0 Fail identical 12,620 Pass, 0 Fail identical
dEQP-GLES2/3/31 (99,745) 99,154 Pass, 0 Fail 0 Fail; only flush_finish timing warnings move 99,153 Pass, 0 Fail 0 Fail; one flush_finish timing warning moves

M4 Pro (G16S), where native GL takes the same entry point: GL broad (13,223) 12,620 Pass / 0 Fail with and without the change, 0 cases changed. Vulkan on G16S/G17P uses the AGX3 deferred lowering, which this change leaves alone (vk-broad on G16S: 18,621 Pass / 0 Fail on the base).

On G13/G14, agx_nir_lower_sample_mask() kills demoted samples where the
demote happens. Once no non-helper lane of a quad is left, the kill ends
the quad, and its rasterizer helper lanes go with it although they never
demoted or terminated. Non-quad subgroup operations that the remaining
lanes run afterwards then miss those helpers: a ballot of the lanes that
are still running counts fewer lanes than the same ballot taken before
the terminate. dEQP-VK.reconvergence.terminate_invocation.bit_count
checks exactly this (terminated + alive == all) and failed on every run,
in the subgroups whose quads held helper lanes.

When a shader discards and also has non-quad subgroup operations, use
the deferred lowering instead: demotes accumulate into a kill mask that
is applied at the end of the shader, after the last subgroup operation,
and no dead-quad kill is inserted before it. Every other shader keeps the
immediate kill. The gallium driver uses the same entry point, so GL
shaders get the same treatment on every chip that uses it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Assisted-by: LLM
Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant