Repository navigation
hk/agx3: generalize vertex root-bypass launches and trim draw hot path - #1222
Conversation
Generalize the AGX3 direct-draw vertex root-bypass path so vertex shaders with vertex attributes, dynamic uniform buffer offsets, or vertex buffer base/clamp updates can launch over narrow pool slices or patched buffer addresses without uploading a full root descriptor table or invalidating the HAL200 bind tail whenever the fragment shader cannot observe the dirty root categories. - Track root mutations by category (push constants, dynamic buffer slot mask, VB attrib bases/clamps, other) plus a non-dynbuf descriptor generation in hk_descriptor_state, and classify VS attrib_base/attrib_clamps ranges independently of general root reads. - Allow hk_agx3_try_push_only_vs_program() to pack dirty narrow slices contiguously and cache a bypass loader shape on hk_g17p_launch when the split ranges differ from the full-root cluster plan. - Inline the hot Ioto arena bump path in hk_g17p_gfx_loader_emit(), fast-path hk_cmd_buffer_get_cs() for active graphics streams, defer hk_gfx_republishes_render_state() behind the 65k PPP index-limit guard, skip redundant per-draw shader/stats/attachmentless/resource work when inactive, and short-circuit empty sync footprints and already-compact tilebuffer layouts. - Fix hk_agx3_multi_draw_ioto_prepare() and hk_agx3_emit_indirect_multi() to account for hoisted VS preambles. - Add unit tests covering generalized root-bypass dirty tracking and non_dynbuf_generation behavior. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Verdict at Blockers None. Checked
Merge order with #1144. This conflicts with #1144 in Still owed before merge: the J773g (G16G) second-generation row, which has been requested. The J700 row and CTS (9,329/0) are in the body. |
|
J773g (M4 Mac mini, G16G B0, HAL200, second generation) at Both arms are release Borealis Vulkan overlays built natively on the Mac and loaded from private prefixes through gpubench-vk ABBA (
VK CTS at 1 worker, 67,446 cases: GPU health: 0 faults, 0 recoveries and |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 07910f2fdb96ffccdf243537d874caa1a0f541dc (code approved. The remaining item is a hardware row at this head, see below.)
Blockers: none in the code.
Merge-policy item, not a code finding: both hardware rows (J700 in the body, J773g in the comment) are at 7fb9b541. The head is now the merge 07910f2f. It brings aurora-wip 5ab97d0f into files this PR touches (hk_sync.c +399, hk_cmd_draw.c +235, hk_cmd_buffer.{c,h}) and hand-resolves a conflict in hk_sync_pass_footprints_done(). That is not the clean-rebase exception, so a row at 07910f2f is still owed. A J700 or J773g rerun of the dx11_draws plus draw CTS subset is enough.
Checked:
- Dirty tracking.
- Pure dynamic-offset binds mark only the changed slots (
hk_root_mark_dynbuf_dirty()). - Set address, set start, buffer end, binding changes, set updates, descriptor buffers, embedded samplers, push descriptors and
hk_meta_end()all takehk_root_mark_dirty()and bumpnon_dynbuf_generation. - In VB updates, a stride change takes the full mark, and base or clamp alone take the narrow one.
- A bypassed launch leaves the root dirty (
bypass_launched), so every full-root reader still uploads.
- Pure dynamic-offset binds mark only the changed slots (
- Vertex side of the bypass. Ranges re-derive from current state: SET from
desc->root.sets[], BUFFER throughhk_g17p_dma_buffer()(current dynamic-buffer descriptors, so a dynamic-offset change reaches a VS reading through a DMA span), ATTRIB/PUSH from fresh narrow slices. Only ROOT ranges read the stalegfx->root, and those either passhk_root_reads_ignore_dirty()or are the offset-0 header range fromhk_agx3_g17p_root_range(), which coversroot_desc_addr+sets[set_count]only.- Non-blocking hardening:
hk_g17p_launch_record()exempts an offset-0 ROOT range by offset alone. A root-relative DMA span that starts at 0 is also tagged ROOT. Bounding the exemption tosize <= hk_root_descriptor_offset(draw)would keep a future longer span at offset 0 from slipping through.
- Non-blocking hardening:
- Fragment side and the bind tail. Elision needs
hk_root_bypass_dirty()plushk_root_reads_ignore_dirty()against the FS, the samenon_dynbuf_generation, and for VB-generation skew an FS that reads neither the root address nor vertex input. The debug-build cross-checkhk_g17p_prepared_bind_tail_matches_impl()follows the same rules. - Pipeline switches, indirect draws and secondaries.
hk_g17p_launch_matches()still gates on shader, linked object and flags.- Indirect draws, a VS with a preamble, a hoisted preamble and root growth all fall back to a full upload.
- Secondaries start from fresh descriptor state.
- The multi-draw paths now include the hoisted-preamble flag (32) and
hk_hw_vs_vdm_state_update(hw_vs, hoisted_preamble).
- Hot-path trims, checked for equivalence.
hk_handle_passthrough_gs()already returned unless a VS, GS or TCS/TES dirty bit was set.hk_flush_shaders()does nothing unlessshaders_dirtyor a dynamic dirty bit is set.hk_needs_index_robustness()returns false for non-indexed draws.hk_pipeline_stat_addr()returns the scratch page whenpipeline_stats_flagsis 0. The adjacency range check matches the four*_WITH_ADJACENCYenums, which are contiguous (6..9). The tilebuffer fast path returns the same occupied-slot layout (only unused tail metadata differs, as already noted). - Merge resolution. The
07910f2fearly return clears bothpass_tile_wait[]andpass_tile_wait_frag, which matches #1144's full path for an empty record list. - Tests fail without the fix. I removed the DYNBUF clause from
hk_root_reads_ignore_dirty()on the merged tree, andhk_root_fragmentfails. With it restored, it passes. Non-blocking: as already noted in the thread, droppinghk_root_mark_dynbuf_dirty()fromhk_bind_descriptor_sets()is still not caught by any test. - NO-GATES. No new chip gates. The
agx_chip_native_hal200 || agx_chip_g17_m5andAGX_CHIP_G17Pchecks are pre-existing code that was moved or inlined. - Merge and local gate. The head merges cleanly onto
aurora-wipa97571c6b2839. The drm-shim build of the merge (x86, asahi + poly) passes 338/338, the same as the tip.
Evidence
- Merged tree
fbdde42f=a97571c6+07910f2f: Ok 338, Fail 0. - Mutation (DYNBUF clause removed from
hk_root_reads_ignore_dirty):asahi - mesa:hk_root_fragment FAIL exit status 1. Restored: Ok 1. git show --cc 07910f2f: the only combined hunk ishk_sync.c(st->pass_tile_wait_frag = NULL;in the early return).git diff --stat 7fb9b541^ 5ab97d0fover the PR's files: 5 files, +590/-119.
Summary
Generalize the AGX3 direct-draw vertex root-bypass path so vertex shaders with vertex attributes, dynamic uniform buffer offsets, or vertex buffer base/clamp updates can launch over narrow pool slices or patched buffer addresses without uploading a full
1,112 Broot descriptor table or invalidating the HAL200 bind tail whenever the fragment shader cannot observe the dirty root categories, and trim remaining per-draw CPU recording overhead on Borealis.Key changes
non_dynbuf_generation(hk_cmd_buffer.h,hk_cmd_buffer.c,hk_cmd_meta.c):HK_ROOT_DIRTY_PUSH,DYNBUFwithdynbuf_dirty_mask,VB_BASE,VB_CLAMP,OTHER) and maintainnon_dynbuf_generationso pure dynamic-offset binds do not force full-root invalidation or bind-tail rebuilds when the fragment shader does not read the dirty slots.draw.attrib_baseanddraw.attrib_clampsranges separately (HK_G17P_RANGE_SOURCE_ATTRIB_BASE/ATTRIB_CLAMP) instead ofHK_G17P_RANGE_SOURCE_ROOT, and recognize offset-0ROOTranges that only supplyroot.sets[](!agx3_main_uses_root_uniform && !has_preamble && !g17p_prolog_uses_root).hk_cmd_buffer.c,hk_cmd_draw.c):attrib_base,attrib_clamps,push) contiguously into a singlehk_pool_alloc()(zero pool bytes when onlyDYNBUFchanged) and cache a bypass loader shape onhk_g17p_launchwhen the split cluster shape differs from the initial full-root loader.hk_g17p_flush_dynamic_state_fast,hk_flush_dynamic_state,hk_g17p_emit_native_bind_tail) to elide the bind tail across bypassed push, dynamic-offset, and VB base/clamp updates.hk_cmd_buffer.h,hk_cmd_buffer.c,hk_cmd_draw.c,hk_sync.c,agx_tilebuffer.c):hk_g17p_gfx_loader_emit()and the active graphics stream fast path inhk_cmd_buffer_get_cs().hk_gfx_republishes_render_state()behind the 65k PPP index-limit guard; guard inactive shader/passthrough-GS/index-robustness/pipeline-stat/attachmentless/G17P-resource checks; inline adjacency topology range check; short-circuit empty sync footprints and already-compact tilebuffer layouts.hk_agx3_multi_draw_ioto_prepare()andhk_agx3_emit_indirect_multi()to account for hoisted VS preambles (flags | 32,hk_hw_vs_vdm_state_update(hw_vs, hoisted_preamble)).test-hk-root-fragment.c,hk_cpu_upload_bench.c):hk_root_reads_ignore_dirty(), andnon_dynbuf_generationstability vs invalidation.Verification (MacBook Neo J700, A18 Pro / G17P B1, kernel
7.3.0-41)Exact-head ABBA+BAAB (
6041c9351efvsd16e86fce34, rebased cleanly ontoorigin/aurora-wip29bdd670922->7fb9b541b729):Root uploads (
ASAHI_MESA_DEBUG=perf, 1200 draws)dx11_draws bind=push:1200(1,334,400 B) ->2(2,224 B, -99.8%)dx11_draws bind=dynoff:1200(1,334,400 B) ->20(22,240 B, -98.3%)dx11_draws bind=dynoff_vb:1200(1,334,400 B) ->20(22,240 B, -98.3%)ABBA+BAAB Performance (
us_per_submit&record_cpu_us, 0 CRC mismatches)record_cpu_usrender.dx11_draws push d1render.dx11_draws push d2render.dx11_draws dynoff d1render.dx11_draws dynoff d2render.dx11_draws dynoff_vb d1render.dx11_draws dynoff_vb d2render.dx11_draws progs=4 color d2render.dx11_draws progs=4 shadow d2render.dx11_draws progs=4 shadow_atlas d2render.bindless_ubo ubo_vec4 d2render.bindless_ubo desc_buf d2heavy fill,deferred,postfx,cull_mdi,mdi,heavy geom,light)Correctness & CI
fedora-mesaci.sh 7fb9b541b729):217/0(Ok 217, Fail 0, Timeout 0, Skipped 0).ASAHI_MESA_DEBUG=verifyon J700:0errors across all 10 draw/geometry/TVB workloads.9,329passed,0failed,0warnings (dEQP-VK.draw.renderpass.{linear_interpolation.no_offset_*,basic_draw.draw.*,indirect_draw.indexed.indirect_draw_count.*},dEQP-VK.draw.dynamic_rendering.primary_cmd_buff.basic_draw.*,dEQP-VK.api.command_buffers.record_many_draws_primary_2,dEQP-VK.pipeline.monolithic.vertex_input.*).0kernel faults,0AVC denials,stock.shPRE==POST.