Repository navigation
asahi: evaluate uniform-only G16G fragment arithmetic per draw - #50
IronsideXXVI wants to merge 9 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.
6705206 to
cc1294e
Compare
[Medium impact] The changes appear safe to merge; no new blocking issue was found. SummaryThis PR moves supported push-constant arithmetic from G16G fragment programs to the CPU once per draw.
No new actionable issues were found. The earlier reports about tiny values, unused inputs, and CPU rounding are addressed in the current code. This review used source checks; no builds or runtime tests were run.
|
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.
G16G forms no native constant program, so a fragment program whose colour comes from push constants recomputes the same clamps, 1 - alpha and source products for every pixel. For an inline-blend program, take the exact fp32 operations (fsat, fmul, fadd, fneg, fabs) whose operands are push constants or immediates, evaluate them on the host when the draw's root is built, and load the results from uniform halves 0..11. Those halves hold only the spill table and the blend constants, which such a program does not use; the program's uniform layout and launch words are unchanged. Fused multiply-add stays on the GPU because G16G FFMA does not round like the host. Only UNORM targets qualify, where host and GPU denormal or NaN handling cannot change a stored byte. For a uniform-colour alpha blend the fragment program becomes the tile load, unpack, one multiply-add per channel with uniform operands, pack and store. Programs built this way are not written to the disk cache. ASAHI_G16_HOST_BLEND_SRC=0 restores per-pixel evaluation; the setting is part of the physical device's compiler flags.
The GPU flushes fp32 denormal operands and results of fadd, fmul and fsat to zero: hk exposes shaderDenormFlushToZeroFloat32 and no fp32 denormal preservation. hk_g16_host_eval kept them, so a tiny intermediate the GPU flushes could be scaled back into range by a later multiply, for example (2^-100 * 2^-30) * 2^127 gave 0.125 on the host and 0 on the GPU, and a UNORM target does not hide that. Flush operands and results the same way on the host. fneg, fabs and mov only move bits and stay as they are; their GPU consumers flush. The source loop also read both sources of every operation. The unused second source of fsat, fneg, fabs and mov is zero-filled TEMP 0, so a clamp as first operation read t[0] before anything wrote it. Read only the sources each operation has.
cc1294e to
674ac37
Compare
|
Both notes were right. Fixed in 674ac37:
The repo's CI |
hk_g16_host_eval ran fadd and fmul in the calling thread's rounding mode, but GPU fp32 arithmetic rounds to nearest even. With FE_UPWARD set by the application, ((1 + 2^-24) - 1) * 2^23 gave 1 on the host instead of 0. Switch to FE_TONEAREST for the evaluation when the caller uses another mode, and restore the caller's mode afterwards.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Thanks Dylan. Reviewing only 67c5c8f, 674ac37 and d8e18f5 here; #49 covers the rest. Evaluating the uniform-only fp32 chain on the host for UNORM targets, with FMA left on the GPU, is a clean way to get the colour section down to the tile work. The 13 -> 4 ALU shape and the -24 % at both sizes are a big step. 674ac37 and d8e18f5 address all three Greptile notes: hk_g16_host_eval() flushes denormals like the GPU, reads only the sources each op has, and evaluates in round-to-nearest-even before restoring the caller's mode.
What blocks a merge:
ASAHI_G16_HOST_BLEND_SRC, like #49's switches, is a runtime switch, and merged code here can't carry it. Please drop it and the compiler-flag bit it adds.- Hardware conformance. This moves shader arithmetic to the CPU, so beyond the readbacks we need a G16G vk-default subset run (blend, push constants, fragment ops) with 0 new Fail/Crash against the base. The edge you flagged yourself belongs in that run as well: whether G16G detects tininess before or after rounding. A later multiply can bring a flushed intermediate back into range, so the host has to match the GPU there.
- Merge order: after #49.
The per-draw fegetround()/fesetround() pair is fine as it is. If CPU time per draw shows up in a profile later, a per-thread check is the obvious next step.
Mesa CI on d8e18f5 is approved and running.
|
Thanks. I'll drop |
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
Merged code cannot carry runtime switches. Remove ASAHI_G16_HOST_BLEND_SRC and agx_g16_host_blend_src_enabled(): on G16G, uniform-only fp32 arithmetic of an inline-blend fragment program is always evaluated on the host per draw (fused multiply-add stays on the GPU). The compiler-flag bit only kept the two settings apart, so it goes too. Limited to G16G because that is the only AGX3b part it was measured on. G16S and G16C were not measured; nothing known rules them out. Assisted-by: LLM
|
Pushed two commits on top of d8e18f5 (no force-push):
The repo's CI Still open: the G16G vk-default subset (blend, push constants, fragment ops) against the base, and inside that run, whether G16G detects tininess before or after rounding. I'll post both when they're done. |
|
Retargeted to aurora-silicon#606 |
Stacked on #49. This branch contains the three commits of #49 followed by one new commit; only the last commit, "asahi: evaluate uniform-only G16G fragment arithmetic per draw", is for review here. It uses the switch helpers and compiler-flag bits #49 adds, and the measured program shape assumes #49's destination-term-first blend. Please merge #49 first; this PR will then show the single commit.
G16G forms no native constant program, so a fragment program whose colour comes from push constants recomputes the same clamps,
1 - alphaand source products for every pixel. For the alpha-blended fill this is 9 of the 13 ALU instructions in the per-pixel program.This change takes, in an inline-blend fragment program on G16G, the exact fp32 operations (
fsat,fmul,fadd,fneg,fabs) whose operands are push constants or immediates, evaluates them on the host when the draw's root table is built, and has the program load the results from uniform halves 0..11. Only the native spill table and the blend constants otherwise use those halves, and a program of this kind uses neither. The program's uniform layout and launch words are unchanged; the results reach the program as one more root-relative uniform range.ASAHI_G16_HOST_BLEND_SRC=0restores per-pixel evaluation. The setting is part of the physical device's compiler flags, so cached pipelines from one setting are not reused under the other.For the uniform-colour alpha blend the fragment program becomes: pixel wait, tile load, two unpacks, one multiply-add per channel with both factors uniform, two packs, pixel wait, tile store (22 -> 13 instructions, 13 -> 4 ALU, 19 -> 11 registers, 170 -> 120 bytes).
Testing
ASAHI_G16_HOST_BLEND_SRC=0.The 2560x1440 and textured runs pause 45 s before each run: under minutes of continuous load this machine's GPU throughput drops by about a quarter for every build, which would otherwise mix states between runs.