Skip to content

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

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

IronsideXXVI wants to merge 3 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: 4/5

[Medium impact] The changes affect G16G fragment shader generation and blending.

The PR appears safe to merge, with a non-blocking request for regression tests around the new instruction-moving pass.

Findings

  1. P2 Instruction moves lack tests ▶

Summary

This PR changes G16G blended fragment programs to shorten the work after the pixel wait.

  • G16G blend programs put the destination term first in additive colour math.
  • G16G fragment programs move uniform-only arithmetic before the pixel wait.

Acknowledged behavior: IronsideXXVI explicitly intended the different final rounding and reported differences within Vulkan’s blending precision requirements.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[G16G blend state] --> B[Destination-first blend add]
  B --> C[Compile and schedule]
  C --> D[Move uniform-only arithmetic before pixel wait]
  D --> E[Allocate registers and emit program]
Loading

Reviews (1) · Last reviewed commit: "asahi: issue uniform-only G16 fragment a..." · Reviewed by Greptile

Comment on lines +8895 to +8896
static bool
agx3_g16_hoist_pixel_independent(agx_context *ctx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Instruction moves lack tests

agx3_g16_hoist_pixel_independent changes instruction order after scheduling, but no test covers its dependency checks or chip gate. Add cases showing a chain of uniform-only operations moving together before WAIT_PIX, a tile-dependent operation staying put, and unchanged order on other chips or with the opt-out. Hardware readbacks do not protect these rules from later compiler changes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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