Repository navigation
asahi: cache the HAL200 resource pointer pair per batch - #619
Conversation
Handle glMultiDraw{Elements,Arrays}Indirect (indirect->draw_count > 1
without an indirect draw count) on native HAL200 chips via a dedicated
agx_draw_multi_indirect() fast path instead of unrolling every sub-draw
through full agx_draw_vbo() validation.
Draw 0 (and the first draw after any mid-loop batch flush) runs through
agx_draw_vbo() to validate shaders, descriptors, feedback loops, BO
residency, and the HAL200 bind tail. Subsequent sub-draws on the clean
batch skip per-draw validation:
- When neither uses_base_param nor uses_draw_id is active, emit only the
indirect draw body without a bind tail or draw-state selector.
- When uses_base_param (including instanced vertex attributes) or
uses_draw_id is active, update only the per-draw VS parameters, rebuild
the VS program, and emit the VDM vertex state update followed by the
cached bind tail and draw-state selector from draw 0, avoiding redundant
bind-state uploads and scissor/depth-bias array growth.
Normalize stride == 0 to the tightly packed command size (20 bytes indexed,
16 bytes non-indexed) and fall back to util_draw_multi_unroll_indirect()
for non-native chips, count_from_stream_output, and user index pointers.
Signed-off-by: Diljit Singh <hey@djdev.me>
…w indirect In agx_draw_multi_indirect(), after draw 0 (or any mid-loop batch flush) establishes a clean native HAL200 batch, memoize: - the pre-relocated G17P VS Ioto program and its AGX_SYSVAL_TABLE_PARAMS relocation sites (using hk_g17p_patch_plan_init/hk_g17p_patch_ldimm) for the common uses_base_param && !uses_draw_id && !root_reads_params_ptr path, - the 28-byte VDM vertex state update (patching only the 8-byte pipeline pair per sub-draw), and - the packed HAL200 indirect draw record (patching only the indirect buffer VA words per sub-draw). Any edge case (cluster-shared PARAMS ranges, short-LDIMM overflow, preamble, or unaligned indirect VA) falls back cleanly to agx_build_pipeline() and agx_g17p_emit_indirect_draw(). Signed-off-by: Diljit Singh <hey@djdev.me>
…ast-patch
Cache each stage's 16-byte {texture_base, samplers} pointer pair upload
in batch->g17p_resource_pair[] (reset on batch init) and reuse it in
agx_build_g17p_graphics_program() and agx_multidraw_init_vs_patch().
Previously, every textured VS draw allocated a fresh pointer pair from
batch->pool, shifting ranges[0] by +16 bytes relative to ROOT/VS ranges
in the same batch->pool address-cache component. That caused
graphics_program_shape_equal() to fail on every textured sub-draw, both
disabling the multi-draw indirect VS fast-patch and thrashing the
8-entry G17P graphics program template cache.
Also narrow root_reads_params_ptr in agx_draw_multi_indirect() to check
overlap specifically with tables[AGX_SYSVAL_TABLE_PARAMS], and fall back
to generating one address-independent patchable template per multi-draw
if the MRU template shares a cluster with PARAMS.
Signed-off-by: Diljit Singh <hey@djdev.me>
There was a problem hiding this comment.
Verdict: REQUEST CHANGES at 2c4f7c49
Blockers:
- Branch is
CONFLICTINGwithaurora-wip. Rebase/merge currentaurora-wipacross the 3 touched files (+716/-13) so the PR isMERGEABLE. - Missing exact-head build/host test and hardware verification. After rebasing, post host test results and exact-head HAL200/G17P multi-draw indirect hardware verification (plus a second-generation regression row for shared Gallium paths).
Checked:
- Commit series (
d8439b38,b24a6d02,2c4f7c49),CONFLICTINGagainstaurora-wip.
Evidence
- Resolve
CONFLICTINGagainstaurora-wipbefore full code/hardware sign-off.
There was a problem hiding this comment.
Verdict: HOLD at 844e9384
Blockers:
- PR title and description out of sync with narrowed diff (
+34/-6): After844e9384mergedaurora-wip, the multi-draw indirect fast-path commits are no longer in the diff againstaurora-wip— only the per-batchagx_g17p_resource_pair_va(){texture_base, samplers}pointer-pair cache remains. Please update the PR title and body to match the actual+34/-6change. - Exact-head build, host tests, and hardware verification at
844e9384missing: Please post a fresh build +meson test --suite asahipass plus exact-head844e9384Gallium GL hardware evidence across two native AGX3 generations (e.g., G16G/G17P and M5) covering textured vertex/fragment draws withASAHI_MESA_DEBUG=verifyand batch reuse.
Checked:
- Audited full
+34/-6diff (src/gallium/drivers/asahi/agx_batch.c,agx_state.c,agx_state.h):agx_batch_init()cleanly zeroesbatch->g17p_resource_pairfor every new batch.agx_g17p_resource_pair_va()caches{texture_base, samplers} -> vaper stage within the batch, matching the caller's!texture_base || !samplersprecondition inagx_g17p_collect_graphics_uniform_ranges()and handlingagx_pool_upload_aligned()failure (!va) cleanly.
Evidence
- Head commit:
844e9384b7c330c828adb67e22bb5c6f67f740a6(Merge aurora-wip into the HAL200 indirect-draw change,MERGEABLEintoaurora-wip). - Diff vs
aurora-wip:+34/-6acrossagx_batch.c,agx_state.c,agx_state.h.
|
Merged aurora-wip at |
There was a problem hiding this comment.
Verdict: MERGE at 844e9384b7c3
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - Audited full +34/-6 diff (src/gallium/drivers/asahi/agx_batch.c, agx_state.c, agx_state.h):
agx_batch_init()cleanly zeroesbatch->g17p_resource_pairfor every new batch.agx_g17p_resource_pair_va()caches{texture_base, samplers} -> vaper stage within the batch, matching the caller's!texture_base || !samplersprecondition inagx_g17p_collect_graphics_uniform_ranges()and handlingagx_pool_upload_aligned()failure (!va) cleanly.
Follow-ups (not blocking): update title/body to narrowed diff; head build/meson tests + GL row (one gen enough)
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J700 (G17P) row: mesa#619 · J700 MacBook Neo (A18 Pro, G17P B1), stock Fedora 44 7.3.0-41.fc44.aurora.aarch64, same boot, base 8b59f2b vs head 844e938: PASS — mditex (gl43, 4 textured MDI calls/frame with VS texelFetch and texture/sampler rebinds): exact 256×256 image at both grids on both arms; ABBA 1024 draws/call 0.297 → 0.300 ms/frame (+0.9%), 64 draws/call 0.153 → 0.148 ms/frame (-2.8%); 619-gles31 321/321 compared, base 307 Pass / 14 NotSupported → head 307 Pass / 14 NotSupported, 0 status changes; 619-gles3 541/541 compared, base 541 Pass → head 541 Pass, 0 status changes; 0 GPU faults, 0 kernel WARNINGs; stock handback verified. Kit B payload |
|
Row:
|
|
Local check on the merge tree (pc, x86-64 clang, asserts on, Asahi Gallium + Vulkan + drm-shim, every test input rebuilt and a second ninja pass clean): With the review at this head and the J700 (G17P) and J773g (G16G) rows above (0 status changes, 0 GPU faults), this meets the merge bar, so I'm merging it. I retitled it to match the narrowed diff. M3 (G15) is the remaining HAL200 generation and is post-merge verification. |
What: On HAL200, a textured vertex shader uploaded its 16-byte
{texture_base, samplers}pointer pair from the batch pool on every draw. That moved the address-cache range, so the graphics-program template cache missed on every sub-draw of a multi-draw. This caches the pair per stage for the batch, reuses it while both addresses are unchanged, and clears it at batch init. Native indirect recording and batched loaders are already onaurora-wipthrough #802, #1243 and #1308.Tested: Both Gallium objects compile at this head. The Minecraft A/B in the earlier description below measured the full three-commit series on an older base. It hasn't been rerun for this smaller diff. Merge-result CI on current
aurora-wippassed: https://github.com/DjDeveloperr/mesa/tree/ci/head-619-5e991b0e.Risk: two-way door · Gallium on the native HAL200 chips (M3, M4, A18 Pro): textured draws and multi-draw indirect.
Not yet: rows at this head on J773g and J700: GL textured multi-draw indirect, base against head.
Earlier description (three-commit series)
Problem
The Gallium Asahi OpenGL driver advertises
caps->multi_draw_indirect = true, so OpenGL 4.3+ applications (such as Minecraft 26.3's indirect chunk renderer) submit large batches of chunk draws viaglMultiDrawElementsIndirect. However,agx_draw_vbo()previously unconditionally delegated everyindirect->draw_count > 1call toutil_draw_multi_unroll_indirect(), running full per-draw validation (agx_draw_vbo), rebuilding the G17P/HAL200 graphics program from scratch, re-packing VDM state updates and indirect records, and growing the batch's scissor/depth-bias arrays on every sub-draw.On an Apple M4 Mac mini, profiling showed
GL43C.nglMultiDrawElementsIndirectconsuming 37.7–51.5% of render-thread wall time (~3.5–4.1 ms/frame) in user CPU even when all sub-draws shared the same pipeline, textures, samplers, and render state. Additionally, for textured vertex shaders (resource_pair == true, e.g. lightmap sampling),agx_build_g17p_graphics_program()allocated a fresh 16-byte{texture_base, samplers}pointer pair frombatch->poolon every draw, shiftingranges[0]inside thebatch->pooladdress-cache component and causinggraphics_program_shape_equal()to miss the 8-entry template cache on every sub-draw.Change
Three commits cleanly targeting
aurora-wip(fa9a6766c01), gated solely by the native HAL200 graphics capability (agx_native_graphics(dev), with clean fallback toutil_draw_multi_unroll_indirect()on non-native chips,count_from_stream_output, indirect draw counts, and user index pointers — no chip, board, or firmware gates):asahi: add clean-batch fast path for native multi-draw indirect(src/gallium/drivers/asahi/{agx_batch.c,agx_state.{c,h}})agx_draw_multi_indirect()forindirect->draw_count > 1without an indirect draw count on native HAL200 chips.agx_draw_vbo()to establish shaders, descriptors, feedback loops, BO residency, and the HAL200 bind tail.uses_base_paramnoruses_draw_idis active; when active, updates only the per-draw VS parameters and reuses draw 0's cached bind tail and draw-state selector without growing scissor/depth-bias tables. Normalizesstride == 0to tightly packed command sizes (20 B indexed, 16 B non-indexed).asahi: fast-patch VS Ioto program and VDM records in native multi-draw indirect(src/gallium/drivers/asahi/agx_state.c)uses_base_param && !uses_draw_id && !root_reads_params_ptrpath:AGX_SYSVAL_TABLE_PARAMSVA immediate per sub-draw),agx_build_pipeline()/agx_g17p_emit_indirect_draw()on any edge case (short-LDIMM overflow, preamble, unaligned indirect VA).asahi: cache G17P resource pointer pair per batch and guarantee MDI fast-patch(src/gallium/drivers/asahi/{agx_batch.c,agx_state.{c,h}}){texture_base, samplers}pointer pair upload inbatch->g17p_resource_pair[](zeroed on batch init) and reuses it acrossagx_build_g17p_graphics_program()andagx_multidraw_init_vs_patch(), eliminating per-draw template cache thrashing on textured vertex shaders.root_reads_params_ptroverlap checks specifically to[offsetof(struct agx_draw_uniforms, tables[AGX_SYSVAL_TABLE_PARAMS]), +8), and falls back to generating one address-independent.patchable = truetemplate per multi-draw if the MRU template shares an address-cache cluster withPARAMS.Testing
Tested on Apple M4 Mac mini (
Apple M4 (G16G B0)), Arch Linux ARM, kernel7.3.0-ARCH-m4drv8, headless Wayland (kwin_wayland --virtual --width 1920 --height 1080), Minecraft 26.3 (RD 12,Fancy,VSync off,maxFps 260, fixed 50sstill:15,spin:15,fly:20benchmark scene). All timed rows met thermal and load gates (hotspot <= 70 C,load1 < 0.5), with 0 GPU kernel error/fault lines and 0 failed units.Same-Machine A/B Performance (Gallium Asahi Native OpenGL 4.6)
d4ad4a4dceclean-batch)e222fe5e62fast-patchpre-G2)ed1ffa40c45411b98d71(e1ba7c727a/ branch head2c4f7c49405)kstacks.txtverification (render thread, 50s steady window):GL43C.nglMultiDrawElementsIndirectcollapsed ~10x: from 51.2% (~4.09 ms/frame; 10,122/19,764 steady samples) before Commit 3 to 5.2% (~0.40 ms/frame; 1,059/20,506 steady samples) with Commits 1–3.still/spin/flyvs Commits 1–2 (4.58 -> 3.61,5.27 -> 4.19,3.97 -> 3.04 ms/frame).GL32C.nglClientWaitSync(GlCommandEncoder.awaitSubmit) is the agx: introduce agx3b support & HAL200 #1 wall limiter at 49.4% (~3.79 ms/frame; 10,126/20,506 samples), corroborated bykstacks.txt(52.0% sleeping,504/989 = 51.0%indrm_syncobj_array_wait_timeout).Conformance Gates (VK-GL-CTS 1.4.7.1, 0 GPU faults)
gles31-mdi-gate+gl46-mdi-gate(458 cases: draw indirect, multi-draw indirect, base-vertex, base-instance, draw-id)5411b98d71&e1ba7c727a)Driver identities, benchmark settings, and build options
-Dbuildtype=release -Db_ndebug=true),gallium-drivers=asahi,zink,vulkan-drivers=asahi,llvm=disabled,spirv-tools=disabled,glvnd=enabled,clang 23.1.5(aarch64).5411b98d719845ada3db0815b1cc402a72c54103(libgallium-26.3.0-devel.soSHA256:6aa6f5263ca210ac68bc2fc8ab6c7509b2476d457347d5cd8f8e11c14a3f9282)e1ba7c727ae449f818510dad36476177f115bf38(libgallium-26.3.0-devel.soSHA256:49128984b68ef82971dede735ecf67c8a19ad5d0715529f800dddc8010991917)Temurin 25.0.5,-Xms1G -Xmx2560M -XX:+UseZGC -XX:+UseCompactObjectHeaders -XX:+UseStringDeduplication),renderDistance:12,graphicsPreset:"fancy",enableVsync:false,maxFps:260,1920x1080fullscreen on headless KWin Wayland.agx_draw_multi_indirect()and continue throughutil_draw_multi_unroll_indirect(); edge cases (preamble, cluster-sharedPARAMS, short-LDIMM overflow, stream-output count, indirect draw count, user index pointers) fall back cleanly.Still to run
Not yet