From fdc988ca88d82c8f57cc2104da8c7154edd4fd82 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 26 Nov 2026 19:29:39 +1100 Subject: [PATCH] borealis: share AGX_CAP_CACHED_CMD_MEMORY to G15 and G16G Enable CPU write-back command, USC, root-descriptor, VDM-slab, Ioto-arena, and descriptor-pool allocations (AGX_CAP_CACHED_CMD_MEMORY) on all native AGX3 chips (G15/G16G/G17P) alongside M5, giving G15 and G16G slab span suballocation, cached root reuse, push-descriptor elision, and HAL200 fragment-root snapshot elision: - Clean each patched command-stream word in hk_cmd_buffer_patch_sparse_sites() via util_flush_range_no_fence() when hk_g17p_cached_cmd_memory() is active, matching hk_cmd_buffer_patch_alias_sites(). - Promote AGX_CAP_CACHED_CMD_MEMORY into AGX_CAPS_NATIVE in agx_chip_caps.h (AGX2 stays on write-combined pools after J316s/J413 ABBA showed explicit flush overhead outweighed reuse; G18G stays off). - Add test_cached_cmd_memory() to test-chip-caps.c and extend hk_cpu_upload_bench.c to cover G15G and G16G. Signed-off-by: Ryan Murray --- src/asahi/lib/agx_chip_caps.h | 12 ++++---- src/asahi/lib/tests/test-chip-caps.c | 16 +++++++++++ src/asahi/vulkan/hk_cmd_buffer.c | 9 ++++-- src/asahi/vulkan/tests/hk_cpu_upload_bench.c | 29 +++++++++++++++++--- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/asahi/lib/agx_chip_caps.h b/src/asahi/lib/agx_chip_caps.h index 19202d2548a4..a6e2f9532d19 100644 --- a/src/asahi/lib/agx_chip_caps.h +++ b/src/asahi/lib/agx_chip_caps.h @@ -160,8 +160,11 @@ enum agx_chip_cap { /* Command-buffer, root-descriptor, VDM-slab, Ioto-arena, and descriptor-pool * BOs are mapped CPU write-back (AGX_BO_WRITEBACK) when util_has_cache_ops() * is available, cleaned before GPU submission, enabling CPU-cached root - * reuse, push-descriptor elision, and direct fragment-root comparisons - * without shadow snapshots. Qualified on G17P and M5 (G17G, G17S, G17C). */ + * reuse, push-descriptor elision, slab span suballocation, and direct + * fragment-root comparisons without shadow snapshots. Qualified on native + * AGX3 (G15/G16G/G17P) and M5 (G17G/G17S/G17C); AGX2 keeps write-combined + * command pools because explicit cache-clean overhead outweighed reuse on + * J316s/J413 gpubench-vk ABBA. */ AGX_CAP_CACHED_CMD_MEMORY = 1u << 22, }; @@ -174,7 +177,7 @@ enum agx_chip_cap { #define AGX_CAPS_NATIVE \ (AGX_CAP_NATIVE_INDIRECT_COMPUTE | AGX_CAP_NATIVE_IMAGEBLOCK | \ AGX_CAP_ELIDE_APP_DISPATCH_BARRIER | AGX_CAP_COOPERATIVE_MATRIX | \ - AGX_CAP_DESCRIPTOR_BUFFER) + AGX_CAP_DESCRIPTOR_BUFFER | AGX_CAP_CACHED_CMD_MEMORY) #define AGX_CAPS_G17P \ (AGX_CAPS_NATIVE | AGX_CAP_NATIVE_PREAMBLE | \ @@ -184,8 +187,7 @@ enum agx_chip_cap { AGX_CAP_CDM_WAR_WEAK_BARRIER | AGX_CAP_GEN9_2D_COMPRESSION | \ AGX_CAP_MOD3_REG_BANK_RA | AGX_CAP_HAL200_LOSSLESS_COMPRESSION | \ AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION | \ - AGX_CAP_SIGNED_ZERO_MINMAX_SELECT | AGX_CAP_CDM_OVERLAP_SPLIT | \ - AGX_CAP_CACHED_CMD_MEMORY) + AGX_CAP_SIGNED_ZERO_MINMAX_SELECT | AGX_CAP_CDM_OVERLAP_SPLIT) /* What the M5 parts (G17G, G17S, G17C) share. */ #define AGX_CAPS_M5 \ diff --git a/src/asahi/lib/tests/test-chip-caps.c b/src/asahi/lib/tests/test-chip-caps.c index a3d6522ab24d..0194246dc3bd 100644 --- a/src/asahi/lib/tests/test-chip-caps.c +++ b/src/asahi/lib/tests/test-chip-caps.c @@ -262,6 +262,21 @@ test_signed_zero_minmax_select(void) } } +/* AGX_CAP_CACHED_CMD_MEMORY is enabled across native AGX3 and M5; AGX2 keeps + * write-combined pools, and G18G/unadmitted chips keep it off until qualified. */ +static void +test_cached_cmd_memory(void) +{ + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + const bool expected = + c == AGX_CHIP_G15G || c == AGX_CHIP_G15S || c == AGX_CHIP_G15C || + c == AGX_CHIP_G16G || c == AGX_CHIP_G17P || c == AGX_CHIP_G17G || + c == AGX_CHIP_G17S || c == AGX_CHIP_G17C; + CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_CACHED_CMD_MEMORY) == expected, c); + } +} + int main(void) { @@ -278,6 +293,7 @@ main(void) test_hal200_lossless_compression(); test_hal200_msaa_color_compression(); test_signed_zero_minmax_select(); + test_cached_cmd_memory(); if (failures) { fprintf(stderr, "agx_chip_caps: %u of %u checks failed\n", failures, diff --git a/src/asahi/vulkan/hk_cmd_buffer.c b/src/asahi/vulkan/hk_cmd_buffer.c index 1cfa5c2f5dfd..c4c9e8b6069e 100644 --- a/src/asahi/vulkan/hk_cmd_buffer.c +++ b/src/asahi/vulkan/hk_cmd_buffer.c @@ -372,11 +372,16 @@ hk_cdm_note_sparse_site(struct hk_cs *cs, uint32_t *word) static void hk_cmd_buffer_patch_sparse_sites(struct hk_cmd_buffer *cmd) { - util_dynarray_foreach(&cmd->sparse_sites, struct hk_sparse_site, site) + const bool cpu_cached = + hk_g17p_cached_cmd_memory(&hk_cmd_buffer_device(cmd)->dev); + util_dynarray_foreach(&cmd->sparse_sites, struct hk_sparse_site, site) { __atomic_store_n(site->word, site->value, __ATOMIC_RELAXED); + if (cpu_cached) + util_flush_range_no_fence(site->word, sizeof(*site->word)); + } __sync_synchronize(); - if (util_has_cache_ops()) + if (cpu_cached || util_has_cache_ops()) util_post_flush_fence(); } diff --git a/src/asahi/vulkan/tests/hk_cpu_upload_bench.c b/src/asahi/vulkan/tests/hk_cpu_upload_bench.c index 4b61d001dc93..485038100a81 100644 --- a/src/asahi/vulkan/tests/hk_cpu_upload_bench.c +++ b/src/asahi/vulkan/tests/hk_cpu_upload_bench.c @@ -1936,10 +1936,11 @@ cached_root_snapshot_elision_correctness(struct fixture *f) const enum agx_chip saved_chip = f->dev.dev.chip; const unsigned saved_debug = f->dev.dev.debug; - /* G17P and M5 use the CPU-cached HK_CMD_BO_ROOT pool: identical roots reuse - * without a new allocation, and root_fragment_snapshot_publish() is skipped - * unless AGX_DBG_VERIFY is set. */ - const enum agx_chip cached_chips[] = {AGX_CHIP_G17P, AGX_CHIP_G17C}; + /* HAL200 (G16G, G17P) and M5 use the CPU-cached HK_CMD_BO_ROOT pool: + * identical roots reuse without a new allocation, and + * root_fragment_snapshot_publish() is skipped unless AGX_DBG_VERIFY is set. */ + const enum agx_chip cached_chips[] = {AGX_CHIP_G16G, AGX_CHIP_G17P, + AGX_CHIP_G17C}; for (unsigned i = 0; i < ARRAY_SIZE(cached_chips); ++i) { reset(f); f->dev.dev.chip = cached_chips[i]; @@ -1976,6 +1977,26 @@ cached_root_snapshot_elision_correctness(struct fixture *f) cmd->state.gfx.root_cpu); } + /* G15 also uses CPU-cached HK_CMD_BO_ROOT and reuses identical roots + * without a new allocation. */ + const enum agx_chip shared_cached_chips[] = {AGX_CHIP_G15G}; + for (unsigned i = 0; i < ARRAY_SIZE(shared_cached_chips); ++i) { + reset(f); + f->dev.dev.chip = shared_cached_chips[i]; + f->dev.dev.debug = 0; + cmd->uploader.root.cpu_cached = true; + + desc->root.sets[0] = 0x30000 + i * 0x100; + const uint64_t r1 = + hk_cmd_buffer_upload_root(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); + CHECK(r1 != 0); + CHECK(desc->uploaded_root_cpu_cached); + CHECK(cmd->state.gfx.root_cpu_cached); + const uint64_t r2 = + hk_cmd_buffer_upload_root(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS); + CHECK(r2 == r1); + } + /* Uncached (WC) roots must never reuse via memcmp readback and must retain * the CPU shadow snapshot on HAL200/M5. */ reset(f);