Repository navigation
asahi: replay native AGX3 direct draws that change only VS constants - #1285
Conversation
A loop of direct draws that rebinds a uniform block range or updates a default-block uniform before each draw changes nothing on the native AGX3 path (M3, M4 and Neo GPUs) but the vertex stage table. Each draw still went through the whole of agx_draw_vbo(): shader, feedback-loop and transform-feedback checks, descriptor updates, the root table comparison, uniform range collection and the patch-plan lookup for the vertex program, only to emit a vertex state update and a draw body. Record the last direct draw of a batch, with the uniform ranges of the vertex program it latched, and replay a following direct draw that changed only vertex constant buffers (or nothing): upload the vertex stage table, patch the same plan with the ranges moved to the current tables, and emit the vertex state update and the draw body the full path would emit. The replay needs the recorded draw to end the VDM stream, the same shaders, primitive and index format, no dirty state but vertex constants, no bound queries, no transform feedback or conditional rendering, and a template list unchanged since the record. Anything else takes the full path, which records the draw again. A vertex shader that reads draw parameters or its stage table pointer from the root table is never recorded: a replay changes that pointer without uploading a new root table. A drm-shim test checks on G13G, G15G, G16G and G17P that replayed draws read the new binding, emit the same commands as the full path apart from the vertex program address, emit only the draw body when nothing changed, and that query-counted draws and fragment state changes take the full path. Signed-off-by: DjDeveloperr <hey@djdev.me>
satchlj
left a comment
There was a problem hiding this comment.
Reviewed at 40dc32ad69bb: clean native-AGX3 repeat-draw fast path in agx_draw_vbo_repeat() / agx_draw_repeat_record(). Guards cover num_draws > 1 (handled earlier), vdm_end == batch->vdm.current, non-VS-const dirty bits, query/XFB/tess/GS/patch/memory-write/unaligned-index/user-index/base-param/draw-id exclusions, template eviction (g17p_graphics_templates_generated), root-table stage-pointer reads (agx_vs_reads_stage_table_pointer), and safe fallback if patching/emission fails before batch->vdm.current or dirty bits are touched. Solid unit test (test-agx-repeat-draw.c), GLES3/3.1 dEQP coverage, and J700 ABBA numbers.
Bring in mesa#1271 (compute pixel-unpack uploads to AGX3 images). The only conflict is the asahi drm-shim test list in meson.build: keep both the repeat-draw tests and the image-copy-buffer tests. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
Verdict: MERGE at 7918a2e1 (land together with or after mesa#1290)
Blockers: none (pairing note: keep merge order with or after mesa#1290 so unpinned render.draws direct 4096 d1 keeps the P-core placement win instead of the standalone -39.6% E-core placement regression).
Checked:
- Verified forward-merge
7918a2e1ontoaurora-wip(postmesa#1271): PR diff remains strictly scoped to the same 5 files (agx_batch.c,agx_state.c,agx_state.h,src/gallium/drivers/asahi/meson.build,tests/test-agx-repeat-draw.c). The only conflict resolution inmeson.buildcleanly preserves bothasahi-*-repeat-drawandasahi-*-image-copy-bufferdrm-shim tests. - Core repeat-draw fast path (
40dc32ad) was already reviewed and approved, andmesa#1271's compute pixel-unpack path touches only compute-stage state (ignored by the vertex-only replay guard). - Verified exact-head J700 ABBA+BAAB pair run (
#1285 @ 7918a2e1+#1290 @ 6e42e7ad,n=4arms): all four direct-draw rows win 4/4 pairs (-61.37%/-37.37%/-28.69%/-39.54%), 0/16 control regressions, all 20 row CRCs + 28 draw-state CRCs + 16 copy CRCs match, dEQP GLES3 draw324/324and UBO2,357/2,357pass, 0 GPU faults, 0 AVCs. - Verified exact-head Fedora Mesa CI
220/0and full drm-shim--suite asahi(341/344in both release and-Db_ndebug=false, includingrepeat-drawong13g/g15g/g16g/g17p).
Evidence
Risk:two-way · M3, M4, Neo GL (native AGX3 only; M1/M2 and M5 never record a draw).- Minor body nit (non-blocking): the
## Not yetbullet still reads "This PR stays a draft until then" even though the PR is now ready and verified paired with#1290.
|
J516s second-generation confirmation — PASS for GL and stock-kernel compatibility MacBook Pro (M3 Pro / T6030),
64/64 CRC observations matched across all eight rows. Direct 1024 d4 was flat and direct 4096 d1 was variable (3/4 pairs faster). Copy throughput was 0.97% lower (3/4 pairs slower, worst pair −1.16%). The other control medians were within 0.72%. There were 0 GPU faults, recoveries, hang kills, quarantines or AVCs. Both arms mapped their own
|
What
On native AGX3 GPUs (M3, M4, Neo), Gallium
asahinow replays a direct draw that follows the previous draw of the batch with only vertex constant buffers rebound, or with nothing changed. This is the loop of a UBO range rebind or aglUniform*before eachglDraw*. Before this change each such draw ran the whole ofagx_draw_vbo(): shader and legality checks, descriptor updates, the root table comparison, uniform range collection and the patch-plan lookup for the vertex program. All of that only to emit a vertex state update and a draw body.This is a different approach from the direct-draw fast path dropped from mesa#1271. On J700 that one never fired:
agx_g17p_try_fast_direct_drawis absent from the profile. It refused every vertex program with a root-table range, i.e. every VS that fetches attributes, so it only added per-draw bookkeeping.New drm-shim test
asahi-{g13g,g15g,g16g,g17p}-repeat-drawchecks:Tested
Tested: J700 MacBook Neo (G17P B1), kit built from 12baca553c7. The driver code of head 40dc32a is the same in release builds; the head adds a debug-build
ASAHI_MESA_DEBUG=dirtyguard, the unit test and the commit message. gpubench-glrender.draws mode=direct: 1024 draws +21.3 % (depth 1) / +37.7 % (depth 4), 4096 draws +43.8 % (depth 4). 4096 draws at depth 1 is −39.6 %, from CPU placement (see Not yet): with the process pinned to the P-cores or withuclampset -m 512, the same row is +30 % / +32 %.mode=mdiand the control rows are within ±0.5 %, except copy_b2i d1 at −3.5 % (inside the arm spread). Conformance is unchanged. 0 GPU faults, 0 SELinux denials, 0 failed units.gpubench-glc228eec (+dirty; the same binary for both arms),--verify, warmup 250 ms, 5 runs × 300 ms per row. Same-boot interleaved A1 B1 B2 A2 B3 A3 A4 B4 (ABBA + BAAB), 4 arms per build. Each arm ran from an isolated tmpfs kit withMESA_LOADER_DRIVER_OVERRIDE=asahi EGL_PLATFORM=surfaceless MESA_SHADER_CACHE_DISABLE=true, with a CPU cool-down between arms.GALLIUM_THREAD=0. The loops cover UBO rebinds, default-block uniforms, DrawArrays, a mix of VBO, fragment-uniform, restart, instancing, base-vertex and misaligned-start changes, UBO rewrites mid-loop, identical consecutive draws with blending, and two UBOs with flushes. gpubench--verifyCRCs were identical on every row that has one.meson.build; both test sets are kept. mesa#1271's compute pixel-unpack upload only binds compute-stage state, which the replay already ignores, so no driver change was needed. Fedora Mesa CI at 7918a2e: 220/0. drm-shim builds, full--suite asahi, release and assert (-Db_ndebug=false): 341/344 each. That includesrepeat-drawon G13G/G15G/G16G/G17P and mesa#1271'simage-copy-buffer(unit, G13G, G17P). The 3 failures areasahi-egl-priority-*, which fail the same way on aurora-wip: EGL does not initialize in the headless CI container. No new warnings insrc/gallium/drivers/asahi(the assert build's unusedbatch_idxinagx_batch.cis already on aurora-wip). The newer aurora-wip commits after 55a8378 do not touch this driver../rig/fedora-mesaci.sh, the repo's asahi workflow) at 40dc32a: 219/0. The drm-shim build (-Dtools=drm-shim) passed 6/6 (the 4 new tests + reload-elision) with 0 new warnings. The assert build (-Db_ndebug=false, full--suite asahi) at 40dc32a: 218/0.hk_packhit the 30 s timeout while the CI host was busy and passed on rerun (21.6 s).stock.shstate was identical before and after every run.rig/fedora-mbuild.sh) with the same meson options.perfondraws=4096depth 4: the threaded-context driver thread has 66 % of the samples and the GPU is busy 165 µs of each ~840 µs submit. On the candidate, the replay replaces the full path for these draws.Risk
Risk: two-way · M3, M4, Neo GL (native AGX3 only; M1/M2 and M5 never record a draw)
Not yet
taskset -c 0,5) the row is 926.0 → 649.4 µs (+30 %); withuclampset -m 512it is 960.0 → 650.1 µs (+32 %). Base already loses the same way at 1024 draws: 757 µs unpinned vs 393 µs pinned. Mesa's thread-placement policy for this (util_thread_sched, the threaded-context thread following the app thread's cache domain) is x86-only. A fix belongs in its own change with its own A/B. This PR stays a draft until then.Evidence
J700 per-arm medians,
render.draws, µs per submit (lower is better):Median of 4 arm medians. Positive delta = faster.
crc same= identical--verifyCRC on every arm of both builds;n/a= the row has no image check.copy_b2i d1 per arm, GB/s: base 36.18 / 36.41 / 36.41 / 34.78, candidate 34.62 / 35.18 / 34.84 / 35.18.
Depth-1 placement check (same boot, 2 arms per build, µs per submit):
taskset -c 0,5uclampset -m 512Unpinned,
perf --sample-cpuputs the base driver thread on CPU 5 (a P-core) and the candidate's on CPU 4 (an E-core).dEQP on J700, same counts on both builds:
Fedora CI on 40dc32a:
FEDORA-CI 40dc32ad69bb 219/0 after-rc=0; drm-shimasahi-{g13g,g15g,g16g,g17p}-repeat-drawandasahi-{g13g,g17p}-reload-elision6/6, 0 warnings in agx_state.c and the new test. Assert build (-Db_ndebug=false):218/0 + hk_pack timeout,hk_packandagx_testsOK on rerun.Exact-head J700 pair verification (
#1285 @ 7918a2e19e46+#1290 @ 6e42e7ada894)Same-boot ABBA+BAAB (
n=4arms/build, 5 timed samples/arm) on MacBook Neo (J700/G17P B1), stock7.3.0-41(apple-mcc4-plane SLC enabled, DTokay,stock.shPRE==POST,0GPU faults,0AVCs), base702dd0165bd0vs combined6a2466d5ac44:render.draws direct 1024render.draws direct 1024render.draws direct 4096render.draws direct 4096transfer.ops copy_b2itransfer.ops copy_b2iAll 14 other GL/VK control rows (
mdi1024/4096 d1/d4,render.heavy,render.light,compute.light) stayed within-0.19%to+0.96%(0/16controls exceeded the regression threshold). All 20 row CRCs, 28 draw-state CRC snapshots, and 16 in-arm copy CRCs matched; dEQP GLES3 draw324/324and UBO2,357/2,357passed on both builds;gdrv0moveduclamp.min 0 -> 512withSeccomp: 0.