Repository navigation
asahi: G16G blend destination term first, uniform-only arithmetic before the pixel wait - #49
IronsideXXVI wants to merge 3 commits into
Conversation
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.
[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
SummaryThis PR changes G16G blended fragment programs to shorten the work after the pixel wait.
Acknowledged behavior: IronsideXXVI explicitly intended the different final rounding and reported differences within Vulkan’s blending precision requirements.
|
| static bool | ||
| agx3_g16_hoist_pixel_independent(agx_context *ctx) |
There was a problem hiding this comment.
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!
Two small G16G changes to alpha-blended fragment programs, plus one opt-in
nir_lower_blendoption they rely on.nir/lower_blend: add an option to emit the destination term first. Additive blending emitssrc * src_factor + dst * dst_factor, which contraction turns intoffma(src, src_factor, dst * dst_factor). Withnir_lower_blend_rt::dst_term_firstthe destination term comes first, so contraction givesffma(dst, dst_factor, src * src_factor). Default off; no other driver changes behaviour.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.asahi: issue uniform-only G16 fragment arithmetic before the pixel wait. After scheduling,fadd,fmul,ffmaandmov_immcomputed only from uniforms and immediates move ahead of the firstwait_pixof a G16G fragment block. For a uniform-colour blend the source terms (clamps,1 - alphaand 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=0andASAHI_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
This improves blended fill by about 5 %; it is not a parity claim. No Apple binaries or captures are included.