Skip to content
14 changes: 8 additions & 6 deletions src/asahi/lib/agx_chip_caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

/* Compute shaders skip the bottom-up register-pressure scheduler: it
Expand Down Expand Up @@ -193,8 +196,8 @@ 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_MOD3_REG_BANK_RA | \
AGX_CAP_SIGNED_ZERO_MINMAX_SELECT)
AGX_CAP_DESCRIPTOR_BUFFER | AGX_CAP_CACHED_CMD_MEMORY | \
AGX_CAP_MOD3_REG_BANK_RA | AGX_CAP_SIGNED_ZERO_MINMAX_SELECT)

#define AGX_CAPS_G17P \
(AGX_CAPS_NATIVE | AGX_CAP_NATIVE_PREAMBLE | \
Expand All @@ -203,8 +206,7 @@ enum agx_chip_cap {
AGX_CAP_SPARSE_RESIDENCY_3D | AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | \
AGX_CAP_CDM_WAR_WEAK_BARRIER | AGX_CAP_GEN9_2D_COMPRESSION | \
AGX_CAP_HAL200_LOSSLESS_COMPRESSION | \
AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION | AGX_CAP_CDM_OVERLAP_SPLIT | \
AGX_CAP_CACHED_CMD_MEMORY)
AGX_CAP_HAL200_MSAA_COLOR_COMPRESSION | AGX_CAP_CDM_OVERLAP_SPLIT)

/* What the M5 parts (G17G, G17S, G17C) share. */
#define AGX_CAPS_M5 \
Expand Down
16 changes: 16 additions & 0 deletions src/asahi/lib/tests/test-chip-caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,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);
}
}

/* AGX_CAP_COMPUTE_SKIP_PRESSURE_SCHED and AGX_CAP_FOLD_SHARED_OFFSETS are
* enabled on the measured G13 rows (G13G, G13X) only. */
static void
Expand Down Expand Up @@ -299,6 +314,7 @@ main(void)
test_hal200_lossless_compression();
test_hal200_msaa_color_compression();
test_signed_zero_minmax_select();
test_cached_cmd_memory();
test_g13_compute_codegen_caps();

if (failures) {
Expand Down
9 changes: 7 additions & 2 deletions src/asahi/vulkan/hk_cmd_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,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();
}

Expand Down
29 changes: 25 additions & 4 deletions src/asahi/vulkan/tests/hk_cpu_upload_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down