Skip to content

asahi: G16G blend destination term first, uniform-only arithmetic before the pixel wait - #49

Open
IronsideXXVI wants to merge 5 commits into
omacom:integration/aurorafrom
IronsideXXVI:fix/g16-blend-dst-first
Open

IronsideXXVI wants to merge 5 commits into
omacom:integration/aurorafrom
IronsideXXVI:fix/g16-blend-dst-first

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 17, 2026 •

Copy link
Copy Markdown

Two small G16G changes to alpha-blended fragment programs, plus one opt-in nir_lower_blend option they rely on.

  1. nir/lower_blend: add an option to emit the destination term first. Additive blending emits src * src_factor + dst * dst_factor, which contraction turns into ffma(src, src_factor, dst * dst_factor). With nir_lower_blend_rt::dst_term_first the destination term comes first, so contraction gives ffma(dst, dst_factor, src * src_factor). Default off; no other driver changes behaviour.
  2. asahi: emit the blend destination term first on G16G. The epilog key carries the choice and it is set only on G16G, so other chips compile as before (including the G17P golden-byte epilog tests) and cached shaders are separated. Each channel then needs one dependent operation after the tilebuffer load and unpack instead of a multiply followed by a multiply-add.
  3. asahi: issue uniform-only G16 fragment arithmetic before the pixel wait. After scheduling, fadd, fmul, ffma and mov_imm computed only from uniforms and immediates move ahead of the first wait_pix of a G16G fragment block. For a uniform-colour blend the source terms (clamps, 1 - alpha and the source products) are then computed before the ordered colour section, which holds only the tile load, unpack, one multiply-add per channel, pack and store. Texture, varying and tile-dependent work keeps its scheduled place. Operations, modifiers and operands are unchanged.

Opt-outs: ASAHI_G16_BLEND_DST_FIRST=0 and ASAHI_G16_PIX_HOIST=0 (both part of the compiler cache identity). The selected 1080p blended-fill program stays at 170 bytes / 22 instructions; only association and order change.

Testing

  • Hardware (M4 MacBook Pro, one boot, isolated driver builds, order installed/off/dst-first/both/both/dst-first/off/installed, depth 64, 1080p RGBA8 fill with 16 alpha-blended layers): off 348.96 µs per submit, destination-first 341.67 (-2.09 %), both 331.64 (-4.96 %); both runs with both changes were below both off runs; installed vs off 0.02 %. 1440p: both changes not slower (the second half of that sequence was disturbed and is not used). Zero GPU faults, health checks before and after every arm.
  • Installed as the system driver on the same machine afterwards: the same blended-fill measurement read 332.1 µs per submit (348.8 before), zero GPU faults.
  • Moving the uniform arithmetic without the destination-first order was measured separately and was slower (+1.5 %); this series only moves arithmetic that depends on uniforms alone.
  • Pixels: a 1920x1080, 16-layer readback of the blended fill and textured paths with three push colours (including alpha 0 and 1 and out-of-range components) and a 64-frame blend/scissor/signed-zero sequence. Off matches the previous driver byte for byte; on differs by at most one UNORM8 step (12755 of 49766400 channel bytes in the fill/texture readback, 0 in the 64-frame sequence), from the association of the final add. Both orders are within Vulkan's blending precision requirements.
  • Compiled programs for the blended-fill, opaque, textured, geometry and plain-triangle benchmark pipelines: unchanged except the blended-fill and textured-blend fragment programs; with both opt-outs byte-identical to the previous build. Textured blended draws, timed afterwards on the installed driver (defaults against both opt-outs, alternated five times, depth 64, 1080p): 784.3 µs against 792.0 µs per submit (-1.0 %); blended fill in the same sequence 331.7 against 348.5 (-4.8 %); zero GPU faults.
  • Packaging build with the full Meson suite: 188 passed, 0 failed, with the defaults and with both opt-outs. On this branch (integration/aurora) the asahi suite passes 73/73 in both settings.

This improves blended fill by about 5 %; it is not a parity claim. No Apple binaries or captures are included.

Additive blending currently emits src * src_factor + dst * dst_factor. With dst_term_first the destination term comes first, so contraction fuses the destination product into the final multiply-add and the source product becomes a separate multiply that a backend can schedule independently of the destination load. Off by default; no driver changes behaviour.
On G16G the epilog's additive blend now fuses dst * dst_factor into the final multiply-add, so each channel needs one dependent operation after the tilebuffer load instead of a multiply followed by a multiply-add. The source product no longer depends on the destination and is scheduled in the load's shadow. The association of the last add changes, so results may differ by one UNORM step from the previous order. The choice is carried in the epilog key, so it applies only to G16G and separates cached shaders. ASAHI_G16_BLEND_DST_FIRST=0 restores the previous order.
After scheduling, move fadd, fmul, ffma and mov_imm computed only from uniforms and immediates ahead of the first wait_pix of a G16G fragment block. With the blend destination term first, the source terms of a uniform-colour blend (clamps, 1 - alpha and the source products) are then computed before the ordered colour section, which holds only the tile load, unpack, one multiply-add per channel, pack and store. Texture, varying and tile-dependent work keeps its scheduled place. Operations, modifiers and operands are unchanged, so results are bit-identical. The choice is part of the Vulkan compiler flags and the Gallium disk-cache identity. ASAHI_G16_PIX_HOIST=0 restores the previous placement.
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was found.

Summary

This PR changes G16G blend arithmetic to shorten the work after the pixel wait.

  • G16G additive blends put the destination term first.
  • G16G fragment programs move uniform arithmetic ahead of the pixel wait.
  • The compiler debug header gains an extra blank line.

Reviews (3) · Last reviewed commit: "asahi: drop the G16G blend and hoist swi..." · Reviewed by Greptile

Comment thread src/asahi/compiler/agx_compile.c Resolved
agx3_g16_hoist_pixel_independent reorders instructions after scheduling,
so cover its rules directly instead of relying on hardware readbacks:

- a chain of uniform-only fmul, fadd, ffma and mov_imm moves ahead of
  WAIT_PIX and keeps its scheduled order;
- a tile load, the operation reading it and the operation reading that
  result stay after the wait, although they also read uniforms;
- nothing moves without a wait, on other chips, in other stages or in
  preambles;
- ASAHI_G16_PIX_HOIST=0 keeps the scheduled order.

Export the pass so the test can call it.
@IronsideXXVI

Copy link
Copy Markdown
Author

On the test note: agreed, and added in 5f81ba4 (src/asahi/compiler/test/test-g16-pixel-hoist.cpp). The pass is now exported so the test can call it. The tests cover:

  • a uniform-only fmul -> fadd -> ffma chain (and the mov_imm it reads) moving ahead of WAIT_PIX in order;
  • a tile load, the op that reads it, and the op that reads that result all staying after the wait;
  • no change without a wait, on other chips (G13G/G13X/G14G/G14X/G17P), in compute and vertex shaders, or in a preamble;
  • no change with ASAHI_G16_PIX_HOIST=0.

The repo's CI build.sh passes locally on this head (meson test: 156 ok, 0 fail). #50 and #51 are rebased on top.

@greptile-apps

greptile-apps Bot commented Nov 20, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

@IronsideXXVI

Copy link
Copy Markdown
Author

The re-review of 5f81ba4 raised no new notes, so nothing more to change here. The fork CI run for this head still needs a maintainer to approve it.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Dylan. Emitting the destination term first, so each channel needs one FMA after the tile load, makes sense. The opt-in nir_lower_blend_rt::dst_term_first leaves every other driver unchanged. The order-balanced timings and the off-vs-on readback (at most one UNORM8 step) are what we'd want to see.

What blocks a merge:

  1. ASAHI_G16_BLEND_DST_FIRST and ASAHI_G16_PIX_HOIST are runtime switches. Merged code here can't carry those. Please drop both, along with the cache-identity bits that exist only to keep the settings apart. The tests in test-g16-pixel-hoist.cpp that setenv the opt-out can check the result against the pre-change program on a chip the pass doesn't touch instead.
  2. agx3_g16_hoist_pixel_independent() moves uniform reads ahead of the first WAIT_PIX without checking for a uniform write between the two. If a G16G main fragment program can never write a uniform register, please say that in the comment, or assert it. If it can, the pass has to stop at the first such write.
  3. Hardware conformance, which this tree's policy requires before a merge. Blend output changes by up to one UNORM8 step, so we need a G16G vk-default subset run (blend and fragment-ops groups at least) with 0 new Fail/Crash against the integration/aurora base.

A question, not a blocker: every G16 part executes AGX3b, but both changes are G16G-only. If G16S/G16C are out only because they weren't measured, please say so in the commit messages.

#50 and #51 carry these commits, so this one merges first. Mesa CI on 5f81ba4 is approved and running.

@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks. I'll drop ASAHI_G16_BLEND_DST_FIRST and ASAHI_G16_PIX_HOIST with their cache-identity bits, and have the tests compare against the pre-change program instead of using the opt-out. For the hoist, I'll either show and assert that a G16G main fragment program can't write a uniform register before the first WAIT_PIX, or stop the pass at the first such write. Then the G16G vk-default subset (blend and fragment ops at least) against the base.

On G16S/G16C: same as #48, left out only because I haven't measured them; the commit messages will say so.

Merged code cannot carry runtime switches. Remove ASAHI_G16_BLEND_DST_FIRST
and ASAHI_G16_PIX_HOIST with their helpers: on G16G the blend destination
term is always emitted first and uniform-only arithmetic is always issued
ahead of the first WAIT_PIX. The Vulkan compiler-flag bit and the Gallium
disk-cache bit only kept the settings apart, so they go too.

agx3_g16_hoist_pixel_independent() moved uniform reads ahead of the wait
without looking for a uniform write between the two. Stop the scan of a
block at the first instruction after the wait that writes the uniform file
(uniform_store or a uniform destination); nothing after it moves.

Tests: the opt-out test is replaced by StopsAtUniformWrite; the other-chip
test already checks the scheduled program is left as it was where the pass
does not run.

Both changes stay limited to G16G because that is the only AGX3b part they
were measured on. G16S and G16C were not measured; nothing known rules them
out.

Assisted-by: LLM
@IronsideXXVI

Copy link
Copy Markdown
Author

Pushed 6f13b2d ("asahi: drop the G16G blend and hoist switches, stop at uniform writes"):

  • ASAHI_G16_BLEND_DST_FIRST and ASAHI_G16_PIX_HOIST are gone with their helpers, the Vulkan compiler-flag bit and the Gallium disk-cache bit. On G16G both changes are unconditional.
  • Uniform writes: agx3_g16_hoist_pixel_independent() now stops scanning a block at the first instruction after the wait that writes the uniform file (uniform_store or a uniform destination). Nothing after that write moves. I didn't want to rely on main programs never writing uniforms. New test: G16PixelHoist.StopsAtUniformWrite.
  • The opt-out test is gone. OtherChipsStagesAndPreamblesUnchanged already checks that the scheduled program stays as it was on chips and stages the pass doesn't touch, and the setenv calls are gone.
  • The commit message says G16S/G16C are left out only because they weren't measured.

The repo's CI build.sh passes locally on this head (meson test: 156 ok, 0 fail). #50 and #51 carry the same change as a new commit on top (no force-push).

Still open: the G16G vk-default subset run (blend and fragment-ops groups at least) against the integration/aurora base. I'll post it when it's done.

@IronsideXXVI

Copy link
Copy Markdown
Author

Retargeted to aurora-silicon#605

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.

2 participants