Repository navigation
asahi: emit clean G17P multi-draw sub-draws without re-validating state - #430
Conversation
util_draw_multi() sends every sub-draw of a multi-draw (Sodium's glMultiDrawElementsBaseVertex terrain) through agx_draw_vbo(), which re-validates shaders, descriptors, feedback loops and queries each time: about 0.1 us of CPU per sub-draw. agx_encode_state() already emits nothing for a sub-draw once the context is clean, so after one full draw the following sub-draws only need their index list records. The feedback-loop check and the index buffer read are made once per multi-draw, since bindings cannot change inside it. Draw ID or base parameters in uniforms, statistics or primitives-generated queries, geometry/tessellation stages, transform feedback, passthrough GS and misaligned index starts keep the full path. Only G17P (A18 Pro, M4 Pro, M4 Max) takes it. AGX_FAST_MULTIDRAW=0 disables it. On an M4 Max, a Sodium-style terrain frame (16000 sub-draws, 4.1M vertices, 864x558), median of three runs: CPU 0.995 -> 0.399 ms per frame, frame 1.331 -> 0.865 ms. 400 sub-draws: unchanged. Images are identical with and without it (32-bit and 16-bit indices, non-indexed, culled). Assisted-by: LLM
|
Thanks for this, the CPU savings on Sodium-style multi-draws are a clear win and the write-up is very easy to follow. One request on scope. We select behaviour by a hardware property, not by the set of machines a change was measured on. The fast path is a CPU-side skip of re-validation, yet it is turned off for M5 and G18G without a stated hardware reason:
If you make it the default, we can run CTS and a sodiumbench A/B on our A18 Pro and M4 Pro and post them here. |
|
Hardware test on an A18 Pro (G17P, J700), Fedora 45 arm64 release build, as a user-space overlay over Mesa 26.3.0-30 on kernel 7.3.0-40. Arms: A = aurora-wip 57df4db. B = A + #417 #418 #419 #428 #429 #430 #435 at their current heads (one clean merge). Same machine, same boot.
|
|
A follow-up on the scope question above: looking closer, the M5/G18G exclusion is right. On those chips |
…w path Follow-up to aurora-silicon#430 by AxxzyWasTaken. agx_draw_multi() fell back to util_draw_multi() on agx_chip_g17_m5() or AGX_CHIP_G18G in addition to !agx_native_graphics(). agx_native_graphics() is agx_chip_native_agx3(), which is already false on G17G/S/C and G18G, so those terms could never decide anything. Remove them; the condition that remains is the real one: the fast path writes the HAL200 draw body every native AGX3 chip encodes, and the comment now says so. AGX_FAST_MULTIDRAW only turned the default path off. It is not a debug flag of the driver's ASAHI_MESA_DEBUG set and adds a second way to change driver behaviour from the environment, so remove it too. Behaviour with the variable unset is unchanged on every chip. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
util_draw_multi()sends every sub-draw of a multi-draw (Sodium'sglMultiDrawElementsBaseVertexterrain) throughagx_draw_vbo(), which re-validates shaders, descriptors, feedback loops and queries each time, about 0.1 us of CPU per sub-draw.agx_encode_state()already emits nothing for a sub-draw once the context is clean, so after one full draw the following sub-draws only need their index list records.The feedback-loop check and the index buffer read are made once per multi-draw, since bindings can't change inside it. Draw ID or base parameters in uniforms, statistics or primitives-generated queries, geometry/tessellation stages, transform feedback, passthrough GS and misaligned index starts keep the full path.
AGX_FAST_MULTIDRAW=0turns it off.Only G17P (A18 Pro, M4 Pro, M4 Max) takes it. Measured only on the M4 Max.
Setup
aurora-wip4ad5457 (baseline) and this branch, 2b09226 (-Dbuildtype=release -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dbuild-tests=true).ASAHI_MESA_DEBUG=1queue,MESA_GLTHREAD=false). Each build's libgallium is picked withLD_LIBRARY_PATH. Desktop running, no game.Benchmark
sodiumbench(source below) draws Sodium's 20-byte vertex format the way Sodium does: oneglMultiDrawElementsBaseVertexper frame, one sub-draw per section, a shared quad index buffer, 864x558 RGBA8 + Z32F.realuses Sodium's terrain shaders (from the mod, not attached);trivialuses minimal built-in shaders. 10 warm-up frames, 300 timed. "CPU" is the time spent in the draw call andglFlushper frame. 3 runs per build, alternating base / PR.realtrivialrealThe 400-draw case has little CPU to save; its frame time moved within the baseline's own spread (0.62-0.75 ms). The PR build with
AGX_FAST_MULTIDRAW=0gives the baseline: 1.287 ms frame, 0.948 ms CPU.In Minecraft (15 Nov, render distance 32, OpenGL) an A/B of the switch gave 105.0 vs 105.1 fps: that scene is GPU-bound, so only the CPU time goes down. It has been in this machine's daily GL driver since 15 Nov.
Correctness
glMultiDrawArrays) and back-face culled: all208274265f1ebe83on both builds.rangeverify verify,zsverify verifyandgldepthcomp(1920x1080, 3456x2234): identical to the baseline.meson test --suite asahi: 138 passed, 0 failed (baseline 138/0).Not tested: the A18 Pro and M4 Pro; games on this exact build.
Commands
Raw output
sodiumbench.c