Repository navigation
asahi: evaluate uniform-only G16G fragment arithmetic per draw - #50
IronsideXXVI wants to merge 4 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.
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.
6705206 to
cc1294e
Compare
[Medium impact] The changes affect selected G16G fragment-shader blend and scheduling paths. Fix the float-control mismatch before merging. FindingsSummaryMoves eligible G16G fragment arithmetic from per-pixel GPU work to per-draw CPU work. Review scope is the final commit; the three prerequisite commits belong to #49.
The evaluator needs to preserve the shader’s tiny-number rules and avoid reading an unused, uninitialized input. Reviews (1) · Last reviewed commit: "asahi: evaluate uniform-only G16G fragme..." · Reviewed by Greptile |
| case HK_G16_HOST_FMUL: r = s[0] * s[1]; break; | ||
| case HK_G16_HOST_FADD: r = s[0] + s[1]; break; |
There was a problem hiding this comment.
Tiny values change rendered colours.
hk_g16_host_lower takes arithmetic from the whole fragment shader, not just the final blend. With normal host floating-point settings, a shader computing (x * y) * z from push constants x = 2^-100, y = 2^-30, and z = 2^127 gets 0.125 here. A shader requesting DenormFlushToZero must instead get zero: the first multiply produces 2^-130, which must be flushed before the next multiply.
UNORM output does not hide this difference because the second multiply makes the tiny value large again. Honor the shader’s float controls for each CPU operation, or refuse host evaluation when those rules cannot be matched.
| for (unsigned j = 0; j < 2; ++j) { | ||
| const struct hk_g16_host_src *src = &p->ops[i].src[j]; | ||
| uint32_t u = 0; | ||
| if (src->kind == HK_G16_HOST_TEMP) { | ||
| s[j] = t[src->value]; |
There was a problem hiding this comment.
Unary operations read uninitialized memory. This loop reads two inputs even for
FSAT, FNEG, FABS, and MOV. Their unused second input is zero-filled when the operation is built, so its kind is HK_G16_HOST_TEMP and its index is zero. When the first operation is a clamp, the loop reads t[0] before anything writes it. The read is volatile, so discarding the unused result does not remove it.
Read only the inputs the operation uses, or initialize unused inputs as immediates. This avoids undefined behavior in the common clamp-first path.
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.