Repository navigation
asahi: elide unchanged HAL200 bind tails and add indirect multi-draw fast path - #802
Conversation
|
Verified exact head
Assisted-by: LLM (Gemini:4 Neon) |
RyanTheTide
left a comment
There was a problem hiding this comment.
FOLLOW-UP · source review of 7a284702cec1
The fast encoder and the per-draw fallback calculate the indirect argument address differently. The fast path widens i before multiplying by stride, while the fallback aggregates i * indirect->stride into the subdraw offset. Please make the fallback's width and range checks explicit before the multiply and test the last draw and a forced fallback after a stream link. The 12,288-draw case covers relatching with a small stride.
Verification here was by source inspection.
G17S B1 (
|
|
Rebased cleanly (
Assert-ON host CI on exact head |
On native AGX3 (HAL200), agx_encode_state() previously emitted a full PPP bind tail and draw-state selector on every dirty draw, even when only vertex uniforms or vertex buffer bindings changed. Clean indirect draws also emitted a redundant bind tail and selector. Track the latched HAL200 bind tail and vertex-shader metadata per VDM chunk on agx_batch, resetting them on batch init and whenever a VDM STREAM_LINK starts a new chunk. When only AGX_DIRTY_VS or AGX_DIRTY_VERTEX is dirty and the current chunk already latched the same fragment program, PPP state, and vertex metadata, emit only the VDM_STATE_UPDATE and omit the bind tail and draw-state selector. Also teach agx_g17p_emit_indirect_draw() to omit the leading selector via agx_vdm_hal200_draw_emit() when draw_state_offset is zero, matching Borealis and asahi_g17p_stream_validator, and drop the clean-indirect bind-tail workaround in agx_draw_vbo(). Extend test-agx-vs-query to cover VS-only bind-tail elision, VDM STREAM_LINK re-latching, and selectorless clean indirect draws under ASAHI_SHIM_VALIDATE_G17P_STREAM=1. Signed-off-by: Diljit Singh <hey@djdev.me>
On native AGX3 (HAL200), glMultiDraw*Indirect previously fell back to util_draw_multi_unroll_indirect(), running full agx_draw_vbo() state validation, BO registration, and 560-byte root uniform uploads for every sub-draw. Factor uniform-range collection out of agx_build_g17p_graphics_program() and add agx_draw_multi_indirect() for native AGX3 indirect multi-draws: - Run draw 0 through full agx_draw_vbo() to validate state, legalize feedback loops, register the indirect and index buffers, and latch the HAL200 bind tail. - For draws 1..N-1 when neither gl_DrawID nor base parameters vary, emit only the selectorless indirect draw body. - When gl_DrawID or base parameters vary, pre-fill contiguous chunks of draw_id push slices isolated more than INT16_MAX bytes from other uniform ranges so draw_id stays in its own Ioto address-cache component (preventing template cache thrashing against static pool tables), relocate the cached Ioto VS template via agx_g17p_graphics_program_cached(), emit the 24-byte VDM_STATE_UPDATE without a bind tail (re-latching only after a 64 KiB VDM STREAM_LINK), and emit the indirect draw. Extend test-agx-vs-query with state-clean and gl_DrawID + base-param + vertex-attribute indirect multi-draw tests crossing a VDM STREAM_LINK boundary under ASAHI_SHIM_VALIDATE_G17P_STREAM=1 and verifying Ioto template cache reuse. Signed-off-by: Diljit Singh <hey@djdev.me>
…ck tests Unify indirect sub-draw offset calculation between the HAL200 fast path and per-draw fallback in agx_draw_multi_indirect() via a shared agx_mdi_subdraw_offset() helper that widens to uint64_t and validates alignment, uint32_t width (pipe_draw_indirect_info::offset), and buffer bounds (indirect->buffer->width0) before multiplying draw_index * stride. Bound the valid draw prefix and base-parameter address span by the same in-range limit, and defer ctx->perf.vs_emits accounting until bind-tail re-latching succeeds so an aborted fast-path emit cannot double-count. Extend test-agx-vs-query to cover: - agx_mdi_subdraw_offset() boundary, alignment, 32-bit multiply wraparound, and 32-bit addition overflow guards; - unpacking and verifying the last draw's indirect buffer VA, draw_id, and params table on both small-stride and large-stride non-zero-offset paths; - a forced per-draw fallback starting in an unlatched post-STREAM_LINK chunk and crossing another VDM STREAM_LINK under ASAHI_SHIM_VALIDATE_G17P_STREAM=1; - a mid-MDI fast-path -> STREAM_LINK -> flush fallback -> fast-path recovery through the last draw; and - runtime overflow and out-of-range clipping on both fast and fallback paths. Signed-off-by: Diljit Singh <hey@djdev.me>
7a28470 to
591107e
Compare
|
Pushed exact head |
satchlj
left a comment
There was a problem hiding this comment.
Verdict at 591107ed1eb0
APPROVE — Clean HAL200 bind-tail elision and indirect multi-draw fast path, resolving both issues from the earlier split (#701): the separate OOM-prone patch-plan helper is replaced by direct agx_g17p_graphics_program_cached() calls with isolated draw_id chunk placement (agx_mdi_isolated_va() / agx_mdi_alloc_draw_id_chunk()) and safe per-draw fallback on failure, and agx_g17p_emit_indirect_draw() documents and strips the unused draw-state selector cleanly when no fresh bind tail is emitted.
Blockers
None.
Checked
- Reviewed all 5 changed files (
src/asahi/lib/agx_linker.h,src/gallium/drivers/asahi/agx_batch.c,src/gallium/drivers/asahi/agx_state.c,src/gallium/drivers/asahi/agx_state.h,src/gallium/drivers/asahi/tests/test-agx-vs-query.c):- Verified HAL200 bind-tail elision (
need_bind_tailinagx_encode_state()andg17p_bind_tail_latched/g17p_have_latched_vsresets acrossAGX_VDM_RECORD_STREAM_LINKinagx_ensure_cmdbuf_has_space()and batch init) againstasahi_g17p_stream_validator.c. - Verified
agx_mdi_subdraw_offset()overflow/alignment/bounds checks,agx_g17p_collect_graphics_uniform_ranges()tracking (single fixed-ABIAGX_SYSVAL_TABLE_PARAMSrange at offset 0 with fail-closed fallback on multiple ranges,AGX_SYSVAL_TABLE_ROOTindirect-root detection),agx_mdi_isolated_va()/agx_mdi_alloc_draw_id_chunk()fallback on allocation failure, andagx_draw_multi_indirect()re-latching onSTREAM_LINKwhenneeds_vs_updateemits a freshVDM_STATE_UPDATE. - Verified
test-agx-vs-query.ccoverage for bind-tail elision,agx_mdi_subdraw_offset()bounds/overflow, and 1,600-draw MDI withSTREAM_LINKre-latching and template reuse.
- Verified HAL200 bind-tail elision (
- Verified isolated Gallium + EGL + drm-shim build and full non-layout
asahiunit/drm-shim suite (167/167PASS, includingasahi-g17p-gallium-vs,asahi-t6041-gallium-vs,asahi-g17p-gallium-blit,asahi-g17p-gallium-submit, andagx_tests). - Verified live Apple M5 Max (
G17C B1,git-591107ed1e, Linux 7.3,MESA_SHADER_CACHE_DISABLE=1,0GPU faults) Gallium GLES31draw_indirectCTS (204/204supported PASS). - Untested scope:
asahi_layout_tests/agx3_layout(excluded due to pre-existing GCC 16 designated-initializer build issue insrc/asahi/layout/tests/test-layout.cpp); G17P hardware execution beyondasahi-g17p-gallium-vs/asahi-t6041-gallium-vsdrm-shim stream validation and live M5 Max Gallium GLES31draw_indirectCTS.
Evidence
- Unit & drm-shim tests (
meson test --no-rebuild):167/167non-layoutasahitests PASS (asahi-g17p-gallium-vsOK,asahi-t6041-gallium-vsOK,agx_testsOK). - Live Apple M5 Max Gallium GLES31 CTS (
OpenGL ES 3.2 Mesa 26.3.0-devel (git-591107ed1e),MESA_SHADER_CACHE_DISABLE=1,0GPU faults):dEQP-GLES31.info.version:1/1PASSdEQP-GLES31.functional.draw_indirect.*:203/203PASS (18NotSupported)
|
Merged into Gates verified at exact head
|
The revert of #822 kept #896 (inter-submission barrier elision for disjoint AGX3 batches, merge commit ba9bcc7), but #896 is built on #822's written-BO list and per-batch submission state, so the driver no longer compiled. Revert #896 as well, in the order a clean revert takes: #896 first, then #822. Two later users of #822 are adapted rather than reverted: - #802 (HAL200 bind elision for multi-draw indirect) noted the indirect buffer as a vertex-stage read for #822's render barrier tracking. That tracking is gone; the indirect buffer is still recorded as a batch read. - #745 (fast-clear batches) also checked #822's primitive counters. Its draw checks remain. #754's agx_resource_set_valid() and #745's change to always write the compute end timestamp are kept. Two test changes keep later tests meaningful without #822: - #822's guard in the threaded-context test that skips comparing a compressed level is kept. That level uploads and reads back through GPU blits, which the no-op drm-shim never runs. - The #802 multi-draw test checked that a forced flush started a new batch by comparing batch pointers. Without #822 the flushed batch is submitted at once and its slot can be reused, so it compares the batch sequence number instead. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
What: Elide unchanged HAL200 bind tails and indirect draw selectors, and add a native AGX3
glMultiDraw*Indirectfast path in Gallium Asahi (agx_draw_multi_indirect()), avoidingutil_draw_multi_unroll_indirect()and Ioto template-cache thrashing across draw-ID updates.Tested:
--suite asahi,--suite poly, plusASAHI_SHIM_VALIDATE_G17P_STREAM=1): 184/184 Pass (0Fail) on exact head591107ed1eb0(including extendedtest-agx-vs-querycoverage for last-draw bounds, forced post-STREAM_LINKfallback, mid-MDI fallback recovery, and offset overflow clipping).G17P B1), Mac mini (G16G B0), and MacBook Pro (G17S B1) acrossgpubench-gl --verifyand GLES/GL CTS with zero GPU faults (render.draws mode=mdi draws=40962.56x-2.82x faster,direct draws=40961.44x faster on G17P).Risk: two-way · G16G (M4), G17P (A18 Pro / MacBook Neo), G17S (M5 Pro). Gated on
agx_chip_native_agx3(); falls back cleanly to per-drawagx_draw_vbo()on any unsupported indirect layout, bounds overflow, or post-STREAM_LINKre-latch failure.Not yet: None.
Details
asahi: elide unchanged HAL200 bind tails and indirect draw selectors(764dfa2db69a)agx_batch(reset on batch init and whenever a VDMSTREAM_LINKstarts a new chunk).AGX_DIRTY_VSorAGX_DIRTY_VERTEXis dirty and the current chunk already latched the same fragment program, PPP state, and vertex metadata, emit only the 24-byteVDM_STATE_UPDATEand omit the redundant PPP bind tail and draw-state selector.agx_g17p_emit_indirect_draw()to omit the leading draw-state selector viaagx_vdm_hal200_draw_emit()whendraw_state_offset == 0, and remove the clean-indirect bind-tail workaround inagx_draw_vbo().asahi: add HAL200 fast path for indirect multi-draw(27037254760a)agx_build_g17p_graphics_program()and addagx_draw_multi_indirect()for native AGX3 (agx_chip_native_agx3)glMultiDraw*Indirectcalls.agx_draw_vbo()to validate state, legalize feedback loops, register buffers, and latch the HAL200 bind tail.1..N-1, emit selectorless indirect draw bodies directly when neithergl_DrawIDnor base parameters vary; when they vary, pre-fill contiguous chunks ofdraw_idpush slices isolated> INT16_MAXbytes from other uniform ranges sodraw_idstays in its own Ioto address-cache component, relocate the cached Ioto VS template viaagx_g17p_graphics_program_cached(), and emit the 24-byteVDM_STATE_UPDATE(re-latching across 64 KiB VDMSTREAM_LINKboundaries).asahi: unify MDI indirect offset checks and extend STREAM_LINK fallback tests(591107ed1eb0)agx_mdi_subdraw_offset()with explicit 64-bit widening, alignment, stride/width, and indirect buffer bounds checks before multiplying.batch->vs_emitsadvancement until post-STREAM_LINKre-latch succeeds.test-agx-vs-queryto cover the last draw, forced fallback after aSTREAM_LINK, mid-MDI fallback recovery, and offset-overflow clipping.Evidence
Offline Assert CI (exact head
591107ed1eb0)--suite asahi+--suite poly+ASAHI_SHIM_VALIDATE_G17P_STREAM=1: 184/184 Pass (0Fail).Hardware Verification — MacBook Neo (
G17P B1, 6-round alternating cool-down ABBA,gpubench-gl --verify)Base -> Head)render.draws mode=mdi draws=4096render.draws mode=mdi draws=4096render.draws mode=mdi draws=1024render.draws mode=mdi draws=1024render.draws mode=direct draws=4096Cross-verified on Apple M4 (
G16G B0) and Apple M5 Pro (G17S B1) in comments below.