From abaafa16af8a9c23503d1018b6982cf6390e3a5a Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:01:41 -0300 Subject: [PATCH 01/13] agx: pin every chip predicate and record allowlist in a truth table The chip tables are about to move into one row per chip. Before that, record what the code answers today: tests/test-chip.c gets one row for every chip predicate and table accessor in agx_chip.h and agx_chip.c and for every per-record allowlist in lib/*_core.[ch] and genxml/agx3_cmdstream.h, with its value for all 19 chips and AGX_CHIP_UNKNOWN. A value outside the enum must answer as UNKNOWN does. The expected strings were printed by this code, at aurora-wip 7ba295723, and not written by hand. The rows show where today's lists disagree, which the refactor has to keep: - agx_isa_is_agx3 is false for AGX3D, agx_encoding_is_agx3 is true. - The VDM stream link, tessellate and direct Index List records, the CDM stream link, link padding and substream barrier, and the Ioto target and profile control refuse G18G. The VDM stream terminate, barrier, PPP state and vertex pipeline pair and the CDM launches and barrier accept it. - agx_chip_hal300_records is G17G and G18G; agx_chip_g17_m5 is G17G, G17S and G17C. Three things outside agx_chip.[ch] that the series also rewrites get rows: - The chip the command-stream decoder takes a kernel identity as. decode.c has its own mapping: it has no cluster-count check, and it takes variant 'X' with chip id 0x6041 on the G17 runtime as G17P, which device open refuses. agxdecode_chip_from_params() is declared in decode.h so the test can call it, and test_decoder_identity() checks every identity, the M4 Pro and M4 Max ones and the 'X' cases against both mappings. - The shader binary version hk_shader_binary_version() gives a chip, as one of its three classes. test-hk-execution-allowance.c already asserts it for the 19 chips, but not for AGX_CHIP_UNKNOWN, and a release build compiles its asserts out. - The Ioto encoding the preshader, state and program codecs select. Their selectors are static, so the rows read it from what each codec packs or accepts. The test now links libasahi_lib, which holds the record cores. The checks that only restated single cells of the table are gone from test-chip.c and test-chip.cpp. The kernel identity mapping, the per-SoC parameter contracts and the G16G compute launch bytes stay, and so does test-chip-admission.c. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. This is CPU-only code; no other machine has run it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/lib/decode.c | 2 +- src/asahi/lib/decode.h | 6 + src/asahi/lib/meson.build | 9 +- src/asahi/lib/tests/test-chip.c | 607 ++++++++++++++++++++---------- src/asahi/lib/tests/test-chip.cpp | 46 --- 5 files changed, 413 insertions(+), 257 deletions(-) diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index b1668789949f..8936a5afdf7a 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -185,7 +185,7 @@ typedef struct drm_asahi_params_global decoder_params; * (G17G/AGX3c), and must never be used as an architecture proxy. This local * form avoids making the standalone decoder library depend on libasahi_lib; * agx_chip_from_params() is the equivalent device-open mapping. */ -static enum agx_chip +enum agx_chip agxdecode_chip_from_params(const decoder_params *params) { if (!params) diff --git a/src/asahi/lib/decode.h b/src/asahi/lib/decode.h index c7b43a33f859..b66d3b302f94 100644 --- a/src/asahi/lib/decode.h +++ b/src/asahi/lib/decode.h @@ -9,6 +9,7 @@ #include #include "agx_bo.h" +#include "agx_chip.h" #include "drm-uapi/asahi_drm.h" @@ -18,6 +19,11 @@ struct agxdecode_ctx *agxdecode_new_context(uint64_t shader_base); void agxdecode_destroy_context(struct agxdecode_ctx *ctx); +/* The chip the decoder takes a trace's kernel parameters as. NULL is + * unknown. Declared for tests/test-chip.c. */ +enum agx_chip +agxdecode_chip_from_params(const struct drm_asahi_params_global *params); + void agxdecode_next_frame(void); void agxdecode_close(void); diff --git a/src/asahi/lib/meson.build b/src/asahi/lib/meson.build index fa488114e908..9f910bd7e391 100644 --- a/src/asahi/lib/meson.build +++ b/src/asahi/lib/meson.build @@ -255,11 +255,12 @@ if with_tests 'asahi-agx-chip', executable( 'asahi-agx-chip', - files( - 'agx_chip.c', - 'tests/test-chip.c', - ), + files('tests/test-chip.c'), include_directories : [inc_include, inc_src, inc_asahi], + dependencies : [idep_agx_pack, idep_mesautil], + link_with : [libasahi_lib], + c_args : [c_msvc_compat_args], + gnu_symbol_visibility : 'hidden', ), suite : ['asahi'], ) diff --git a/src/asahi/lib/tests/test-chip.c b/src/asahi/lib/tests/test-chip.c index c18e5d318e8f..5d905597841d 100644 --- a/src/asahi/lib/tests/test-chip.c +++ b/src/asahi/lib/tests/test-chip.c @@ -9,6 +9,31 @@ #include #include +#include "asahi/genxml/agx3_cmdstream.h" +#include "asahi/vulkan/hk_agx3_vdm_decode.h" +#include "agx3_cdm_direct_launch_semantic_core.h" +#include "agx3_compute_program_core.h" +#include "agx_ioto_core.h" +#include "agx_ioto_load_core.h" +#include "agx_ioto_preshader_core.h" +#include "agx_ioto_profile_core.h" +#include "agx_ioto_program_core.h" +#include "agx_ioto_state_core.h" +#include "agx_ppp.h" +#include "agx_ppp_hal200_graphics_core.h" +#include "agx_ppp_hal300_depth_bias_scissor_core.h" +#include "agx_ppp_hal300_depth_stencil_core.h" +#include "agx_ppp_viewport_payload_core.h" +#include "agx_vdm_barrier_core.h" +#include "agx_vdm_index_list_core.h" +#include "agx_vdm_ppp_state_core.h" +#include "agx_vdm_state_core.h" +#include "agx_vdm_state_update_core.h" +#include "agx_vdm_stream_link_core.h" +#include "agx_vdm_stream_terminate_core.h" +#include "agx_vdm_tessellate_core.h" +#include "decode.h" + _Static_assert(sizeof(struct drm_asahi_params_global) == 616, "drm_asahi_params_global ABI"); _Static_assert(offsetof(struct drm_asahi_params_global, usc_generation) == 592, @@ -48,68 +73,375 @@ static unsigned checks; } \ } while (0) -struct chip_case { +/* + * The truth table: what every chip predicate, table accessor and per-record + * allowlist answers for every enum agx_chip value. It pins behaviour, so a + * refactor of the chip tables must leave it passing unedited; a row changes + * only together with the hardware evidence for the new answer. + * + * Each row is an expression of `c` and its value for the twenty identities in + * enum order, one base-36 digit each, grouped by generation: + * + * G13G G13X G14G G14X | G15P G15G G15S G15C G15D | G16P G16G G16S G16C | + * G17P G17A G17G G17S G17C | G18G | UNKNOWN + * + * A failing row prints the string the code produces. + */ +#define TRUTH_TABLE(ROW) \ + /* Identity and generation axes. */ \ + ROW(agx_chip_isa(c), "2222 23333 3333 33333 3 0") \ + ROW(agx_chip_isa_encoding(c), "0000 01111 1111 11222 3 4") \ + ROW(agx_chip_command_stream_generation(c), "0000 41111 2222 22333 3 4") \ + ROW(agx_chip_descriptor_generation(c), "7788 09999 9999 99aaa a 0") \ + ROW(agx_chip_sampler_generation(c), "0000 30000 1111 11222 2 3") \ + ROW(agx_chip_sampler_heap_element_size(c) / 8, "1111 04444 4444 44444 4 0") \ + ROW(agx_chip_submission_model(c), "0000 30000 3011 13222 2 3") \ + ROW(agx_chip_record_family(c), "0123 4ddd8 9dbc defgh i j") \ + ROW(agx_encoding_is_agx3(agx_chip_isa_encoding(c)), \ + "0000 01111 1111 11111 1 0") \ + ROW(agx_isa_is_agx3(agx_chip_isa_encoding(c)), "0000 01111 1111 11111 0 0") \ + ROW(agx_encoding_is_g17_class(agx_chip_isa_encoding(c)), \ + "0000 00000 0000 00111 1 0") \ + /* Paths. */ \ + ROW(agx_chip_native_agx3(c), "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_native_g15(c), "0000 01110 0000 00000 0 0") \ + ROW(agx_chip_g17_m5(c), "0000 00000 0000 00111 0 0") \ + ROW(agx_chip_hal300_records(c), "0000 00000 0000 00100 1 0") \ + ROW(agx_chip_m5_paths(c), "0000 00000 0000 00100 1 0") \ + ROW(agx_chip_codegen_supported(c), "1111 11111 1111 11111 0 0") \ + ROW(agx_chip_driver_supported(c), "1111 01110 0100 10000 0 0") \ + ROW(agx_chip_uses_legacy_precompiled_programs(c), \ + "1111 00000 0000 00000 0 0") \ + /* Capabilities and quirks. */ \ + ROW(agx_chip_has_native_render_context(c), "0000 00000 0000 10000 0 0") \ + ROW(agx_chip_native_indirect_compute(c), "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_indirect_geometry_flush(c), "0000 01110 0000 00000 0 0") \ + ROW(agx_chip_cdm_wide_visibility(c), "0000 01110 0000 00000 0 0") \ + ROW(agx_chip_elide_app_dispatch_barrier(c), "0000 01110 0100 10111 0 0") \ + ROW(agx_chip_usc_helper_table_slots(c, 0), "aaaa aaaaa aaaa 6aaaa a a") \ + ROW(agx_chip_usc_helper_table_slots(c, 6), "aaaa aaaaa aaaa 6aaaa a a") \ + ROW(agx_chip_usc_helper_table_slots(c, 10), "aaaa aaaaa aaaa aaaaa a a") \ + ROW(agx_chip_usc_base_page_fill_returns(c), "0000 00010 0000 00000 0 0") \ + ROW(agx_chip_usc_base_page_fill_returns_for(c, 1), \ + "0000 00010 0000 00000 0 0") \ + ROW(agx_chip_usc_base_page_fill_returns_for(c, 2), \ + "0000 00010 0000 00000 0 0") \ + ROW(agx_chip_usc_base_page_fill_returns_for(c, 4), \ + "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_explicit_robust_image_bounds(c), "0000 01110 0100 00000 0 0") \ + ROW(agx_chip_native_imageblock(c), "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_defect(c), "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x8140, 2), \ + "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x8140, 4), \ + "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x6040, 2), \ + "0000 01110 0100 00000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x6040, 4), \ + "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x6041, 2), \ + "0000 01110 0100 00000 0 0") \ + ROW(agx_chip_uncovered_tile_ms_reload_defect(c, 0x6041, 4), \ + "0000 01110 0100 10000 0 0") \ + ROW(agx_chip_tri_merge_across_side_effects(c), "0000 00000 0000 10000 0 0") \ + ROW(agx_chip_image_load_misses_own_store(c), "0000 00000 0000 10000 0 0") \ + ROW(agx_chip_exact_fma32(c), "1111 10001 1011 11111 1 1") \ + ROW(agx_chip_sampler_has_lod_bias(c), "0000 00000 1111 11000 0 0") \ + ROW(agx_chip_native_preamble(c), "0000 00000 0000 10000 0 0") \ + ROW(agx_chip_query_ti_spill(c), "0000 00000 0000 10000 0 0") \ + ROW(agx_chip_has_hardware_ray_tracing(c), "0000 01111 1111 11111 1 0") \ + ROW(agx_chip_needs_scheduling_stalls(c), "0000 01000 0000 00000 0 0") \ + ROW(agx_chip_cooperative_matrix_supported(c), "0000 01111 1111 11111 0 0") \ + /* Per-record allowlists: VDM. */ \ + ROW(agx_vdm_state_vertex_pipeline_pair_supported(c), \ + "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_state_update_supported(c), "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_ppp_state_core_supported(c), "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_barrier_core_supported(c), "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_barrier_core_word(c, false) == AGX_VDM_BARRIER_CORE_PLAIN, \ + "0000 00110 0100 00000 0 0") \ + ROW(agx_vdm_stream_link_core_supported(c), "0000 01111 0111 10111 0 0") \ + ROW(agx_vdm_stream_terminate_core_supported(c), \ + "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_tessellate_direct_target_supported(c), \ + "0000 01111 0111 10111 0 0") \ + ROW(agx_vdm_index_list_direct_target_supported_inline(c), \ + "0000 01111 0111 10111 0 0") \ + ROW(agx_vdm_index_list_direct_is_hal300_inline(c), \ + "0000 00000 0000 00111 0 0") \ + ROW(agx_vdm_index_list_record_chip(c), "0123 45678 9abc defgh f j") \ + ROW(agx_vdm_index_list_indexed_or_indirect_supported_inline(c), \ + "0000 01111 0111 10111 1 0") \ + ROW(agx_vdm_index_list_nonindexed_has_tail(c), "0000 00000 0000 00111 1 0") \ + ROW(agx_vdm_index_list_hal300_unk2(c, 12), "7777 77777 7777 77777 5 7") \ + /* Per-record allowlists: PPP. */ \ + ROW(agx_ppp_legacy_payload_supported(c), "1111 01111 0111 10000 0 0") \ + ROW(agx_ppp_hal200_graphics_core_supported(c), "0000 01110 0100 10000 0 0") \ + ROW(agx_ppp_hal300_depth_stencil_core_supported(c), \ + "0000 00000 0000 00111 1 0") \ + ROW(agx_ppp_hal300_depth_bias_scissor_core_supported(c), \ + "0000 00000 0000 00111 1 0") \ + ROW(agx_ppp_viewport_payload_core_supported(c), \ + "0000 01111 0111 10111 1 0") \ + /* Per-record allowlists: CDM. */ \ + ROW(agx3_cdm_launch_target_grounded(c), "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_direct_launch_target_grounded(c), "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_indirect_launch_target_grounded(c), \ + "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_indirect_launch_36_target_grounded(c), \ + "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_stream_link_target_grounded(c), "0000 01111 0111 10111 0 0") \ + ROW(agx3_cdm_link_padding_target_grounded(c), "0000 01111 0111 10111 0 0") \ + ROW(agx3_cdm_barrier_target_grounded(c), "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_barrier_flags_grounded(c, 0), "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_barrier_flags_grounded(c, 1), "0000 00000 0000 00111 0 0") \ + ROW(agx3_cdm_barrier_flags_grounded(c, 5), "0000 01111 0111 10111 1 0") \ + ROW(agx3_cdm_barrier_flags_grounded(c, 0xf), "0000 00000 0000 00111 0 0") \ + ROW(agx3_cdm_barrier_flags_grounded(c, 0x10), "0000 00000 0000 00000 0 0") \ + ROW(agx3_cdm_barrier_wide_visibility_grounded(c), \ + "0000 01110 0100 00000 0 0") \ + ROW(agx3_cdm_barrier_flush_memory_grounded(c), "0000 00000 0000 10111 0 0") \ + ROW(agx3_cdm_substream_barrier_target_grounded(c), \ + "0000 01111 0111 10111 0 0") \ + ROW(agx3_cdm_secondary_barrier_target_grounded(c), \ + "0000 00000 0000 00111 0 0") \ + ROW(agx3_g17s_minimal_compute_dispatch_ready(c), \ + "0000 00000 0000 00010 0 0") \ + ROW(agx3_native_indirect_compute_dispatch_size(c) / 4, \ + "iiii ijjji iiii iiiii i i") \ + /* Per-record allowlists: Ioto. */ \ + ROW(agx_ioto_target_supported(c), "0000 01111 0111 10111 0 0") \ + ROW(agx_ioto_load_target_encoding(c), "0000 01111 0111 10222 0 0") \ + ROW(agx_ioto_profile_control_supported(c), "0000 01111 0111 10111 0 0") \ + ROW(agx_ioto_profile_control_size(c), "0000 04444 0444 40666 0 0") \ + ROW(ioto_preshader_generation(c), "0000 01111 0111 10222 0 0") \ + ROW(ioto_state_generation(c), "0000 01111 0111 10222 0 0") \ + ROW(ioto_program_inline_lddev(c), "0000 01111 0111 10000 0 0") \ + /* Outside lib: the command-stream decoder and the Vulkan driver. */ \ + ROW(decoder_chip(c), "0123 45678 9abc defgh i j") \ + ROW(shader_binary_version_class(c), "2222 21111 1111 31333 1 1") + +/* The Ioto encoding a codec packs for a chip: 1 for GPU0, 2 for GPU1, or 0 + * when it refuses the chip. The preshader branch starts with a different byte + * in each encoding, and each encoding refuses the other's SPECTPR state. */ +static unsigned +ioto_preshader_generation(enum agx_chip chip) +{ + uint8_t out[AGX_IOTO_PRESHADER_BRANCH_SIZE]; + + if (!agx_ioto_preshader_pack_branch(chip, 0, false, out)) + return 0; + + return out[0] == 0x0f ? 1 : out[0] == 0x5e ? 2 : 9; +} + +static unsigned +ioto_state_generation(enum agx_chip chip) +{ + const struct agx_ioto_state gpu0 = {0}, gpu1 = {.f = {3, 166}}; + uint8_t out[AGX_IOTO_SPECTPR_SIZE]; + + return agx_ioto_state_pack_spectpr(chip, &gpu0, out, sizeof(out)) ? 1 + : agx_ioto_state_pack_spectpr(chip, &gpu1, out, sizeof(out)) ? 2 + : 0; +} + +/* Whether the program codec takes the LDDEV that GPU0 programs carry inline, + * which no Ioto record decoder knows. */ +static unsigned +ioto_program_inline_lddev(enum agx_chip chip) +{ + const uint8_t lddev[AGX_IOTO_GPU0_INLINE_LDDEV_SIZE] = {0x67}; + size_t offset = 0; + + return agx_ioto_program_copy_suffix_offset(chip, lddev, sizeof(lddev), + &offset) && + offset == sizeof(lddev); +} + +static unsigned decoder_chip(enum agx_chip chip); + +/* Which of the Vulkan driver's three shader binary versions a chip's + * binaries carry: 1 classic, 2 AGX2, 3 AGX3. */ +static unsigned +shader_binary_version_class(enum agx_chip chip) +{ + switch (hk_shader_binary_version(chip)) { + case HK_CLASSIC_SHADER_BINARY_VERSION: + return 1; + case HK_AGX2_SHADER_BINARY_VERSION: + return 2; + case HK_AGX3_SHADER_BINARY_VERSION: + return 3; + default: + return 9; + } +} + +static const char *const chip_names[AGX_CHIP_UNKNOWN + 1] = { + "G13G", "G13X", "G14G", "G14X", "G15P", "G15G", "G15S", + "G15C", "G15D", "G16P", "G16G", "G16S", "G16C", "G17P", + "G17A", "G17G", "G17S", "G17C", "G18G", "unknown", +}; + +static void +check_row(const char *expr, const unsigned *got, const char *want) +{ + char got_s[AGX_CHIP_UNKNOWN + 2] = {0}, want_s[AGX_CHIP_UNKNOWN + 2] = {0}; + unsigned n = 0; + + for (; *want && n <= AGX_CHIP_UNKNOWN; ++want) { + if (*want != ' ') + want_s[n++] = *want; + } + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) + got_s[i] = + got[i] < 36 ? "0123456789abcdefghijklmnopqrstuvwxyz"[got[i]] : '?'; + + checks++; + if (strcmp(got_s, want_s)) { + fprintf(stderr, "%s:\n got \"%.4s %.5s %.4s %.5s %.1s %.1s\"\n", + expr, got_s, got_s + 4, got_s + 9, got_s + 13, got_s + 18, + got_s + 19); + fprintf(stderr, " expected \"%s\"\n", want_s); + failures++; + } +} + +static void +test_truth_table(void) +{ + _Static_assert(AGX_CHIP_UNKNOWN == 19, "one column per chip"); + +#define ROW(expr, want) \ + { \ + unsigned got[AGX_CHIP_UNKNOWN + 1]; \ + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { \ + const enum agx_chip c = (enum agx_chip)i; \ + got[i] = (unsigned)(expr); \ + } \ + check_row(#expr, got, want); \ + /* A value outside the enum answers as UNKNOWN does (or, for the rows \ + * that name a chip, as itself). */ \ + for (unsigned i = 0; i < 3; ++i) { \ + const enum agx_chip c = \ + (enum agx_chip)(i ? AGX_CHIP_UNKNOWN + i : -1); \ + const unsigned value = (unsigned)(expr); \ + CHECK(value == got[AGX_CHIP_UNKNOWN] || value == (unsigned)c); \ + } \ + } + TRUTH_TABLE(ROW) +#undef ROW + + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + const char *product = agx_chip_exact_product_name(c); + + CHECK(strcmp(agx_chip_name(c), chip_names[i]) == 0); + if (c == AGX_CHIP_G17P) + CHECK(product && strcmp(product, "A18 Pro") == 0); + else + CHECK(product == NULL); + } +} + +/* Exact driver-core identities recovered from Apple's readChipInfo table. */ +static const struct { uint32_t generation; uint32_t variant; uint32_t clusters; enum agx_chip chip; - enum agx_isa isa; - enum agx_isa_encoding encoding; - const char *name; - bool ray_tracing; - bool scheduling_stalls; +} chip_cases[] = { + {13, 'G', 1, AGX_CHIP_G13G}, {13, 'S', 2, AGX_CHIP_G13X}, + {13, 'C', 4, AGX_CHIP_G13X}, {13, 'D', 8, AGX_CHIP_G13X}, + {14, 'G', 1, AGX_CHIP_G14G}, {14, 'S', 2, AGX_CHIP_G14X}, + {14, 'C', 4, AGX_CHIP_G14X}, {14, 'D', 8, AGX_CHIP_G14X}, + {15, 'P', 1, AGX_CHIP_G15P}, {15, 'G', 1, AGX_CHIP_G15G}, + {15, 'S', 2, AGX_CHIP_G15S}, {15, 'C', 4, AGX_CHIP_G15C}, + {15, 'D', 8, AGX_CHIP_G15D}, {16, 'P', 1, AGX_CHIP_G16P}, + {16, 'G', 1, AGX_CHIP_G16G}, {16, 'S', 2, AGX_CHIP_G16S}, + {16, 'C', 4, AGX_CHIP_G16C}, {17, 'P', 1, AGX_CHIP_G17P}, + {17, 'A', 1, AGX_CHIP_G17A}, {17, 'G', 1, AGX_CHIP_G17G}, + {17, 'S', 2, AGX_CHIP_G17S}, {17, 'C', 4, AGX_CHIP_G17C}, + {18, 'G', 1, AGX_CHIP_G18G}, }; -/* - * Exact driver-core identities recovered from Apple's readChipInfo table. - * P/A are not Mac performance tiers: G15P is the A16 AGX2 part, while G17P - * (A18 Pro) and G17A stay on the AGX3b/HAL200 side of the M5 boundary. - */ -static const struct chip_case chip_cases[] = { - {13, 'G', 1, AGX_CHIP_G13G, AGX_ISA_AGX2, AGX_ISA_ENCODING_AGX2, - "G13G", false, false}, - {13, 'S', 2, AGX_CHIP_G13X, AGX_ISA_AGX2, AGX_ISA_ENCODING_AGX2, - "G13X", false, false}, - {14, 'G', 1, AGX_CHIP_G14G, AGX_ISA_AGX2, AGX_ISA_ENCODING_AGX2, - "G14G", false, false}, - {14, 'C', 4, AGX_CHIP_G14X, AGX_ISA_AGX2, AGX_ISA_ENCODING_AGX2, - "G14X", false, false}, - - {15, 'P', 1, AGX_CHIP_G15P, AGX_ISA_AGX2, AGX_ISA_ENCODING_AGX2, - "G15P", false, false}, - {15, 'G', 1, AGX_CHIP_G15G, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G15G", true, true}, - {15, 'S', 2, AGX_CHIP_G15S, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G15S", true, false}, - {15, 'C', 4, AGX_CHIP_G15C, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G15C", true, false}, - {15, 'D', 8, AGX_CHIP_G15D, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G15D", true, false}, - - {16, 'P', 1, AGX_CHIP_G16P, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G16P", true, false}, - {16, 'G', 1, AGX_CHIP_G16G, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G16G", true, false}, - {16, 'S', 2, AGX_CHIP_G16S, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G16S", true, false}, - {16, 'C', 4, AGX_CHIP_G16C, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G16C", true, false}, - - {17, 'P', 1, AGX_CHIP_G17P, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G17P", true, false}, - {17, 'A', 1, AGX_CHIP_G17A, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3B, - "G17A", true, false}, - {17, 'G', 1, AGX_CHIP_G17G, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3C, - "G17G", true, false}, - {17, 'S', 2, AGX_CHIP_G17S, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3C, - "G17S", true, false}, - {17, 'C', 4, AGX_CHIP_G17C, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3C, - "G17C", true, false}, - - /* M6 (J873): the third AGX3 encoding. */ - {18, 'G', 1, AGX_CHIP_G18G, AGX_ISA_AGX3, AGX_ISA_ENCODING_AGX3D, - "G18G", true, false}, -}; +/* The chip the command-stream decoder takes a chip's first kernel identity + * as. */ +static unsigned +decoder_chip(enum agx_chip chip) +{ + for (unsigned i = 0; i < sizeof(chip_cases) / sizeof(chip_cases[0]); ++i) { + if (chip_cases[i].chip == chip) { + const struct drm_asahi_params_global params = { + .gpu_generation = chip_cases[i].generation, + .gpu_variant = chip_cases[i].variant, + }; + return agxdecode_chip_from_params(¶ms); + } + } + + return agxdecode_chip_from_params(NULL); +} + +/* The decoder has its own mapping from the kernel's identity. It is that of + * agx_chip_from_params() without the cluster-count check (the counts here + * are zero), plus variant 'X': a trace that names the M4 Max that way decodes + * as G17P, where device open refuses the variant. */ +static void +test_decoder_identity(void) +{ + for (unsigned i = 0; i < sizeof(chip_cases) / sizeof(chip_cases[0]); ++i) { + const struct drm_asahi_params_global params = { + .gpu_generation = chip_cases[i].generation, + .gpu_variant = chip_cases[i].variant, + }; + CHECK_EQ(agxdecode_chip_from_params(¶ms), chip_cases[i].chip); + } + CHECK_EQ(agxdecode_chip_from_params(NULL), AGX_CHIP_UNKNOWN); + + /* The M4 Pro and M4 Max on the G17 kernel runtime are G17P. */ + static const struct { + uint32_t variant, chip_id, hal; + enum agx_chip decoder, device; + } g17_runtime[] = { + {'S', 0x6040, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_G17P, AGX_CHIP_G17P}, + {'S', 0x6041, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_G16S, AGX_CHIP_G16S}, + {'S', 0x6040, DRM_ASAHI_GPU_HAL_LEGACY, AGX_CHIP_G16S, AGX_CHIP_G16S}, + {'C', 0x6041, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_G17P, AGX_CHIP_G17P}, + {'C', 0x6040, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_G16C, AGX_CHIP_G16C}, + {'C', 0x6041, DRM_ASAHI_GPU_HAL_LEGACY, AGX_CHIP_G16C, AGX_CHIP_G16C}, + {'X', 0x6041, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_G17P, AGX_CHIP_UNKNOWN}, + {'X', 0x6040, DRM_ASAHI_GPU_HAL_200, AGX_CHIP_UNKNOWN, AGX_CHIP_UNKNOWN}, + {'X', 0x6041, DRM_ASAHI_GPU_HAL_LEGACY, AGX_CHIP_UNKNOWN, + AGX_CHIP_UNKNOWN}, + }; + for (unsigned i = 0; i < sizeof(g17_runtime) / sizeof(g17_runtime[0]); ++i) { + const struct drm_asahi_params_global params = { + .gpu_generation = 16, + .gpu_variant = g17_runtime[i].variant, + .chip_id = g17_runtime[i].chip_id, + .num_clusters_total = 4, + .usc_generation = 3, + .gpu_hal_generation = g17_runtime[i].hal, + }; + CHECK_EQ(agxdecode_chip_from_params(¶ms), g17_runtime[i].decoder); + CHECK_EQ(agx_chip_from_params(¶ms), g17_runtime[i].device); + } + + /* 'X' is the M4 Max only. */ + struct drm_asahi_params_global x = { + .gpu_generation = 17, + .gpu_variant = 'X', + .chip_id = 0x6041, + .usc_generation = 3, + .gpu_hal_generation = DRM_ASAHI_GPU_HAL_200, + }; + CHECK_EQ(agxdecode_chip_from_params(&x), AGX_CHIP_UNKNOWN); + x.gpu_generation = 16; + x.usc_generation = 2; + CHECK_EQ(agxdecode_chip_from_params(&x), AGX_CHIP_UNKNOWN); +} static enum agx_chip chip_for(uint32_t generation, uint32_t variant, uint32_t clusters) @@ -127,26 +459,13 @@ test_recovered_table(void) bool seen[AGX_CHIP_UNKNOWN + 1] = {0}; for (unsigned i = 0; i < sizeof(chip_cases) / sizeof(chip_cases[0]); ++i) { - const struct chip_case *c = &chip_cases[i]; - - CHECK_EQ(chip_for(c->generation, c->variant, c->clusters), c->chip); - CHECK_EQ(agx_chip_isa(c->chip), c->isa); - CHECK_EQ(agx_chip_isa_encoding(c->chip), c->encoding); - CHECK(strcmp(agx_chip_name(c->chip), c->name) == 0); - CHECK(agx_chip_has_hardware_ray_tracing(c->chip) == c->ray_tracing); - CHECK(agx_chip_needs_scheduling_stalls(c->chip) == - c->scheduling_stalls); - /* Every named chip has a known encoding. Every encoding but AGX3d has - * a packer: AGX2 through agx_pack.c, AGX3b/AGX3c through - * agx3_pack_binary.c. */ - CHECK(c->encoding != AGX_ISA_ENCODING_UNKNOWN); - CHECK(agx_chip_codegen_supported(c->chip) == - (c->encoding != AGX_ISA_ENCODING_AGX3D)); - CHECK(!seen[c->chip]); - seen[c->chip] = true; + CHECK_EQ(chip_for(chip_cases[i].generation, chip_cases[i].variant, + chip_cases[i].clusters), + chip_cases[i].chip); + seen[chip_cases[i].chip] = true; } - /* Every named enum must have exactly one row above. */ + /* Every named enum is reachable from the kernel's identity. */ for (int chip = AGX_CHIP_G13G; chip < AGX_CHIP_UNKNOWN; ++chip) CHECK(seen[chip]); } @@ -159,132 +478,14 @@ test_variant_is_load_bearing(void) CHECK_EQ(chip_for(17, 'G', 4), AGX_CHIP_G17G); CHECK_EQ(chip_for(15, 'P', 2), AGX_CHIP_G15P); CHECK_EQ(chip_for(15, 'S', 1), AGX_CHIP_G15S); - - CHECK_EQ(agx_chip_isa(AGX_CHIP_G15P), AGX_ISA_AGX2); - CHECK_EQ(agx_chip_isa_encoding(AGX_CHIP_G17P), - AGX_ISA_ENCODING_AGX3B); - CHECK_EQ(agx_chip_isa_encoding(AGX_CHIP_G17A), - AGX_ISA_ENCODING_AGX3B); - CHECK_EQ(agx_chip_isa_encoding(AGX_CHIP_G17G), - AGX_ISA_ENCODING_AGX3C); CHECK_EQ(chip_for(18, 'G', 4), AGX_CHIP_G18G); - CHECK_EQ(agx_chip_isa_encoding(AGX_CHIP_G18G), - AGX_ISA_ENCODING_AGX3D); } +/* The kernel-published identity is checked beyond the chip: each admitted + * profile is one exact SoC contract. */ static void -test_independent_generation_axes(void) +test_params_contracts(void) { - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G13G), - AGX_CS_GENERATION_AGX2); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G13G), - AGX_DESCRIPTOR_GENERATION_7); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G14X), - AGX_DESCRIPTOR_GENERATION_8); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G14X), - AGX_SAMPLER_GENERATION_GEN4); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G14X), 8); - - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G15G), - AGX_CS_GENERATION_G15); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G15D), - AGX_DESCRIPTOR_GENERATION_9); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G15D), - AGX_SAMPLER_GENERATION_GEN4); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G15D), 32); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G15D), - AGX_SUBMISSION_MODEL_CLASSIC); - - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G16G), - AGX_CS_GENERATION_HAL200); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G16S), - AGX_DESCRIPTOR_GENERATION_9); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G16S), - AGX_SAMPLER_GENERATION_GEN4_HAL200); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G16G), - AGX_SUBMISSION_MODEL_CLASSIC); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G16S), - AGX_SUBMISSION_MODEL_DUAL); - - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G17P), - AGX_CS_GENERATION_HAL200); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G17P), - AGX_DESCRIPTOR_GENERATION_9); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G17P), - AGX_SAMPLER_GENERATION_GEN4_HAL200); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G17P), 32); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G17P), - AGX_SUBMISSION_MODEL_DUAL); - - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G17G), - AGX_CS_GENERATION_HAL300); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G17S), - AGX_DESCRIPTOR_GENERATION_10); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G17C), - AGX_SAMPLER_GENERATION_GEN5); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G17S), 32); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G17G), - AGX_SUBMISSION_MODEL_SKSM); - - /* G18G writes the M5 records with a new shader encoding. */ - CHECK_EQ(agx_chip_isa(AGX_CHIP_G18G), AGX_ISA_AGX3); - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G18G), - AGX_CS_GENERATION_HAL300); - CHECK_EQ(agx_chip_descriptor_generation(AGX_CHIP_G18G), - AGX_DESCRIPTOR_GENERATION_10); - CHECK_EQ(agx_chip_sampler_generation(AGX_CHIP_G18G), - AGX_SAMPLER_GENERATION_GEN5); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G18G), 32); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G18G), - AGX_SUBMISSION_MODEL_SKSM); - CHECK(agx_chip_has_hardware_ray_tracing(AGX_CHIP_G18G)); - CHECK(!agx_chip_needs_scheduling_stalls(AGX_CHIP_G18G)); - CHECK(!agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_G18G)); - CHECK(agx_chip_exact_product_name(AGX_CHIP_G18G) == NULL); - - /* The witnessed HAL300 record set is G17G and G18G only. */ - for (int chip = AGX_CHIP_G13G; chip <= AGX_CHIP_UNKNOWN; ++chip) { - const enum agx_chip c = (enum agx_chip)chip; - CHECK(agx_chip_hal300_records(c) == - (c == AGX_CHIP_G17G || c == AGX_CHIP_G18G)); - if (agx_chip_hal300_records(c)) - CHECK_EQ(agx_chip_command_stream_generation(c), - AGX_CS_GENERATION_HAL300); - } - - /* These phone identities are useful for selecting the ISA, but the Mac - * driver corpus did not contain enough evidence to select every other - * driver axis. They remain outside the runnable device set. */ - CHECK_EQ(agx_chip_command_stream_generation(AGX_CHIP_G15P), - AGX_CS_GENERATION_UNKNOWN); - CHECK_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G15P), 0); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G16P), - AGX_SUBMISSION_MODEL_UNKNOWN); - CHECK_EQ(agx_chip_submission_model(AGX_CHIP_G17A), - AGX_SUBMISSION_MODEL_UNKNOWN); - - CHECK(agx_chip_driver_supported(AGX_CHIP_G13G)); - CHECK(agx_chip_driver_supported(AGX_CHIP_G14X)); - - /* Codegen and device support are separate axes. G17P has the exact - * T8140/HAL200 path; the other AGX3 identities have encoders but not a - * complete Honeykrisp device path. */ - CHECK(agx_chip_codegen_supported(AGX_CHIP_G15P)); - CHECK(agx_chip_codegen_supported(AGX_CHIP_G15G)); - CHECK(agx_chip_codegen_supported(AGX_CHIP_G17P)); - CHECK(agx_chip_codegen_supported(AGX_CHIP_G17S)); - CHECK(!agx_chip_codegen_supported(AGX_CHIP_UNKNOWN)); - /* No agx3d table exists, so G18G has no code generator and therefore no - * device path, whatever its command-stream axes say. */ - CHECK(!agx_chip_codegen_supported(AGX_CHIP_G18G)); - CHECK(!agx_chip_driver_supported(AGX_CHIP_G18G)); - - CHECK(!agx_chip_driver_supported(AGX_CHIP_G15P)); - CHECK(agx_chip_driver_supported(AGX_CHIP_G15G)); - CHECK(agx_chip_driver_supported(AGX_CHIP_G17P)); - CHECK(!agx_chip_driver_supported(AGX_CHIP_G17S)); - CHECK(!agx_chip_driver_supported(AGX_CHIP_UNKNOWN)); - struct drm_asahi_params_global g17p = { .gpu_generation = 17, .gpu_variant = 'P', @@ -295,9 +496,6 @@ test_independent_generation_axes(void) .gpu_hal_generation = DRM_ASAHI_GPU_HAL_200, }; CHECK(agx_params_driver_supported(&g17p)); - CHECK(strcmp(agx_chip_exact_product_name(AGX_CHIP_G17P), "A18 Pro") == - 0); - CHECK(agx_chip_exact_product_name(AGX_CHIP_G17G) == NULL); g17p.chip_id = 0x8141; CHECK(!agx_params_driver_supported(&g17p)); g17p.chip_id = 0x8140; @@ -352,11 +550,6 @@ test_independent_generation_axes(void) CHECK(!agx_params_m5_supported(&m6)); CHECK(!agx_params_driver_supported(&m6)); - CHECK(agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_G13G)); - CHECK(agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_G14X)); - CHECK(!agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_G17P)); - CHECK(!agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_UNKNOWN)); - CHECK(strcmp(agx_command_stream_generation_name( AGX_CS_GENERATION_HAL200), "HAL200") == 0); @@ -404,9 +597,9 @@ test_classification_invariants(void) CHECK(agx_chip_has_hardware_ray_tracing(c) == (isa == AGX_ISA_AGX3)); } + CHECK(strcmp(agx_isa_name(AGX_ISA_AGX2), "AGX2") == 0); CHECK(strcmp(agx_isa_name(AGX_ISA_AGX3), "AGX3") == 0); - CHECK(strcmp(agx_chip_name(AGX_CHIP_G18G), "G18G") == 0); - CHECK(strcmp(agx_chip_name(AGX_CHIP_UNKNOWN), "unknown") == 0); + CHECK(strcmp(agx_isa_name(AGX_ISA_UNKNOWN), "unknown") == 0); } /* The inline lookups answer every per-draw query; they must match the @@ -435,9 +628,11 @@ test_inline_lookups_match_reference(void) int main(void) { + test_truth_table(); test_recovered_table(); + test_decoder_identity(); test_variant_is_load_bearing(); - test_independent_generation_axes(); + test_params_contracts(); test_invalid_identity(); test_classification_invariants(); test_inline_lookups_match_reference(); diff --git a/src/asahi/lib/tests/test-chip.cpp b/src/asahi/lib/tests/test-chip.cpp index ddcf06f4f973..34f4bd2d0cd6 100644 --- a/src/asahi/lib/tests/test-chip.cpp +++ b/src/asahi/lib/tests/test-chip.cpp @@ -40,38 +40,6 @@ TEST(AGXChip, G16GRequiresExactKernelContract) } EXPECT_FALSE(agx_params_driver_supported(¶ms)) << field; } - - for (auto chip : {AGX_CHIP_G16P, AGX_CHIP_G16S, AGX_CHIP_G16C}) { - EXPECT_TRUE(agx_chip_codegen_supported(chip)); - EXPECT_FALSE(agx_chip_driver_supported(chip)); - } - EXPECT_TRUE(agx_chip_driver_supported(AGX_CHIP_G15S)); - EXPECT_TRUE(agx_chip_driver_supported(AGX_CHIP_G17P)); -} - -TEST(AGXChip, G16GUsesSharedNativePathWithItsOwnCapabilities) -{ - EXPECT_TRUE(agx_chip_native_agx3(AGX_CHIP_G16G)); - EXPECT_EQ(agx_chip_isa_encoding(AGX_CHIP_G16G), AGX_ISA_ENCODING_AGX3B); - EXPECT_EQ(agx_chip_record_family(AGX_CHIP_G16G), AGX_CHIP_G17P); - EXPECT_EQ(agx_chip_command_stream_generation(AGX_CHIP_G16G), - AGX_CS_GENERATION_HAL200); - EXPECT_EQ(agx_chip_descriptor_generation(AGX_CHIP_G16G), - AGX_DESCRIPTOR_GENERATION_9); - EXPECT_EQ(agx_chip_sampler_generation(AGX_CHIP_G16G), - AGX_SAMPLER_GENERATION_GEN4_HAL200); - EXPECT_EQ(agx_chip_sampler_heap_element_size(AGX_CHIP_G16G), 32u); - EXPECT_EQ(agx_chip_usc_helper_table_slots(AGX_CHIP_G16G, 0), 10u); - EXPECT_TRUE(agx_chip_native_indirect_compute(AGX_CHIP_G16G)); - EXPECT_TRUE(agx_chip_native_imageblock(AGX_CHIP_G16G)); - EXPECT_TRUE(agx_chip_explicit_robust_image_bounds(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_native_g15(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_has_native_render_context(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_native_preamble(AGX_CHIP_G16G)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_defect(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_tri_merge_across_side_effects(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_exact_fma32(AGX_CHIP_G16G)); - EXPECT_FALSE(agx_chip_uses_legacy_precompiled_programs(AGX_CHIP_G16G)); } TEST(AGXChip, TextureDescriptorSpareWordIsM5Gen10) @@ -86,20 +54,6 @@ TEST(AGXChip, TextureDescriptorSpareWordIsM5Gen10) EXPECT_FALSE(agx_chip_texture_descriptor_spare_word(chip)); } -TEST(AGXChip, UncoveredTileReloadDefect) -{ - /* M4 Pro keeps a 2x reload in the tilebuffer; 4x and A18 Pro spill. */ - EXPECT_FALSE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x6040, 2)); - EXPECT_FALSE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x6041, 2)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x6041, 4)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x6040, 4)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x8140, 2)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G17P, 0x8140, 4)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G16G, 0x8132, 2)); - EXPECT_TRUE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G15S, 0x6030, 2)); - EXPECT_FALSE(agx_chip_uncovered_tile_ms_reload_defect(AGX_CHIP_G13G, 0x8103, 2)); -} - TEST(AGXChip, G16GSharedComputeLaunchBytes) { agx3_g17p_native_compute_program_desc desc = {}; From 0f0ab96a895f0f0b899ac6239ab7b521657a89c7 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:09:18 -0300 Subject: [PATCH 02/13] agx: describe each chip in one row of a chip table agx_chip.h said what a chip is in several places: three positional arrays for the command-stream, descriptor and sampler generations, with a static_assert on the enumerator order, a *_reference switch for each in agx_chip.c that only the test read, switches for the instruction set, encoding, submission model and name, and a chip list in each predicate. The five native chips were typed three times. Put it in one row per chip. AGX_CHIPS() is an X-macro that enum agx_chip and agx_chip_infos[] are both expanded from, so the enum and the table cannot fall out of step. A row has the name, instruction set, encoding, command-stream, descriptor and sampler generation, submission model, path (AGX2, native AGX3, HAL300 or none), the records the chip is witnessed to take and one named bit per quirk predicate. The table is initialised by position because the C++ units that include the header reject designators. The OpenCL units get the rows but not the table. The precompiled libagx kernels take the chip as a run-time argument, and asahi_clc does not finish compiling a kernel that indexes a table (stopped after 11 minutes and 14.8 GiB). So the predicates those units can call, agx_chip_native_agx3() and agx_chip_has_record(), expand AGX_CHIPS() into the comparisons of the chips whose row passes, which is what the hand-written lists compiled to. They do so in C and C++ as well, so the test covers what the kernels run. AGX_CHIPS() passes its extra arguments on to the row macro, which is how that expansion is given the chip and the test. Every predicate keeps its name, signature and answers and now reads the row, so no call site changes. agx_chip_isa(), agx_chip_isa_encoding(), agx_chip_submission_model() and agx_chip_name() become inline row reads. Predicates that were derived from other predicates stay derived. The record bits are in the rows already; the record allowlists start reading them in the next commit, and until then the test checks each bit against its allowlist. agx_chip_m5_paths() and agx_chip_hal300_records() had the same body, G17G or G18G, and do not mean the same: one says which paths the driver runs, the other which record layouts native captures witness. They stay two predicates and each reads a bit of its own, so a chip that gains one does not get the other. Removed as dead: the *_reference switches, the positional arrays and their static_assert. The three chip ids of the G17P SoCs get names. Comments only: agx_chip_cdm_wide_visibility() and the record bit AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY say that they differ on G16G, as they did before, and the header's opening comment calls the Vulkan driver Borealis. Two lists that look alike and are not stay apart: agx_isa_is_agx3() is AGX3B and AGX3C, agx_encoding_is_agx3() also AGX3D. No behaviour change is intended for any chip. The truth table passes with its rows unedited (a path row is new), and the precompiled libagx kernels are byte-identical to those built from b8762aab9. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/lib/agx_chip.c | 309 +----------------- src/asahi/lib/agx_chip.h | 545 +++++++++++++++++++++----------- src/asahi/lib/tests/test-chip.c | 60 ++-- 3 files changed, 411 insertions(+), 503 deletions(-) diff --git a/src/asahi/lib/agx_chip.c b/src/asahi/lib/agx_chip.c index 07d4997df2b6..80e922fa3047 100644 --- a/src/asahi/lib/agx_chip.c +++ b/src/asahi/lib/agx_chip.c @@ -68,13 +68,13 @@ agx_chip_from_params(const struct drm_asahi_params_global *params) * a performance gate on it needs rows on those parts (see enum * agx_chip). */ - if (params->chip_id == 0x6040 && + if (params->chip_id == AGX_CHIP_ID_M4_PRO && params->usc_generation == AGX_ISA_AGX3 && params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) return AGX_CHIP_G17P; return AGX_CHIP_G16S; case 'C': - if (params->chip_id == 0x6041 && + if (params->chip_id == AGX_CHIP_ID_M4_MAX && params->usc_generation == AGX_ISA_AGX3 && params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) return AGX_CHIP_G17P; @@ -102,269 +102,6 @@ agx_chip_from_params(const struct drm_asahi_params_global *params) } } -enum agx_isa -agx_chip_isa(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - return AGX_ISA_AGX2; - - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return AGX_ISA_AGX3; - - case AGX_CHIP_UNKNOWN: - default: - return AGX_ISA_UNKNOWN; - } -} - -enum agx_isa_encoding -agx_chip_isa_encoding(enum agx_chip chip) -{ - /* - * Which encoder table a part uses. Apple's own tables decode each family - * 100% under exactly one of these and essentially 0% under the other, so - * this is a measurement rather than a reading of the naming scheme. - * - * gpu_gen and gpu_var are a string split of the kernel core-name table, so - * they map directly. P/A are not Mac performance tiers: G15P is AGX2 and - * G17P/G17A remain on the AGX3b/HAL200 side while the G17 Mac parts use - * AGX3c/HAL300. - */ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - return AGX_ISA_ENCODING_AGX2; - - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - return AGX_ISA_ENCODING_AGX3B; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return AGX_ISA_ENCODING_AGX3C; - - /* The agx3d encoding table, shared with G18M and G19P. */ - case AGX_CHIP_G18G: - return AGX_ISA_ENCODING_AGX3D; - - case AGX_CHIP_UNKNOWN: - default: - return AGX_ISA_ENCODING_UNKNOWN; - } -} - -enum agx_command_stream_generation -agx_chip_command_stream_generation_reference(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - return AGX_CS_GENERATION_AGX2; - - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - return AGX_CS_GENERATION_G15; - - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - return AGX_CS_GENERATION_HAL200; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return AGX_CS_GENERATION_HAL300; - - /* The record format, not the kernel HAL: the J873 native captures decode - * and repack under the HAL300 codecs. See agx_chip_hal300_records. */ - case AGX_CHIP_G18G: - return AGX_CS_GENERATION_HAL300; - - /* The A16 compiler target is known to be AGX2, but its command-stream - * class was not present in the Mac driver corpus. Do not infer it. */ - case AGX_CHIP_G15P: - case AGX_CHIP_UNKNOWN: - default: - return AGX_CS_GENERATION_UNKNOWN; - } -} - -enum agx_descriptor_generation -agx_chip_descriptor_generation_reference(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - return AGX_DESCRIPTOR_GENERATION_7; - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - return AGX_DESCRIPTOR_GENERATION_8; - - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - return AGX_DESCRIPTOR_GENERATION_9; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return AGX_DESCRIPTOR_GENERATION_10; - - /* The J873 colour render's PBE descriptor (ffe40a02 00007f80 00005800 - * 0003f010) and its texture descriptor (f6880a02 0007f80f 00005800 - * 000fc010) unpack as Gen10 and repack byte-identically. */ - case AGX_CHIP_G18G: - return AGX_DESCRIPTOR_GENERATION_10; - - case AGX_CHIP_G15P: - case AGX_CHIP_UNKNOWN: - default: - return AGX_DESCRIPTOR_GENERATION_UNKNOWN; - } -} - -enum agx_sampler_generation -agx_chip_sampler_generation_reference(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - return AGX_SAMPLER_GENERATION_GEN4; - - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - return AGX_SAMPLER_GENERATION_GEN4_HAL200; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return AGX_SAMPLER_GENERATION_GEN5; - - /* The J873 texture-sample render's sampler (Metal's default descriptor - * with nearest filters and clamp-to-edge) is 000f0000 00000780 at - * element 2 of a 32-byte heap. It repacks byte-identically as Gen5 and - * not as either Gen4 layout, whose maximum-LOD clamp of 14.0 turns the - * 15.0 there into 000e0000. */ - case AGX_CHIP_G18G: - return AGX_SAMPLER_GENERATION_GEN5; - - case AGX_CHIP_G15P: - case AGX_CHIP_UNKNOWN: - default: - return AGX_SAMPLER_GENERATION_UNKNOWN; - } -} - -unsigned -agx_chip_sampler_heap_element_size_reference(enum agx_chip chip) -{ - switch (agx_chip_command_stream_generation_reference(chip)) { - case AGX_CS_GENERATION_AGX2: - return 8; - case AGX_CS_GENERATION_G15: - case AGX_CS_GENERATION_HAL200: - case AGX_CS_GENERATION_HAL300: - return 32; - case AGX_CS_GENERATION_UNKNOWN: - default: - return 0; - } -} - -enum agx_submission_model -agx_chip_submission_model(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - return AGX_SUBMISSION_MODEL_CLASSIC; - - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - return AGX_SUBMISSION_MODEL_DUAL; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return AGX_SUBMISSION_MODEL_SKSM; - - /* On macOS 26A428 the G18G GPU has only SKSM channels, for 3D, TA - * and compute work; there is no classic queue. */ - case AGX_CHIP_G18G: - return AGX_SUBMISSION_MODEL_SKSM; - - /* No corresponding accelerator class was present in the Mac corpus. */ - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - case AGX_CHIP_UNKNOWN: - default: - return AGX_SUBMISSION_MODEL_UNKNOWN; - } -} - bool agx_chip_codegen_supported(enum agx_chip chip) { @@ -495,13 +232,13 @@ agx_params_driver_supported(const struct drm_asahi_params_global *params) case AGX_CHIP_G17P: { /* Honeykrisp's first AGX3 path is the exact T8140/A18 Pro contract. * Do not let the shared G17P ISA name admit another SoC or topology. */ - const bool a18_pro = - params->chip_id == 0x8140 && params->num_clusters_total == 1; + const bool a18_pro = params->chip_id == AGX_CHIP_ID_A18_PRO && + params->num_clusters_total == 1; /* M4 Pro: two clusters (a binned part keeps two). */ - const bool m4_pro = - params->chip_id == 0x6040 && params->num_clusters_total == 2; - const bool m4_max = - params->chip_id == 0x6041 && params->num_clusters_total == 4; + const bool m4_pro = params->chip_id == AGX_CHIP_ID_M4_PRO && + params->num_clusters_total == 2; + const bool m4_max = params->chip_id == AGX_CHIP_ID_M4_MAX && + params->num_clusters_total == 4; return (a18_pro || m4_pro || m4_max) && params->num_dies == 1 && params->usc_generation == AGX_ISA_AGX3 && params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200; @@ -637,35 +374,7 @@ agx_chip_needs_scheduling_stalls(enum agx_chip chip) /* The M3 base part alone. Not a property of its encoding: G15G shares the * agx3b table with G15S/C/D, every G16 part, and G17P/A, none of which * pad. */ - return chip == AGX_CHIP_G15G; -} - -const char * -agx_chip_name(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: return "G13G"; - case AGX_CHIP_G13X: return "G13X"; - case AGX_CHIP_G14G: return "G14G"; - case AGX_CHIP_G14X: return "G14X"; - case AGX_CHIP_G15P: return "G15P"; - case AGX_CHIP_G15G: return "G15G"; - case AGX_CHIP_G15S: return "G15S"; - case AGX_CHIP_G15C: return "G15C"; - case AGX_CHIP_G15D: return "G15D"; - case AGX_CHIP_G16P: return "G16P"; - case AGX_CHIP_G16G: return "G16G"; - case AGX_CHIP_G16S: return "G16S"; - case AGX_CHIP_G16C: return "G16C"; - case AGX_CHIP_G17P: return "G17P"; - case AGX_CHIP_G17A: return "G17A"; - case AGX_CHIP_G17G: return "G17G"; - case AGX_CHIP_G17S: return "G17S"; - case AGX_CHIP_G17C: return "G17C"; - case AGX_CHIP_G18G: return "G18G"; - case AGX_CHIP_UNKNOWN: - default: return "unknown"; - } + return agx_chip_info(chip)->quirks & AGX_QUIRK_SCHEDULING_STALLS; } const char * diff --git a/src/asahi/lib/agx_chip.h b/src/asahi/lib/agx_chip.h index 02f89f8642f4..b42de0996fb1 100644 --- a/src/asahi/lib/agx_chip.h +++ b/src/asahi/lib/agx_chip.h @@ -22,55 +22,13 @@ * * AGX3 now has separate decoders and encoders. Device support remains a * stricter question: G17P is admitted only through its exact T8140 contract, - * while other AGX3 identities stay outside the runnable Honeykrisp path until + * while other AGX3 identities stay outside the runnable Borealis path until * their independently-versioned pieces are connected. */ -enum agx_chip { - /* AGX2. `G` is a single-cluster part, `X` is multi-cluster. */ - AGX_CHIP_G13G, - AGX_CHIP_G13X, - AGX_CHIP_G14G, - AGX_CHIP_G14X, - - /* G15P is the A16 phone part and still executes AGX2. The Mac G15 parts - * execute AGX3b; G15G additionally needs explicit scheduling nops. */ - AGX_CHIP_G15P, - AGX_CHIP_G15G, - AGX_CHIP_G15S, - AGX_CHIP_G15C, - AGX_CHIP_G15D, - - /* Every G16 part executes AGX3b. */ - AGX_CHIP_G16P, - AGX_CHIP_G16G, - AGX_CHIP_G16S, - AGX_CHIP_G16C, - - /* G17P/G17A remain on the HAL200/AGX3b side of the boundary. The M5 - * G/S/C parts use AGX3c. - * - * G17P is an instruction-set and firmware-HAL profile (AGX3b shaders, - * HAL200 firmware interface), not one SoC. agx_chip_from_params() maps - * three SoCs to it: the A18 Pro (T8140, one cluster), the M4 Pro (T6040) - * and the M4 Max (T6041). They share the encodings, so encoding gates on - * G17P are exact. They differ in cluster and core counts, caches and - * clocks, so a performance or tuning gate on G17P is only as good as the - * rows behind it: give it measurements on its members (at least the A18 - * Pro and the M4 Pro), or select it by the hardware property that is the - * real reason. */ - AGX_CHIP_G17P, - AGX_CHIP_G17A, - AGX_CHIP_G17G, - AGX_CHIP_G17S, - AGX_CHIP_G17C, - - /* The M6 base part (J873, T8152). Its command-stream records are the - * M5 HAL300 ones, but its shaders use a third AGX3 encoding. */ - AGX_CHIP_G18G, - - AGX_CHIP_UNKNOWN, -}; +#ifndef __OPENCL_VERSION__ +#include +#endif /* Instruction set. Apple's compiler names these agx2 and agx3, and the low * nibble of an applegpu Mach-O cpusubtype is exactly this value. */ @@ -167,6 +125,287 @@ enum agx_submission_model { AGX_SUBMISSION_MODEL_UNKNOWN, }; +/* Which of the driver's command paths a chip runs: the AGX2 one, the native + * AGX3 one (agx_chip_native_agx3) or the HAL300 one of the M5 parts and G18G. + * NONE is a recognised part that device open does not admit. */ +enum agx_chip_path { + AGX_CHIP_PATH_NONE, + AGX_CHIP_PATH_AGX2, + AGX_CHIP_PATH_NATIVE_AGX3, + AGX_CHIP_PATH_HAL300, +}; + +/* + * Command-stream records a chip is witnessed to take, one bit per record + * codec. A codec refuses a chip without its bit, so a bit is set only with + * captures or hardware results for that chip and that record. The codec's own + * file says what the evidence is. + */ +enum agx_chip_record { + AGX_RECORD_VDM_STATE = 1 << 0, + AGX_RECORD_VDM_PPP_STATE = 1 << 1, + AGX_RECORD_VDM_BARRIER = 1 << 2, + AGX_RECORD_VDM_STREAM_LINK = 1 << 3, + AGX_RECORD_VDM_STREAM_TERMINATE = 1 << 4, + AGX_RECORD_VDM_TESSELLATE = 1 << 5, + AGX_RECORD_VDM_INDEX_LIST = 1 << 6, + AGX_RECORD_PPP_HAL300_DEPTH_STENCIL = 1 << 7, + AGX_RECORD_PPP_HAL300_DEPTH_BIAS_SCISSOR = 1 << 8, + AGX_RECORD_CDM_LAUNCH = 1 << 9, + AGX_RECORD_CDM_INDIRECT_LAUNCH = 1 << 10, + AGX_RECORD_CDM_INDIRECT_LAUNCH_36 = 1 << 11, + AGX_RECORD_CDM_STREAM_LINK = 1 << 12, + AGX_RECORD_CDM_LINK_PADDING = 1 << 13, + AGX_RECORD_CDM_BARRIER = 1 << 14, + /* G16G has it too, unlike agx_chip_cdm_wide_visibility(). */ + AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY = 1 << 15, + AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY = 1 << 16, + AGX_RECORD_CDM_SUBSTREAM_BARRIER = 1 << 17, + AGX_RECORD_CDM_SECONDARY_BARRIER = 1 << 18, + AGX_RECORD_IOTO_PROFILE_CONTROL = 1 << 19, + /* agx_chip_hal300_records */ + AGX_RECORD_HAL300_NATIVE_CAPTURE = 1 << 20, +}; + +/* The records of every byte-witnessed G15, G16 and G17 identity. */ +#define AGX_RECORDS_G15_G17 \ + (AGX_RECORD_VDM_STATE | AGX_RECORD_VDM_PPP_STATE | AGX_RECORD_VDM_BARRIER | \ + AGX_RECORD_VDM_STREAM_LINK | AGX_RECORD_VDM_STREAM_TERMINATE | \ + AGX_RECORD_VDM_TESSELLATE | AGX_RECORD_VDM_INDEX_LIST | \ + AGX_RECORD_CDM_LAUNCH | AGX_RECORD_CDM_INDIRECT_LAUNCH | \ + AGX_RECORD_CDM_INDIRECT_LAUNCH_36 | AGX_RECORD_CDM_STREAM_LINK | \ + AGX_RECORD_CDM_LINK_PADDING | AGX_RECORD_CDM_BARRIER | \ + AGX_RECORD_CDM_SUBSTREAM_BARRIER | AGX_RECORD_IOTO_PROFILE_CONTROL) + +/* What the M5 parts add to them. */ +#define AGX_RECORDS_M5 \ + (AGX_RECORDS_G15_G17 | AGX_RECORD_PPP_HAL300_DEPTH_STENCIL | \ + AGX_RECORD_PPP_HAL300_DEPTH_BIAS_SCISSOR | \ + AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY | AGX_RECORD_CDM_SECONDARY_BARRIER) + +/* G18G has the records its J873 native captures contain. The codecs of the + * other G15-G17 records refuse it: the VDM stream link and tessellate codecs + * because no capture contains the record, the rest as their lists stood + * before this table (see each codec). */ +#define AGX_RECORDS_G18G \ + (AGX_RECORD_VDM_STATE | AGX_RECORD_VDM_PPP_STATE | AGX_RECORD_VDM_BARRIER | \ + AGX_RECORD_VDM_STREAM_TERMINATE | AGX_RECORD_PPP_HAL300_DEPTH_STENCIL | \ + AGX_RECORD_PPP_HAL300_DEPTH_BIAS_SCISSOR | AGX_RECORD_CDM_LAUNCH | \ + AGX_RECORD_CDM_INDIRECT_LAUNCH | AGX_RECORD_CDM_INDIRECT_LAUNCH_36 | \ + AGX_RECORD_CDM_BARRIER | AGX_RECORD_HAL300_NATIVE_CAPTURE) + +/* Per-chip behaviour that is not a generation axis. Each bit is read by the + * one predicate below that is named after it, which documents it. */ +enum agx_chip_quirk { + AGX_QUIRK_NATIVE_RENDER_CONTEXT = 1 << 0, + AGX_QUIRK_NATIVE_INDIRECT_COMPUTE = 1 << 1, + AGX_QUIRK_USC_HELPER_SLOT_PER_CORE = 1 << 2, + AGX_QUIRK_USC_BASE_PAGE_FILL_RETURNS = 1 << 3, + AGX_QUIRK_EXPLICIT_ROBUST_IMAGE_BOUNDS = 1 << 4, + AGX_QUIRK_NATIVE_IMAGEBLOCK = 1 << 5, + AGX_QUIRK_UNCOVERED_TILE_MS_DEFECT = 1 << 6, + AGX_QUIRK_TRI_MERGE_ACROSS_SIDE_EFFECTS = 1 << 7, + AGX_QUIRK_IMAGE_LOAD_MISSES_OWN_STORE = 1 << 8, + AGX_QUIRK_INEXACT_FMA32 = 1 << 9, + AGX_QUIRK_NATIVE_PREAMBLE = 1 << 10, + AGX_QUIRK_SCHEDULING_STALLS = 1 << 11, + AGX_QUIRK_M5_PATHS = 1 << 12, +}; + +/* What the five native AGX3 chips share. */ +#define AGX_QUIRKS_NATIVE \ + (AGX_QUIRK_NATIVE_INDIRECT_COMPUTE | AGX_QUIRK_NATIVE_IMAGEBLOCK | \ + AGX_QUIRK_UNCOVERED_TILE_MS_DEFECT) + +/* The native chips that are not G17P: G15G, G15S, G15C and G16G. */ +#define AGX_QUIRKS_NATIVE_PRE_G17 \ + (AGX_QUIRKS_NATIVE | AGX_QUIRK_EXPLICIT_ROBUST_IMAGE_BOUNDS | \ + AGX_QUIRK_INEXACT_FMA32) + +#define AGX_QUIRKS_G17P \ + (AGX_QUIRKS_NATIVE | AGX_QUIRK_NATIVE_RENDER_CONTEXT | \ + AGX_QUIRK_USC_HELPER_SLOT_PER_CORE | \ + AGX_QUIRK_TRI_MERGE_ACROSS_SIDE_EFFECTS | \ + AGX_QUIRK_IMAGE_LOAD_MISSES_OWN_STORE | AGX_QUIRK_NATIVE_PREAMBLE) + +/* + * The chip table: one row per chip, and the only place that says what a chip + * is. enum agx_chip and agx_chip_infos[] are both expanded from it, so they + * cannot disagree, and every predicate below reads a field of the row. + * + * Columns: chip, instruction set, binary encoding, command-stream generation, + * descriptor generation, sampler generation, submission model, path, + * witnessed records, quirks. + * + * AGX2: `G` is a single-cluster part, `X` is multi-cluster. + * + * G15P is the A16 phone part and still executes AGX2; its command-stream, + * descriptor and sampler classes were not in the Mac driver corpus and are + * not inferred. The Mac G15 parts execute AGX3b; G15G additionally needs + * explicit scheduling nops. Every G16 part executes AGX3b. + * + * G17P/G17A remain on the HAL200/AGX3b side of the boundary. The M5 G/S/C + * parts use AGX3c. + * + * G17P is an instruction-set and firmware-HAL profile (AGX3b shaders, HAL200 + * firmware interface), not one SoC. agx_chip_from_params() maps three SoCs to + * it: the A18 Pro (T8140, one cluster), the M4 Pro (T6040) and the M4 Max + * (T6041). They share the encodings, so encoding gates on G17P are exact. + * They differ in cluster and core counts, caches and clocks, so a performance + * or tuning gate on G17P is only as good as the rows behind it: give it + * measurements on its members (at least the A18 Pro and the M4 Pro), or + * select it by the hardware property that is the real reason. + * + * G18G is the M6 base part (J873, T8152). Its shaders use a third AGX3 + * encoding, the agx3d table it shares with G18M and G19P. The other axes are + * the M5 ones: + * - Records: HAL300. This is the record format, not the kernel HAL; the + * J873 native captures decode and repack under the HAL300 codecs (see + * agx_chip_hal300_records). + * - Descriptors: Gen10. The J873 colour render's PBE descriptor (ffe40a02 + * 00007f80 00005800 0003f010) and its texture descriptor (f6880a02 + * 0007f80f 00005800 000fc010) unpack as Gen10 and repack byte-identically. + * - Samplers: Gen5. The J873 texture-sample render's sampler (Metal's + * default descriptor with nearest filters and clamp-to-edge) is 000f0000 + * 00000780 at element 2 of a 32-byte heap. It repacks byte-identically as + * Gen5 and not as either Gen4 layout, whose maximum-LOD clamp of 14.0 + * turns the 15.0 there into 000e0000. + * - Submission: on macOS 26A428 the G18G GPU has only SKSM channels, for + * 3D, TA and compute work; there is no classic queue. + * + * No accelerator class for G15P, G16P or G17A was in the Mac corpus, so their + * submission model is unknown. + */ +#define AGX_CHIPS(X, ...) \ + X(G13G, AGX2, AGX2, AGX2, 7, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G13X, AGX2, AGX2, AGX2, 7, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G14G, AGX2, AGX2, AGX2, 8, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G14X, AGX2, AGX2, AGX2, 8, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G15P, AGX2, AGX2, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, NONE, 0, 0, \ + __VA_ARGS__) \ + X(G15G, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ + AGX_QUIRKS_NATIVE_PRE_G17 | AGX_QUIRK_SCHEDULING_STALLS, __VA_ARGS__) \ + X(G15S, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ + AGX_QUIRKS_NATIVE_PRE_G17, __VA_ARGS__) \ + X(G15C, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ + AGX_QUIRKS_NATIVE_PRE_G17 | AGX_QUIRK_USC_BASE_PAGE_FILL_RETURNS, \ + __VA_ARGS__) \ + X(G15D, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NONE, AGX_RECORDS_G15_G17, 0, \ + __VA_ARGS__) \ + X(G16P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, UNKNOWN, NONE, 0, 0, \ + __VA_ARGS__) \ + X(G16G, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, CLASSIC, NATIVE_AGX3, \ + AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ + AGX_QUIRKS_NATIVE_PRE_G17, __VA_ARGS__) \ + X(G16S, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NONE, \ + AGX_RECORDS_G15_G17, 0, __VA_ARGS__) \ + X(G16C, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NONE, \ + AGX_RECORDS_G15_G17, 0, __VA_ARGS__) \ + X(G17P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NATIVE_AGX3, \ + AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY, \ + AGX_QUIRKS_G17P, __VA_ARGS__) \ + X(G17A, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, UNKNOWN, NONE, 0, 0, \ + __VA_ARGS__) \ + X(G17G, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, \ + AGX_RECORDS_M5 | AGX_RECORD_HAL300_NATIVE_CAPTURE, AGX_QUIRK_M5_PATHS, \ + __VA_ARGS__) \ + X(G17S, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_M5, 0, \ + __VA_ARGS__) \ + X(G17C, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_M5, 0, \ + __VA_ARGS__) \ + X(G18G, AGX3, AGX3D, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_G18G, \ + AGX_QUIRK_M5_PATHS, __VA_ARGS__) + +enum agx_chip { +#define AGX_CHIP_ENUM(chip, ...) AGX_CHIP_##chip, + AGX_CHIPS(AGX_CHIP_ENUM) +#undef AGX_CHIP_ENUM + AGX_CHIP_UNKNOWN, +}; + +struct agx_chip_info { + /* Stable name for diagnostics, e.g. "G15G". */ + char name[8]; + enum agx_isa isa; + enum agx_isa_encoding encoding; + enum agx_command_stream_generation cs_generation; + enum agx_descriptor_generation descriptor_generation; + enum agx_sampler_generation sampler_generation; + enum agx_submission_model submission_model; + enum agx_chip_path path; + /* Mask of enum agx_chip_record. */ + unsigned records; + /* Mask of enum agx_chip_quirk. */ + unsigned quirks; +}; + +#ifndef __OPENCL_VERSION__ + +/* Initialised by position: the C++ translation units that include this + * header reject array and field designators. */ +static const struct agx_chip_info agx_chip_infos[AGX_CHIP_UNKNOWN + 1] = { +#define AGX_CHIP_INFO(chip, isa, encoding, cs, descriptor, sampler, \ + submission, path, records, quirks, ...) \ + {#chip, \ + AGX_ISA_##isa, \ + AGX_ISA_ENCODING_##encoding, \ + AGX_CS_GENERATION_##cs, \ + AGX_DESCRIPTOR_GENERATION_##descriptor, \ + AGX_SAMPLER_GENERATION_##sampler, \ + AGX_SUBMISSION_MODEL_##submission, \ + AGX_CHIP_PATH_##path, \ + records, \ + quirks}, + AGX_CHIPS(AGX_CHIP_INFO) +#undef AGX_CHIP_INFO + {"unknown", AGX_ISA_UNKNOWN, AGX_ISA_ENCODING_UNKNOWN, + AGX_CS_GENERATION_UNKNOWN, AGX_DESCRIPTOR_GENERATION_UNKNOWN, + AGX_SAMPLER_GENERATION_UNKNOWN, AGX_SUBMISSION_MODEL_UNKNOWN, + AGX_CHIP_PATH_NONE, 0, 0}, +}; + +/* The row of a chip. AGX_CHIP_UNKNOWN and any value outside the enum get the + * unknown row. The predicates below are queried several times per recorded + * draw and dispatch, and this is one bounded table load: no out-of-line call + * and no jump table, whose indirect branch is especially costly when the x86 + * driver build runs under FEX. */ +static inline const struct agx_chip_info * +agx_chip_info(enum agx_chip chip) +{ + return &agx_chip_infos[(unsigned)chip < AGX_CHIP_UNKNOWN ? chip + : AGX_CHIP_UNKNOWN]; +} + +#endif + +/* + * The predicates the OpenCL units can call do not load from the table. The + * precompiled libagx kernels get the chip as a run-time argument, and + * asahi_clc does not finish compiling a kernel that indexes a table. A test + * of the row instead expands to the comparisons of the chips whose row + * passes it, which is what a hand-written chip list compiles to. The C units + * use the same expansion, so tests/test-chip.c tests what the kernels run. + * AGX_CHIPS(AGX_CHIP_ROW_TEST, chip, TEST, arg) is that expansion for the + * rows that pass TEST(path, records, arg). + */ +#define AGX_CHIP_ROW_TEST(row, isa, encoding, cs, descriptor, sampler, \ + submission, path, records, quirks, chip, TEST, arg) \ + | (((chip) == AGX_CHIP_##row) & TEST(AGX_CHIP_PATH_##path, records, arg)) +#define AGX_CHIP_ROW_HAS_RECORD(path, records, record) \ + (((records) & (record)) != 0) +#define AGX_CHIP_ROW_ON_PATH(path, records, wanted) ((path) == (wanted)) + +/* Whether a chip is witnessed to take a record (enum agx_chip_record). */ +static inline bool +agx_chip_has_record(enum agx_chip chip, unsigned record) +{ + return false AGX_CHIPS(AGX_CHIP_ROW_TEST, chip, AGX_CHIP_ROW_HAS_RECORD, + record); +} + /* G17P keeps every colour target in the imageblock past 64 bytes a sample: * Apple's applegpu_g17p fragments store five RGBA32Float targets at tile * offsets 0..64 and eight at 0..112, and an eight-target mixed-format set at @@ -209,16 +448,11 @@ enum agx_submission_model { * differs from G17P, a narrower capability predicate below answers for it; * the chip identity is never tested at the call site. */ -#ifndef __OPENCL_VERSION__ -#include -#endif - static inline bool agx_chip_native_agx3(enum agx_chip chip) { - return chip == AGX_CHIP_G15G || chip == AGX_CHIP_G15S || - chip == AGX_CHIP_G15C || chip == AGX_CHIP_G16G || - chip == AGX_CHIP_G17P; + return false AGX_CHIPS(AGX_CHIP_ROW_TEST, chip, AGX_CHIP_ROW_ON_PATH, + AGX_CHIP_PATH_NATIVE_AGX3); } /* The chip whose record encodings GPU-generated (libagx) command-stream @@ -230,10 +464,6 @@ agx_chip_record_family(enum agx_chip chip) return agx_chip_native_agx3(chip) ? AGX_CHIP_G17P : chip; } -#ifndef __OPENCL_VERSION__ -#include -#endif - /* * Whether native captures on this chip witness the HAL300 records Mesa's M5 * packers write: the VDM state, PPP state and Index List words, the nine PPP @@ -254,28 +484,13 @@ agx_chip_record_family(enum agx_chip chip) * * This is a statement about the record layouts only. G17S/G17C also write * HAL300 records but have no native graphics capture, so the codecs that - * accept them list them by name. It says nothing about the shader encoding - * or the kernel submission ABI. + * accept them have their own record bits. It says nothing about the shader + * encoding or the kernel submission ABI. */ static inline bool agx_chip_hal300_records(enum agx_chip chip) { - return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G18G; -} - -/* - * Whether the Gallium driver takes its M5 paths on this chip: draw admission, - * native descriptors, the VDM/PPP streams and the M5 kernel contract. G18G - * does: its records and texture/PBE descriptors are byte-identical to M5's - * on every J873 native capture (agx_chip_hal300_records), its code is G17G - * code re-encoded (agx_device_key::emit_agx3d), and the chip-specific deltas - * (the tailed non-indexed Index List, the point-size rule) stay keyed on the - * chip inside the record packers. - */ -static inline bool -agx_chip_m5_paths(enum agx_chip chip) -{ - return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G18G; + return agx_chip_has_record(chip, AGX_RECORD_HAL300_NATIVE_CAPTURE); } /* @@ -321,8 +536,6 @@ agx_encoding_is_g17_class(enum agx_isa_encoding encoding) #ifndef __OPENCL_VERSION__ -#include -#include #include #include "drm-uapi/asahi_drm.h" @@ -336,6 +549,11 @@ agx_isa_is_agx3(enum agx_isa_encoding enc) return enc == AGX_ISA_ENCODING_AGX3B || enc == AGX_ISA_ENCODING_AGX3C; } +/* drm_asahi_params_global::chip_id of the three SoCs that run as G17P. */ +#define AGX_CHIP_ID_A18_PRO 0x8140 +#define AGX_CHIP_ID_M4_PRO 0x6040 +#define AGX_CHIP_ID_M4_MAX 0x6041 + #ifdef __cplusplus extern "C" { #endif @@ -347,105 +565,39 @@ enum agx_chip agx_chip_from_params(const struct drm_asahi_params_global *params); /* The instruction set a chip executes. */ -enum agx_isa agx_chip_isa(enum agx_chip chip); - -/* The binary encoding of that instruction set. Known for every chip in the - * enum; UNKNOWN only for AGX_CHIP_UNKNOWN. */ -enum agx_isa_encoding agx_chip_isa_encoding(enum agx_chip chip); - -enum agx_command_stream_generation -agx_chip_command_stream_generation_reference(enum agx_chip chip); - -enum agx_descriptor_generation -agx_chip_descriptor_generation_reference(enum agx_chip chip); - -enum agx_sampler_generation -agx_chip_sampler_generation_reference(enum agx_chip chip); - -unsigned agx_chip_sampler_heap_element_size_reference(enum agx_chip chip); - -/* These are queried several times per recorded draw and dispatch. Answer them - * with one bounded table load instead of an out-of-line call through a jump - * table: an indirect branch per query is especially costly when the x86 - * driver build runs under FEX. */ -#define AGX_CHIP_TABLE(G13G, G13X, G14G, G14X, G15P, G15G, G15S, G15C, G15D, \ - G16P, G16G, G16S, G16C, G17P, G17A, G17G, G17S, G17C, \ - G18G) \ - { \ - G13G, G13X, G14G, G14X, G15P, G15G, G15S, G15C, G15D, G16P, G16G, G16S, \ - G16C, G17P, G17A, G17G, G17S, G17C, G18G, \ - } +static inline enum agx_isa +agx_chip_isa(enum agx_chip chip) +{ + return agx_chip_info(chip)->isa; +} -/* The table is positional (C++ translation units include this header and - * reject array designators), so pin the enumerator order it relies on. */ -static_assert(AGX_CHIP_G13G == 0 && AGX_CHIP_G13X == 1 && AGX_CHIP_G14G == 2 && - AGX_CHIP_G14X == 3 && AGX_CHIP_G15P == 4 && - AGX_CHIP_G15G == 5 && AGX_CHIP_G15S == 6 && - AGX_CHIP_G15C == 7 && AGX_CHIP_G15D == 8 && - AGX_CHIP_G16P == 9 && AGX_CHIP_G16G == 10 && - AGX_CHIP_G16S == 11 && AGX_CHIP_G16C == 12 && - AGX_CHIP_G17P == 13 && AGX_CHIP_G17A == 14 && - AGX_CHIP_G17G == 15 && AGX_CHIP_G17S == 16 && - AGX_CHIP_G17C == 17 && AGX_CHIP_G18G == 18 && - AGX_CHIP_UNKNOWN == 19, - "AGX_CHIP_TABLE is ordered by enum agx_chip"); +/* The binary encoding of that instruction set: which encoder table a part + * uses. Apple's own tables decode each family 100% under exactly one of them + * and essentially 0% under the others, so this is a measurement rather than a + * reading of the naming scheme. Known for every chip in the enum; UNKNOWN + * only for AGX_CHIP_UNKNOWN. */ +static inline enum agx_isa_encoding +agx_chip_isa_encoding(enum agx_chip chip) +{ + return agx_chip_info(chip)->encoding; +} static inline enum agx_command_stream_generation agx_chip_command_stream_generation(enum agx_chip chip) { - static const uint8_t table[AGX_CHIP_UNKNOWN] = AGX_CHIP_TABLE( - AGX_CS_GENERATION_AGX2, AGX_CS_GENERATION_AGX2, AGX_CS_GENERATION_AGX2, - AGX_CS_GENERATION_AGX2, - /* A16's command-stream class was not in the Mac corpus. */ - AGX_CS_GENERATION_UNKNOWN, - AGX_CS_GENERATION_G15, AGX_CS_GENERATION_G15, AGX_CS_GENERATION_G15, - AGX_CS_GENERATION_G15, - AGX_CS_GENERATION_HAL200, AGX_CS_GENERATION_HAL200, - AGX_CS_GENERATION_HAL200, AGX_CS_GENERATION_HAL200, - AGX_CS_GENERATION_HAL200, AGX_CS_GENERATION_HAL200, - AGX_CS_GENERATION_HAL300, AGX_CS_GENERATION_HAL300, - AGX_CS_GENERATION_HAL300, AGX_CS_GENERATION_HAL300); - return (unsigned)chip < AGX_CHIP_UNKNOWN - ? (enum agx_command_stream_generation)table[chip] - : AGX_CS_GENERATION_UNKNOWN; + return agx_chip_info(chip)->cs_generation; } static inline enum agx_descriptor_generation agx_chip_descriptor_generation(enum agx_chip chip) { - static const uint8_t table[AGX_CHIP_UNKNOWN] = AGX_CHIP_TABLE( - AGX_DESCRIPTOR_GENERATION_7, AGX_DESCRIPTOR_GENERATION_7, - AGX_DESCRIPTOR_GENERATION_8, AGX_DESCRIPTOR_GENERATION_8, - AGX_DESCRIPTOR_GENERATION_UNKNOWN, - AGX_DESCRIPTOR_GENERATION_9, AGX_DESCRIPTOR_GENERATION_9, - AGX_DESCRIPTOR_GENERATION_9, AGX_DESCRIPTOR_GENERATION_9, - AGX_DESCRIPTOR_GENERATION_9, AGX_DESCRIPTOR_GENERATION_9, - AGX_DESCRIPTOR_GENERATION_9, AGX_DESCRIPTOR_GENERATION_9, - AGX_DESCRIPTOR_GENERATION_9, AGX_DESCRIPTOR_GENERATION_9, - AGX_DESCRIPTOR_GENERATION_10, AGX_DESCRIPTOR_GENERATION_10, - AGX_DESCRIPTOR_GENERATION_10, AGX_DESCRIPTOR_GENERATION_10); - return (unsigned)chip < AGX_CHIP_UNKNOWN - ? (enum agx_descriptor_generation)table[chip] - : AGX_DESCRIPTOR_GENERATION_UNKNOWN; + return agx_chip_info(chip)->descriptor_generation; } static inline enum agx_sampler_generation agx_chip_sampler_generation(enum agx_chip chip) { - static const uint8_t table[AGX_CHIP_UNKNOWN] = AGX_CHIP_TABLE( - AGX_SAMPLER_GENERATION_GEN4, AGX_SAMPLER_GENERATION_GEN4, - AGX_SAMPLER_GENERATION_GEN4, AGX_SAMPLER_GENERATION_GEN4, - AGX_SAMPLER_GENERATION_UNKNOWN, - AGX_SAMPLER_GENERATION_GEN4, AGX_SAMPLER_GENERATION_GEN4, - AGX_SAMPLER_GENERATION_GEN4, AGX_SAMPLER_GENERATION_GEN4, - AGX_SAMPLER_GENERATION_GEN4_HAL200, AGX_SAMPLER_GENERATION_GEN4_HAL200, - AGX_SAMPLER_GENERATION_GEN4_HAL200, AGX_SAMPLER_GENERATION_GEN4_HAL200, - AGX_SAMPLER_GENERATION_GEN4_HAL200, AGX_SAMPLER_GENERATION_GEN4_HAL200, - AGX_SAMPLER_GENERATION_GEN5, AGX_SAMPLER_GENERATION_GEN5, - AGX_SAMPLER_GENERATION_GEN5, AGX_SAMPLER_GENERATION_GEN5); - return (unsigned)chip < AGX_CHIP_UNKNOWN - ? (enum agx_sampler_generation)table[chip] - : AGX_SAMPLER_GENERATION_UNKNOWN; + return agx_chip_info(chip)->sampler_generation; } /* Native sampler heap element size. The packed state word remains eight @@ -466,8 +618,11 @@ agx_chip_sampler_heap_element_size(enum agx_chip chip) } } -enum agx_submission_model -agx_chip_submission_model(enum agx_chip chip); +static inline enum agx_submission_model +agx_chip_submission_model(enum agx_chip chip) +{ + return agx_chip_info(chip)->submission_model; +} /* * Whether the native path runs on Apple's G15 command-stream generation @@ -488,7 +643,7 @@ agx_chip_native_g15(enum agx_chip chip) static inline bool agx_chip_has_native_render_context(enum agx_chip chip) { - return chip == AGX_CHIP_G17P; + return agx_chip_info(chip)->quirks & AGX_QUIRK_NATIVE_RENDER_CONTEXT; } /* Whether the native indirect compute pair (grid helper plus the 24-byte @@ -499,9 +654,7 @@ agx_chip_has_native_render_context(enum agx_chip chip) static inline bool agx_chip_native_indirect_compute(enum agx_chip chip) { - return chip == AGX_CHIP_G17P || chip == AGX_CHIP_G15G || - chip == AGX_CHIP_G15S || - chip == AGX_CHIP_G15C || chip == AGX_CHIP_G16G; + return agx_chip_info(chip)->quirks & AGX_QUIRK_NATIVE_INDIRECT_COMPUTE; } /* Whether the CDM's fetch of an indirect geometry block needs a cache flush @@ -520,6 +673,7 @@ agx_chip_indirect_geometry_flush(enum agx_chip chip) * stream with 0x600215fe, not the ordinary flags-5 word that suffices on * HAL200; the kernel's end-of-command flush does not cover dependencies * inside a stream. + * G15 only, unlike AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, which G16G has. */ static inline bool agx_chip_cdm_wide_visibility(enum agx_chip chip) @@ -531,8 +685,29 @@ agx_chip_cdm_wide_visibility(enum agx_chip chip) static inline bool agx_chip_g17_m5(enum agx_chip chip) { - return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G17S || - chip == AGX_CHIP_G17C; + const struct agx_chip_info *info = agx_chip_info(chip); + + return info->encoding == AGX_ISA_ENCODING_AGX3C && + info->cs_generation == AGX_CS_GENERATION_HAL300; +} + +/* + * Whether the Gallium driver takes its M5 paths on this chip: draw admission, + * native descriptors, the VDM/PPP streams and the M5 kernel contract. G18G + * does: its records and texture/PBE descriptors are byte-identical to M5's + * on every J873 native capture (agx_chip_hal300_records), its code is G17G + * code re-encoded (agx_device_key::emit_agx3d), and the chip-specific deltas + * (the tailed non-indexed Index List, the point-size rule) stay keyed on the + * chip inside the record packers. + * + * These are the chips of agx_chip_hal300_records() today. That one says which + * record layouts native captures witness, this one which paths the driver + * runs, and each has its own bit, so that neither widens with the other. + */ +static inline bool +agx_chip_m5_paths(enum agx_chip chip) +{ + return agx_chip_info(chip)->quirks & AGX_QUIRK_M5_PATHS; } /* Whether consecutive application dispatches of one CDM stream may omit the @@ -558,7 +733,7 @@ agx_chip_elide_app_dispatch_barrier(enum agx_chip chip) static inline unsigned agx_chip_usc_helper_table_slots(enum agx_chip chip, unsigned cores_per_cluster) { - if (chip != AGX_CHIP_G17P) + if (!(agx_chip_info(chip)->quirks & AGX_QUIRK_USC_HELPER_SLOT_PER_CORE)) return 10; return cores_per_cluster > 6 ? cores_per_cluster : 6; } @@ -571,7 +746,7 @@ agx_chip_usc_helper_table_slots(enum agx_chip chip, unsigned cores_per_cluster) static inline bool agx_chip_usc_base_page_fill_returns(enum agx_chip chip) { - return chip == AGX_CHIP_G15C; + return agx_chip_info(chip)->quirks & AGX_QUIRK_USC_BASE_PAGE_FILL_RETURNS; } static inline bool @@ -613,7 +788,7 @@ agx_chip_texture_descriptor_spare_word(enum agx_chip chip) static inline bool agx_chip_explicit_robust_image_bounds(enum agx_chip chip) { - return chip == AGX_CHIP_G16G || agx_chip_native_g15(chip); + return agx_chip_info(chip)->quirks & AGX_QUIRK_EXPLICIT_ROBUST_IMAGE_BOUNDS; } /* @@ -624,9 +799,7 @@ agx_chip_explicit_robust_image_bounds(enum agx_chip chip) static inline bool agx_chip_native_imageblock(enum agx_chip chip) { - return chip == AGX_CHIP_G17P || chip == AGX_CHIP_G15G || - chip == AGX_CHIP_G15S || - chip == AGX_CHIP_G15C || chip == AGX_CHIP_G16G; + return agx_chip_info(chip)->quirks & AGX_QUIRK_NATIVE_IMAGEBLOCK; } /* @@ -639,8 +812,7 @@ agx_chip_native_imageblock(enum agx_chip chip) static inline bool agx_chip_uncovered_tile_ms_defect(enum agx_chip chip) { - return chip == AGX_CHIP_G17P || chip == AGX_CHIP_G16G || - agx_chip_native_g15(chip); + return agx_chip_info(chip)->quirks & AGX_QUIRK_UNCOVERED_TILE_MS_DEFECT; } /* @@ -655,7 +827,8 @@ static inline bool agx_chip_uncovered_tile_ms_reload_defect(enum agx_chip chip, uint32_t chip_id, unsigned samples) { - if (chip == AGX_CHIP_G17P && (chip_id == 0x6040 || chip_id == 0x6041) && + if (chip == AGX_CHIP_G17P && + (chip_id == AGX_CHIP_ID_M4_PRO || chip_id == AGX_CHIP_ID_M4_MAX) && samples == 2) return false; return agx_chip_uncovered_tile_ms_defect(chip); @@ -668,7 +841,7 @@ agx_chip_uncovered_tile_ms_reload_defect(enum agx_chip chip, uint32_t chip_id, static inline bool agx_chip_tri_merge_across_side_effects(enum agx_chip chip) { - return chip == AGX_CHIP_G17P; + return agx_chip_info(chip)->quirks & AGX_QUIRK_TRI_MERGE_ACROSS_SIDE_EFFECTS; } /* Whether an image load misses a store made earlier in the same invocation, @@ -677,7 +850,7 @@ agx_chip_tri_merge_across_side_effects(enum agx_chip chip) static inline bool agx_chip_image_load_misses_own_store(enum agx_chip chip) { - return chip == AGX_CHIP_G17P; + return agx_chip_info(chip)->quirks & AGX_QUIRK_IMAGE_LOAD_MISSES_OWN_STORE; } /* Whether native FP32 FFMA meets the exact rounding contract required by @@ -686,7 +859,7 @@ agx_chip_image_load_misses_own_store(enum agx_chip chip) static inline bool agx_chip_exact_fma32(enum agx_chip chip) { - return chip != AGX_CHIP_G16G && !agx_chip_native_g15(chip); + return !(agx_chip_info(chip)->quirks & AGX_QUIRK_INEXACT_FMA32); } /* Whether the sampler state word carries the LOD bias. The HAL200 sampler @@ -706,7 +879,7 @@ agx_chip_sampler_has_lod_bias(enum agx_chip chip) static inline bool agx_chip_native_preamble(enum agx_chip chip) { - return chip == AGX_CHIP_G17P; + return agx_chip_info(chip)->quirks & AGX_QUIRK_NATIVE_PREAMBLE; } /* @@ -788,8 +961,12 @@ agx_chip_cooperative_matrix_supported(enum agx_chip chip) agx_chip_g17_m5(chip); } -/* Stable name for diagnostics, e.g. "G15X". Never NULL. */ -const char *agx_chip_name(enum agx_chip chip); +/* Stable name for diagnostics, e.g. "G15G". Never NULL. */ +static inline const char * +agx_chip_name(enum agx_chip chip) +{ + return agx_chip_info(chip)->name; +} /* Stable name for the instruction set, e.g. "AGX3". Never NULL. */ const char *agx_isa_name(enum agx_isa isa); diff --git a/src/asahi/lib/tests/test-chip.c b/src/asahi/lib/tests/test-chip.c index 5d905597841d..a2bcc0919ec7 100644 --- a/src/asahi/lib/tests/test-chip.c +++ b/src/asahi/lib/tests/test-chip.c @@ -103,6 +103,7 @@ static unsigned checks; ROW(agx_encoding_is_g17_class(agx_chip_isa_encoding(c)), \ "0000 00000 0000 00111 1 0") \ /* Paths. */ \ + ROW(agx_chip_info(c)->path, "1111 02220 0200 20333 3 0") \ ROW(agx_chip_native_agx3(c), "0000 01110 0100 10000 0 0") \ ROW(agx_chip_native_g15(c), "0000 01110 0000 00000 0 0") \ ROW(agx_chip_g17_m5(c), "0000 00000 0000 00111 0 0") \ @@ -602,27 +603,48 @@ test_classification_invariants(void) CHECK(strcmp(agx_isa_name(AGX_ISA_UNKNOWN), "unknown") == 0); } -/* The inline lookups answer every per-draw query; they must match the - * exhaustive reference switches for every identity, including UNKNOWN and - * out-of-range values. */ +/* A record bit of the chip table is what that record's allowlist answers. + * Checked while the allowlists still carry their own chip lists. */ static void -test_inline_lookups_match_reference(void) +test_record_bits_match_allowlists(void) { - for (int chip = AGX_CHIP_G13G; chip <= AGX_CHIP_UNKNOWN + 3; ++chip) { - const enum agx_chip c = (enum agx_chip)chip; - CHECK_EQ(agx_chip_command_stream_generation(c), - agx_chip_command_stream_generation_reference(c)); - CHECK_EQ(agx_chip_descriptor_generation(c), - agx_chip_descriptor_generation_reference(c)); - CHECK_EQ(agx_chip_sampler_generation(c), - agx_chip_sampler_generation_reference(c)); - CHECK_EQ(agx_chip_sampler_heap_element_size(c), - agx_chip_sampler_heap_element_size_reference(c)); + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + const unsigned records = agx_chip_info(c)->records; + +#define RECORD(bit, allowlist) \ + CHECK(!!(records & AGX_RECORD_##bit) == allowlist(c)) + RECORD(VDM_STATE, agx_vdm_state_vertex_pipeline_pair_supported); + RECORD(VDM_PPP_STATE, agx_vdm_ppp_state_core_supported); + RECORD(VDM_BARRIER, agx_vdm_barrier_core_supported); + RECORD(VDM_STREAM_LINK, agx_vdm_stream_link_core_supported); + RECORD(VDM_STREAM_TERMINATE, agx_vdm_stream_terminate_core_supported); + RECORD(VDM_TESSELLATE, agx_vdm_tessellate_direct_target_supported); + RECORD(VDM_INDEX_LIST, + agx_vdm_index_list_direct_target_supported_inline); + RECORD(PPP_HAL300_DEPTH_STENCIL, + agx_ppp_hal300_depth_stencil_core_supported); + RECORD(PPP_HAL300_DEPTH_BIAS_SCISSOR, + agx_ppp_hal300_depth_bias_scissor_core_supported); + RECORD(CDM_LAUNCH, agx3_cdm_launch_target_grounded); + RECORD(CDM_INDIRECT_LAUNCH, agx3_cdm_indirect_launch_target_grounded); + RECORD(CDM_INDIRECT_LAUNCH_36, + agx3_cdm_indirect_launch_36_target_grounded); + RECORD(CDM_STREAM_LINK, agx3_cdm_stream_link_target_grounded); + RECORD(CDM_LINK_PADDING, agx3_cdm_link_padding_target_grounded); + RECORD(CDM_BARRIER, agx3_cdm_barrier_target_grounded); + RECORD(CDM_BARRIER_WIDE_VISIBILITY, + agx3_cdm_barrier_wide_visibility_grounded); + RECORD(CDM_BARRIER_FLUSH_MEMORY, + agx3_cdm_barrier_flush_memory_grounded); + RECORD(CDM_SUBSTREAM_BARRIER, + agx3_cdm_substream_barrier_target_grounded); + RECORD(CDM_SECONDARY_BARRIER, + agx3_cdm_secondary_barrier_target_grounded); + RECORD(IOTO_PROFILE_CONTROL, agx_ioto_profile_control_supported); + RECORD(HAL300_NATIVE_CAPTURE, agx_chip_hal300_records); +#undef RECORD } - CHECK_EQ(agx_chip_command_stream_generation((enum agx_chip)-1), - AGX_CS_GENERATION_UNKNOWN); - CHECK_EQ(agx_chip_descriptor_generation((enum agx_chip)-1), - AGX_DESCRIPTOR_GENERATION_UNKNOWN); } int @@ -635,7 +657,7 @@ main(void) test_params_contracts(); test_invalid_identity(); test_classification_invariants(); - test_inline_lookups_match_reference(); + test_record_bits_match_allowlists(); if (failures) { fprintf(stderr, "agx_chip: %u of %u checks failed\n", failures, checks); From 9be57b6b71e3ec739a8d9e2e4cfe09feca28625e Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:26:02 -0300 Subject: [PATCH 03/13] asahi/decode: take the chip identity, ISA and name from the chip table decode.c had its own copy of agx_chip_from_params(), because the decoder library does not link agx_chip.c, plus a list of the AGX3 chips and a chip name table. Move the generation/variant switch into an inline, agx_chip_from_identity(), that both use. agx_chip_from_params() is that plus its cluster-count check. The decoder's AGX3 list was every chip whose instruction set is AGX3, so it asks agx_chip_isa(). The copy had diverged, and the differences are kept: - It maps gpu_generation 16, variant 'X', chip id 0x6041 on the G17 runtime to G17P. agx_chip_from_params() accepted 'X' in 53b30c6ae and dropped it three days later in b45e4ec54 ("drop legacy T6041 X and upstream UAPI compatibility"), with a test that 'X' is unknown. cea3f4dec then added 'X' to the decoder, and its message says agx_chip_from_params() maps "variant C or X", which was no longer true. So device open is right to refuse 'X', and the decoder still accepts it: a trace from a kernel that names the M4 Max that way decodes as G17P. Whether it should is a separate change. - It has no cluster-count check and takes NULL parameters as unknown. Old and new mapping agree on 184,320 identities (generation 11-20, every 7-bit variant, six chip ids, USC 2/3, three HAL generations, four cluster counts), and on NULL. The truth table's decoder row and test_decoder_identity() pass unedited. One difference between the removed helpers and the shared ones cannot be reached. agxdecode_chip_name() said "unknown" for G13G, G13X, G14G, G14X and G15P, and agx_chip_name() names them. All five calls print the chip in a message of an AGX3 decoder: - agxdecode_cdm_agx3() (two calls) and agxdecode_vdm_agx3(), which agxdecode_cdm() and agxdecode_vdm() enter only when the chip's instruction set is AGX3; - agxdecode_ppp_agx3(), which only agxdecode_vdm_agx3() calls; - agxdecode_ioto(), the pipeline decoder of those two and of agxdecode_drm_cmd_render() for a native AGX3 chip or G18G. Those five chips execute AGX2, so none of them gets to a call and no output changes. AGX_CHIP_UNKNOWN is "unknown" under both names. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/lib/agx_chip.c | 85 +----------------------- src/asahi/lib/agx_chip.h | 99 ++++++++++++++++++++++++++++ src/asahi/lib/decode.c | 135 +++++---------------------------------- 3 files changed, 117 insertions(+), 202 deletions(-) diff --git a/src/asahi/lib/agx_chip.c b/src/asahi/lib/agx_chip.c index 80e922fa3047..0aaba3335e00 100644 --- a/src/asahi/lib/agx_chip.c +++ b/src/asahi/lib/agx_chip.c @@ -16,90 +16,7 @@ agx_chip_from_params(const struct drm_asahi_params_global *params) params->num_clusters_total > DRM_ASAHI_MAX_CLUSTERS) return AGX_CHIP_UNKNOWN; - /* These are command-stream architecture identities, not an ordering. - * - * Generations 15 and up are recognised so diagnostics can name the part and - * its command-stream generation. agx_chip_driver_supported decides whether - * the driver proceeds; agx_chip_codegen_supported covers only the shader - * packer. - * - * The variant character is load-bearing. Cluster count cannot distinguish - * G17P (A18 Pro, AGX3b) from G17G (M5, AGX3c), and G15P is an AGX2 part in - * the same numeric generation as AGX3 M3. The kernel already publishes the - * exact P/G/S/C/D/A character, so use it directly. - */ - switch (params->gpu_generation) { - case 13: - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G13G; - case 'S': - case 'C': - case 'D': return AGX_CHIP_G13X; - default: return AGX_CHIP_UNKNOWN; - } - case 14: - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G14G; - case 'S': - case 'C': - case 'D': return AGX_CHIP_G14X; - default: return AGX_CHIP_UNKNOWN; - } - case 15: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G15P; - case 'G': return AGX_CHIP_G15G; - case 'S': return AGX_CHIP_G15S; - case 'C': return AGX_CHIP_G15C; - case 'D': return AGX_CHIP_G15D; - default: return AGX_CHIP_UNKNOWN; - } - case 16: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G16P; - case 'G': return AGX_CHIP_G16G; - case 'S': - /* The M4 Pro (T6040) on the G17 kernel runtime takes the A18 Pro's - * contract: its firmware has the A18 Pro firmware's interface, and - * every G16S axis in these tables (AGX3B, HAL200, Gen9, Gen4-HAL200, - * 32-byte sampler heap, dual submission) equals G17P's. The M4 Max - * (T6041) below takes it for the same reason. G17P therefore names - * the AGX3B + HAL200 profile of three SoCs, not the A18 Pro alone: - * a performance gate on it needs rows on those parts (see enum - * agx_chip). - */ - if (params->chip_id == AGX_CHIP_ID_M4_PRO && - params->usc_generation == AGX_ISA_AGX3 && - params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) - return AGX_CHIP_G17P; - return AGX_CHIP_G16S; - case 'C': - if (params->chip_id == AGX_CHIP_ID_M4_MAX && - params->usc_generation == AGX_ISA_AGX3 && - params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) - return AGX_CHIP_G17P; - return AGX_CHIP_G16C; - default: return AGX_CHIP_UNKNOWN; - } - case 17: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G17P; - case 'A': return AGX_CHIP_G17A; - case 'G': return AGX_CHIP_G17G; - case 'S': return AGX_CHIP_G17S; - case 'C': return AGX_CHIP_G17C; - default: return AGX_CHIP_UNKNOWN; - } - case 18: - /* Only the M6 base part has been observed. G18M and G19P share its - * shader encoding but nothing else about them is known. */ - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G18G; - default: return AGX_CHIP_UNKNOWN; - } - default: - return AGX_CHIP_UNKNOWN; - } + return agx_chip_from_identity(params); } bool diff --git a/src/asahi/lib/agx_chip.h b/src/asahi/lib/agx_chip.h index b42de0996fb1..9af1a4b78c4c 100644 --- a/src/asahi/lib/agx_chip.h +++ b/src/asahi/lib/agx_chip.h @@ -554,6 +554,105 @@ agx_isa_is_agx3(enum agx_isa_encoding enc) #define AGX_CHIP_ID_M4_PRO 0x6040 #define AGX_CHIP_ID_M4_MAX 0x6041 +/* Whether the kernel runs the SoC with this chip id on its G17 runtime: AGX3 + * shaders behind the HAL200 firmware interface. */ +static inline bool +agx_params_g17_runtime(const struct drm_asahi_params_global *params, + uint32_t chip_id) +{ + return params->chip_id == chip_id && + params->usc_generation == AGX_ISA_AGX3 && + params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200; +} + +/* The chip the kernel's generation and variant name. agx_chip_from_params() + * is this plus the checks device open needs; the command-stream decoder, + * which does not link agx_chip.c, uses it directly. */ +static inline enum agx_chip +agx_chip_from_identity(const struct drm_asahi_params_global *params) +{ + /* These are command-stream architecture identities, not an ordering. + * + * Generations 15 and up are recognised so diagnostics can name the part and + * its command-stream generation. agx_chip_driver_supported decides whether + * the driver proceeds; agx_chip_codegen_supported covers only the shader + * packer. + * + * The variant character is load-bearing. Cluster count cannot distinguish + * G17P (A18 Pro, AGX3b) from G17G (M5, AGX3c), and G15P is an AGX2 part in + * the same numeric generation as AGX3 M3. The kernel already publishes the + * exact P/G/S/C/D/A character, so use it directly. + */ + switch (params->gpu_generation) { + case 13: + switch (params->gpu_variant) { + case 'G': return AGX_CHIP_G13G; + case 'S': + case 'C': + case 'D': return AGX_CHIP_G13X; + default: return AGX_CHIP_UNKNOWN; + } + case 14: + switch (params->gpu_variant) { + case 'G': return AGX_CHIP_G14G; + case 'S': + case 'C': + case 'D': return AGX_CHIP_G14X; + default: return AGX_CHIP_UNKNOWN; + } + case 15: + switch (params->gpu_variant) { + case 'P': return AGX_CHIP_G15P; + case 'G': return AGX_CHIP_G15G; + case 'S': return AGX_CHIP_G15S; + case 'C': return AGX_CHIP_G15C; + case 'D': return AGX_CHIP_G15D; + default: return AGX_CHIP_UNKNOWN; + } + case 16: + switch (params->gpu_variant) { + case 'P': return AGX_CHIP_G16P; + case 'G': return AGX_CHIP_G16G; + case 'S': + /* The M4 Pro (T6040) on the G17 kernel runtime takes the A18 Pro's + * contract: its firmware has the A18 Pro firmware's interface, and + * every G16S axis in these tables (AGX3B, HAL200, Gen9, Gen4-HAL200, + * 32-byte sampler heap, dual submission) equals G17P's. The M4 Max + * (T6041) below takes it for the same reason. G17P therefore names + * the AGX3B + HAL200 profile of three SoCs, not the A18 Pro alone: + * a performance gate on it needs rows on those parts (see enum + * agx_chip). + */ + if (agx_params_g17_runtime(params, AGX_CHIP_ID_M4_PRO)) + return AGX_CHIP_G17P; + return AGX_CHIP_G16S; + case 'C': + if (agx_params_g17_runtime(params, AGX_CHIP_ID_M4_MAX)) + return AGX_CHIP_G17P; + return AGX_CHIP_G16C; + default: return AGX_CHIP_UNKNOWN; + } + case 17: + switch (params->gpu_variant) { + case 'P': return AGX_CHIP_G17P; + case 'A': return AGX_CHIP_G17A; + case 'G': return AGX_CHIP_G17G; + case 'S': return AGX_CHIP_G17S; + case 'C': return AGX_CHIP_G17C; + default: return AGX_CHIP_UNKNOWN; + } + case 18: + /* Only the M6 base part has been observed. G18M and G19P share its + * shader encoding but nothing else about them is known. */ + switch (params->gpu_variant) { + case 'G': return AGX_CHIP_G18G; + default: return AGX_CHIP_UNKNOWN; + } + default: + return AGX_CHIP_UNKNOWN; + } +} + #ifdef __cplusplus extern "C" { #endif diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index 8936a5afdf7a..317c7707d4bb 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -182,125 +182,24 @@ typedef struct drm_asahi_params_global decoder_params; /* Keep command-stream selection on the kernel's explicit generation/variant * identity. Cluster count cannot distinguish A18 Pro (G17P/AGX3b) from M5 - * (G17G/AGX3c), and must never be used as an architecture proxy. This local - * form avoids making the standalone decoder library depend on libasahi_lib; - * agx_chip_from_params() is the equivalent device-open mapping. */ + * (G17G/AGX3c), and must never be used as an architecture proxy. + * + * This is agx_chip_from_params() without device open's cluster-count check, + * and with one more identity: a trace that names the M4 Max by variant 'X' + * decodes as G17P. Device open refuses that variant. */ enum agx_chip agxdecode_chip_from_params(const decoder_params *params) { if (!params) return AGX_CHIP_UNKNOWN; - switch (params->gpu_generation) { - case 13: - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G13G; - case 'S': - case 'C': - case 'D': return AGX_CHIP_G13X; - default: return AGX_CHIP_UNKNOWN; - } - case 14: - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G14G; - case 'S': - case 'C': - case 'D': return AGX_CHIP_G14X; - default: return AGX_CHIP_UNKNOWN; - } - case 15: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G15P; - case 'G': return AGX_CHIP_G15G; - case 'S': return AGX_CHIP_G15S; - case 'C': return AGX_CHIP_G15C; - case 'D': return AGX_CHIP_G15D; - default: return AGX_CHIP_UNKNOWN; - } - case 16: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G16P; - case 'G': return AGX_CHIP_G16G; - case 'S': - /* As agx_chip_from_params(): the M4 Pro on the G17 runtime is G17P. */ - if (params->chip_id == 0x6040 && - params->usc_generation == AGX_ISA_AGX3 && - params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) - return AGX_CHIP_G17P; - return AGX_CHIP_G16S; - case 'C': - case 'X': - /* As agx_chip_from_params(): the M4 Max on the G17 runtime is G17P. */ - if (params->chip_id == 0x6041 && - params->usc_generation == AGX_ISA_AGX3 && - params->gpu_hal_generation == DRM_ASAHI_GPU_HAL_200) - return AGX_CHIP_G17P; - return params->gpu_variant == 'C' ? AGX_CHIP_G16C : AGX_CHIP_UNKNOWN; - default: return AGX_CHIP_UNKNOWN; - } - case 17: - switch (params->gpu_variant) { - case 'P': return AGX_CHIP_G17P; - case 'A': return AGX_CHIP_G17A; - case 'G': return AGX_CHIP_G17G; - case 'S': return AGX_CHIP_G17S; - case 'C': return AGX_CHIP_G17C; - default: return AGX_CHIP_UNKNOWN; - } - case 18: - switch (params->gpu_variant) { - case 'G': return AGX_CHIP_G18G; - default: return AGX_CHIP_UNKNOWN; - } - default: - return AGX_CHIP_UNKNOWN; + if (params->gpu_generation == 16 && params->gpu_variant == 'X') { + return agx_params_g17_runtime(params, AGX_CHIP_ID_M4_MAX) + ? AGX_CHIP_G17P + : AGX_CHIP_UNKNOWN; } -} - -static bool -agxdecode_chip_uses_agx3(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - default: - return false; - } -} -static const char * -agxdecode_chip_name(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G15G: return "G15G"; - case AGX_CHIP_G15S: return "G15S"; - case AGX_CHIP_G15C: return "G15C"; - case AGX_CHIP_G15D: return "G15D"; - case AGX_CHIP_G16P: return "G16P"; - case AGX_CHIP_G16G: return "G16G"; - case AGX_CHIP_G16S: return "G16S"; - case AGX_CHIP_G16C: return "G16C"; - case AGX_CHIP_G17P: return "G17P"; - case AGX_CHIP_G17A: return "G17A"; - case AGX_CHIP_G17G: return "G17G"; - case AGX_CHIP_G17S: return "G17S"; - case AGX_CHIP_G17C: return "G17C"; - case AGX_CHIP_G18G: return "G18G"; - default: return "unknown"; - } + return agx_chip_from_identity(params); } /* Abstraction for command stream parsing */ @@ -737,7 +636,7 @@ agxdecode_ioto(UNUSED struct agxdecode_ctx *ctx, const uint8_t *map, &consumed)) { fprintf(agxdecode_dump_stream, "Unknown or non-canonical AGX3 Ioto record for %s\n", - agxdecode_chip_name(chip)); + agx_chip_name(chip)); return STATE_ERROR; } @@ -787,7 +686,7 @@ agxdecode_cdm_agx3(struct agxdecode_ctx *ctx, const uint8_t *map, if (!agx3_cdm_direct_launch_unpack(chip, map, available, &direct)) { fprintf(agxdecode_dump_stream, "Note: AGX3 launch is not the canonical direct form for %s\n", - agxdecode_chip_name(chip)); + agx_chip_name(chip)); u_hexdump(agxdecode_dump_stream, map, MIN2(available, (size_t)AGX3_CDM_DIRECT_LAUNCH_SIZE), false); } @@ -796,7 +695,7 @@ agxdecode_cdm_agx3(struct agxdecode_ctx *ctx, const uint8_t *map, if (!agx3_cdm_decode_one(chip, map, available, &record)) { fprintf(agxdecode_dump_stream, "Unknown or non-canonical AGX3 CDM record for %s\n", - agxdecode_chip_name(chip)); + agx_chip_name(chip)); return STATE_ERROR; } @@ -906,7 +805,7 @@ agxdecode_cdm(struct agxdecode_ctx *ctx, const uint8_t *map, decoder_params *params, UNUSED void *data) { const enum agx_chip chip = agxdecode_chip_from_params(params); - if (agxdecode_chip_uses_agx3(chip)) + if (agx_chip_isa(chip) == AGX_ISA_AGX3) return agxdecode_cdm_agx3(ctx, map, available, link, verbose, params, chip); @@ -1020,7 +919,7 @@ agxdecode_ppp_agx3(struct agxdecode_ctx *ctx, enum agx_chip chip, uint64_t va, fprintf(agxdecode_dump_stream, "Unsupported or non-canonical AGX3 PPP payload for %s " "(%zu bytes)\n", - agxdecode_chip_name(chip), size); + agx_chip_name(chip), size); if (verbose) u_hexdump(agxdecode_dump_stream, payload, size, false); return; @@ -1097,7 +996,7 @@ agxdecode_vdm_agx3(struct agxdecode_ctx *ctx, const uint8_t *map, if (!agx_vdm_decode_one(chip, map, available, &record)) { fprintf(agxdecode_dump_stream, "Unknown or non-canonical AGX3 VDM record for %s\n", - agxdecode_chip_name(chip)); + agx_chip_name(chip)); return STATE_ERROR; } @@ -1284,7 +1183,7 @@ agxdecode_vdm(struct agxdecode_ctx *ctx, const uint8_t *map, decoder_params *params, UNUSED void *data) { const enum agx_chip chip = agxdecode_chip_from_params(params); - if (agxdecode_chip_uses_agx3(chip)) + if (agx_chip_isa(chip) == AGX_ISA_AGX3) return agxdecode_vdm_agx3(ctx, map, available, link, verbose, params, chip); From c201d4f27fd645658ba61f3e58f69693df5d5340 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:26:02 -0300 Subject: [PATCH 04/13] asahi: read the descriptor generation from the chip table agx_gallium_descriptor_generation() was a fourth copy of the per-chip descriptor generation, with the same answer as agx_chip_descriptor_generation() for all 19 chips and AGX_CHIP_UNKNOWN. Its sixteen callers use the shared accessor. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216, and the gallium driver builds. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- .../drivers/asahi/agx_native_descriptor.h | 38 ------------------- src/gallium/drivers/asahi/agx_pipe.c | 4 +- src/gallium/drivers/asahi/agx_state.c | 20 +++++----- .../asahi/tests/test-agx-native-descriptor.c | 8 ++-- 4 files changed, 16 insertions(+), 54 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_native_descriptor.h b/src/gallium/drivers/asahi/agx_native_descriptor.h index a50773aec358..0835a07b15aa 100644 --- a/src/gallium/drivers/asahi/agx_native_descriptor.h +++ b/src/gallium/drivers/asahi/agx_native_descriptor.h @@ -63,44 +63,6 @@ struct agx_gallium_storage_descriptor_layout { uint8_t stride; }; -/* G15P/A16 executes AGX2, but its complete descriptor/command-stream ABI is - * not grounded. Keep it UNKNOWN here just like the shared chip policy. - */ -static inline enum agx_descriptor_generation -agx_gallium_descriptor_generation(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - return AGX_DESCRIPTOR_GENERATION_7; - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - return AGX_DESCRIPTOR_GENERATION_8; - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16P: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17A: - return AGX_DESCRIPTOR_GENERATION_9; - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - /* The J873 native captures carry Gen10 texture and PBE descriptors that - * Mesa's G17G packers reproduce byte for byte. */ - case AGX_CHIP_G18G: - return AGX_DESCRIPTOR_GENERATION_10; - case AGX_CHIP_G15P: - case AGX_CHIP_UNKNOWN: - default: - return AGX_DESCRIPTOR_GENERATION_UNKNOWN; - } -} - static inline bool agx_gallium_descriptor_generation_is_agx2( enum agx_descriptor_generation generation) diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 911aba30d98d..5bb9dcbd5347 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -484,7 +484,7 @@ agx_compression_allowed(const struct agx_resource *pres) { const struct agx_device *dev = agx_device(pres->base.screen); const enum agx_descriptor_generation generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); /* Allow disabling compression for debugging */ if (dev->debug & AGX_DBG_NOCOMPRESS) { @@ -2918,7 +2918,7 @@ agx_dmabuf_modifier_external_only(struct pipe_screen *screen, uint64_t modifier) */ return modifier == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED && !agx_gallium_shared_compression_supported( - agx_gallium_descriptor_generation(agx_device(screen)->chip)); + agx_chip_descriptor_generation(agx_device(screen)->chip)); } static void diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 430568a0d1ba..0bebcaf7ca5f 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -2026,7 +2026,7 @@ agx_batch_upload_pbe_internal(struct agx_batch *batch, { struct agx_device *dev = agx_device(batch->ctx->base.screen); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); const unsigned descriptor_size = agx_gallium_pbe_descriptor_size(descriptor_generation); @@ -2737,7 +2737,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, dev->chip == AGX_CHIP_G18G && stage == MESA_SHADER_COMPUTE && agx_nir_lower_g17p_gallium_storage_write(nir, 1); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); const unsigned texture_descriptor_size = agx_gallium_texture_descriptor_size(descriptor_generation); if (!texture_descriptor_size) @@ -3450,7 +3450,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, * agx_g17p_fill_storage_tail() writes. */ /* G18G adds AGX_NIR_TEXTURE_GENERATION_G18G to keep its own forms. */ NIR_PASS(_, nir, agx_nir_lower_multisampled_image_store_for_generation, - agx_gallium_descriptor_generation(dev->chip) | + agx_chip_descriptor_generation(dev->chip) | (dev->chip == AGX_CHIP_G18G ? AGX_NIR_TEXTURE_GENERATION_G18G : 0)); @@ -4066,7 +4066,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, }); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); if (agx_native_graphics(dev)) { /* Texel fetches get G17P's explicit out-of-view predicate only in @@ -5901,7 +5901,7 @@ agx_upload_textures(struct agx_batch *batch, struct agx_compiled_shader *cs, struct agx_device *dev = agx_device(ctx->base.screen); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); const unsigned descriptor_size = agx_gallium_texture_descriptor_size(descriptor_generation); if (!descriptor_size) @@ -9664,7 +9664,7 @@ agx_g17p_build_mixed_bg_eot(struct agx_batch *batch, struct agx_context *ctx = batch->ctx; struct agx_device *dev = agx_device(ctx->base.screen); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); const unsigned descriptor_size = agx_gallium_texture_descriptor_size(descriptor_generation); const unsigned samples = MAX2(framebuffer_key->tib.nr_samples, 1); @@ -10152,7 +10152,7 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) struct agx_context *ctx = batch->ctx; struct agx_device *dev = agx_device(ctx->base.screen); const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); const unsigned descriptor_size = agx_gallium_texture_descriptor_size(descriptor_generation); if (!descriptor_size) @@ -15010,7 +15010,7 @@ agx_g17g_mrt_spills_encodable(struct agx_context *ctx) { struct agx_device *dev = agx_device(ctx->base.screen); const enum agx_descriptor_generation generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); /* The packers only read the device through the batch. */ struct agx_batch scratch = {.ctx = ctx}; @@ -16354,7 +16354,7 @@ agx_launch(struct agx_batch *batch, struct agx_grid grid, const bool g18g = dev->chip == AGX_CHIP_G18G; const unsigned descriptor_size = agx_gallium_texture_descriptor_size( - agx_gallium_descriptor_generation(dev->chip)); + agx_chip_descriptor_generation(dev->chip)); const uint64_t write_control = agx_pool_upload_aligned( &batch->pool, g18g ? agx_g18g_native_write_state1 @@ -16874,7 +16874,7 @@ agx_decompress_inplace(struct agx_batch *batch, struct pipe_surface *surf, struct ail_layout *layout = &rsrc->layout; unsigned level = surf->level; const enum agx_descriptor_generation descriptor_generation = - agx_gallium_descriptor_generation(dev->chip); + agx_chip_descriptor_generation(dev->chip); perf_debug(dev, "Decompressing in-place due to: %s", reason); diff --git a/src/gallium/drivers/asahi/tests/test-agx-native-descriptor.c b/src/gallium/drivers/asahi/tests/test-agx-native-descriptor.c index 9d77d9e3d399..a5d5b17c7b05 100644 --- a/src/gallium/drivers/asahi/tests/test-agx-native-descriptor.c +++ b/src/gallium/drivers/asahi/tests/test-agx-native-descriptor.c @@ -56,7 +56,7 @@ test_chip_routing(void) for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { const enum agx_descriptor_generation generation = - agx_gallium_descriptor_generation(cases[i].chip); + agx_chip_descriptor_generation(cases[i].chip); CHECK(generation == cases[i].generation); CHECK(agx_gallium_texture_descriptor_size(generation) == cases[i].size); CHECK(agx_gallium_pbe_descriptor_size(generation) == cases[i].size); @@ -68,12 +68,12 @@ test_chip_routing(void) CHECK(storage.stride == 2 * cases[i].size); } - CHECK(agx_gallium_descriptor_generation(AGX_CHIP_UNKNOWN) == + CHECK(agx_chip_descriptor_generation(AGX_CHIP_UNKNOWN) == AGX_DESCRIPTOR_GENERATION_UNKNOWN); - CHECK(agx_gallium_descriptor_generation(AGX_CHIP_G15P) == + CHECK(agx_chip_descriptor_generation(AGX_CHIP_G15P) == AGX_DESCRIPTOR_GENERATION_UNKNOWN); CHECK(agx_gallium_storage_descriptor_layout( - agx_gallium_descriptor_generation(AGX_CHIP_G15P)) + agx_chip_descriptor_generation(AGX_CHIP_G15P)) .stride == 0); CHECK(agx_gallium_texture_descriptor_size( AGX_DESCRIPTOR_GENERATION_UNKNOWN) == 0); From 88c983660c3548d0ad3b4d8bf8f4d40df410327b Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:26:02 -0300 Subject: [PATCH 05/13] agx: read the per-record chip allowlists from the chip table Twenty record codecs in lib/*_core.[ch] and genxml/agx3_cmdstream.h each carried the list of chips they accept: the same twelve chips ten times, and five times the same list without G18G. Each now reads its own bit of the chip's row through agx_chip_has_record(). The lists that disagree keep disagreeing, because every record has its own bit. For G18G the VDM stream link, tessellate and direct Index List records, the CDM stream link, link padding and substream barrier and the Ioto profile control stay refused, as the truth table in tests/test-chip.c shows row by row. Whether G18G should take them is for someone with the hardware. agx_vdm_index_list_direct_target_supported_inline() is compiled into the libagx kernels. Under OpenCL C agx_chip_has_record() expands to the comparisons of the chips that have the bit, and the precompiled kernels are byte-identical to those built from b8762aab9. Left as they are: agx_ppp_viewport_payload_core_supported() and agx_ioto_target_supported(), which answer through a layout or encoding selector and have no list of their own, and agx_ppp_legacy_payload_supported() and agx_ppp_hal200_graphics_core_supported(), which already ask a chip predicate. The test that checked each bit against its allowlist goes; the truth table rows are unedited. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/genxml/agx3_cmdstream.h | 109 ++---------------- src/asahi/lib/agx_ioto_profile_core.c | 17 +-- .../agx_ppp_hal300_depth_bias_scissor_core.c | 11 +- .../lib/agx_ppp_hal300_depth_stencil_core.c | 11 +- src/asahi/lib/agx_vdm_barrier_core.c | 27 +---- src/asahi/lib/agx_vdm_index_list_core.h | 17 +-- src/asahi/lib/agx_vdm_ppp_state_core.c | 27 +---- src/asahi/lib/agx_vdm_state_core.c | 27 +---- src/asahi/lib/agx_vdm_stream_link_core.c | 29 +---- src/asahi/lib/agx_vdm_stream_terminate_core.c | 27 +---- src/asahi/lib/agx_vdm_tessellate_core.c | 29 +---- src/asahi/lib/tests/test-chip.c | 45 -------- 12 files changed, 22 insertions(+), 354 deletions(-) diff --git a/src/asahi/genxml/agx3_cmdstream.h b/src/asahi/genxml/agx3_cmdstream.h index 2dd74ef84f81..90d8a8d5c0c4 100644 --- a/src/asahi/genxml/agx3_cmdstream.h +++ b/src/asahi/genxml/agx3_cmdstream.h @@ -134,23 +134,7 @@ agx3_cmdstream_load_le32(const uint8_t *src) static inline bool agx3_cdm_launch_target_grounded(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_LAUNCH); } /* Kept separate from the 40-byte direct-launch gate so later evidence for one @@ -159,25 +143,9 @@ agx3_cdm_launch_target_grounded(enum agx_chip chip) static inline bool agx3_cdm_indirect_launch_target_grounded(enum agx_chip chip) { - switch (chip) { /* G18G: the same six-word launch; the template's upper half of word 4 * is 0. */ - case AGX_CHIP_G18G: - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_INDIRECT_LAUNCH); } /* Keep the nine-word family independently gated: its presence was checked @@ -186,24 +154,8 @@ agx3_cdm_indirect_launch_target_grounded(enum agx_chip chip) static inline bool agx3_cdm_indirect_launch_36_target_grounded(enum agx_chip chip) { - switch (chip) { /* G18G: the same nine-word launch. */ - case AGX_CHIP_G18G: - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_INDIRECT_LAUNCH_36); } /* The 48-bit link form holds in every scoped base and aggregate family. @@ -212,22 +164,7 @@ agx3_cdm_indirect_launch_36_target_grounded(enum agx_chip chip) static inline bool agx3_cdm_stream_link_target_grounded(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_STREAM_LINK); } static inline bool @@ -524,7 +461,7 @@ agx3_cdm_stream_link_unpack( static inline bool agx3_cdm_link_padding_target_grounded(enum agx_chip chip) { - return chip != AGX_CHIP_G18G && agx3_cdm_launch_target_grounded(chip); + return agx_chip_has_record(chip, AGX_RECORD_CDM_LINK_PADDING); } static inline bool @@ -579,23 +516,7 @@ agx3_cdm_link_padding_unpack( static inline bool agx3_cdm_barrier_target_grounded(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_BARRIER); } static inline bool @@ -627,8 +548,7 @@ agx3_cdm_barrier_wide_visibility_grounded(enum agx_chip chip) { /* G15C (M3 Max) is G15S's generation with more clusters and takes the * same forms. */ - return chip == AGX_CHIP_G15G || chip == AGX_CHIP_G15S || - chip == AGX_CHIP_G15C || chip == AGX_CHIP_G16G; + return agx_chip_has_record(chip, AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY); } #define AGX3_CDM_BARRIER_WIDE_VISIBILITY UINT32_C(0x0002009e) @@ -655,15 +575,7 @@ agx3_cdm_barrier_wide_visibility_grounded(enum agx_chip chip) static inline bool agx3_cdm_barrier_flush_memory_grounded(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY); } static inline uint32_t @@ -786,7 +698,7 @@ agx3_cdm_sstt_flush_invalidate_validate(enum agx_chip chip, static inline bool agx3_cdm_substream_barrier_target_grounded(enum agx_chip chip) { - return chip != AGX_CHIP_G18G && agx3_cdm_barrier_target_grounded(chip); + return agx_chip_has_record(chip, AGX_RECORD_CDM_SUBSTREAM_BARRIER); } static inline bool @@ -847,8 +759,7 @@ agx3_cdm_substream_barrier_unpack( static inline bool agx3_cdm_secondary_barrier_target_grounded(enum agx_chip chip) { - return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G17S || - chip == AGX_CHIP_G17C; + return agx_chip_has_record(chip, AGX_RECORD_CDM_SECONDARY_BARRIER); } static inline bool diff --git a/src/asahi/lib/agx_ioto_profile_core.c b/src/asahi/lib/agx_ioto_profile_core.c index 052d2204cd3d..96b3a76a42d3 100644 --- a/src/asahi/lib/agx_ioto_profile_core.c +++ b/src/asahi/lib/agx_ioto_profile_core.c @@ -36,22 +36,7 @@ is_hal300(enum agx_chip chip) bool agx_ioto_profile_control_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_IOTO_PROFILE_CONTROL); } size_t diff --git a/src/asahi/lib/agx_ppp_hal300_depth_bias_scissor_core.c b/src/asahi/lib/agx_ppp_hal300_depth_bias_scissor_core.c index 4cd13dcac947..f86446bd5870 100644 --- a/src/asahi/lib/agx_ppp_hal300_depth_bias_scissor_core.c +++ b/src/asahi/lib/agx_ppp_hal300_depth_bias_scissor_core.c @@ -37,16 +37,7 @@ unpack_base(const uint8_t *src, uint64_t *base) bool agx_ppp_hal300_depth_bias_scissor_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_PPP_HAL300_DEPTH_BIAS_SCISSOR); } bool diff --git a/src/asahi/lib/agx_ppp_hal300_depth_stencil_core.c b/src/asahi/lib/agx_ppp_hal300_depth_stencil_core.c index d6a15f435c7e..25fcf2d1b3d7 100644 --- a/src/asahi/lib/agx_ppp_hal300_depth_stencil_core.c +++ b/src/asahi/lib/agx_ppp_hal300_depth_stencil_core.c @@ -31,16 +31,7 @@ bool agx_ppp_hal300_depth_stencil_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_PPP_HAL300_DEPTH_STENCIL); } bool diff --git a/src/asahi/lib/agx_vdm_barrier_core.c b/src/asahi/lib/agx_vdm_barrier_core.c index 5e3864694a54..74988de87906 100644 --- a/src/asahi/lib/agx_vdm_barrier_core.c +++ b/src/asahi/lib/agx_vdm_barrier_core.c @@ -25,33 +25,8 @@ bool agx_vdm_barrier_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: /* G18G memory barriers use the same word. */ - case AGX_CHIP_G18G: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_VDM_BARRIER); } bool diff --git a/src/asahi/lib/agx_vdm_index_list_core.h b/src/asahi/lib/agx_vdm_index_list_core.h index 5eeb7508a8aa..b73b99f33da7 100644 --- a/src/asahi/lib/agx_vdm_index_list_core.h +++ b/src/asahi/lib/agx_vdm_index_list_core.h @@ -119,22 +119,7 @@ struct agx_vdm_index_list_indirect_words { static inline bool agx_vdm_index_list_direct_target_supported_inline(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_VDM_INDEX_LIST); } static inline bool diff --git a/src/asahi/lib/agx_vdm_ppp_state_core.c b/src/asahi/lib/agx_vdm_ppp_state_core.c index 38d47a8e44d9..e0cdce188f7c 100644 --- a/src/asahi/lib/agx_vdm_ppp_state_core.c +++ b/src/asahi/lib/agx_vdm_ppp_state_core.c @@ -11,32 +11,7 @@ bool agx_vdm_ppp_state_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_VDM_PPP_STATE); } bool diff --git a/src/asahi/lib/agx_vdm_state_core.c b/src/asahi/lib/agx_vdm_state_core.c index 2514c2965433..7410dfa438ff 100644 --- a/src/asahi/lib/agx_vdm_state_core.c +++ b/src/asahi/lib/agx_vdm_state_core.c @@ -11,32 +11,7 @@ bool agx_vdm_state_vertex_pipeline_pair_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_VDM_STATE); } bool diff --git a/src/asahi/lib/agx_vdm_stream_link_core.c b/src/asahi/lib/agx_vdm_stream_link_core.c index 23f76e5ccd7e..f22a4b0de52b 100644 --- a/src/asahi/lib/agx_vdm_stream_link_core.c +++ b/src/asahi/lib/agx_vdm_stream_link_core.c @@ -34,33 +34,8 @@ bool agx_vdm_stream_link_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - /* No J873 native capture contains this record yet. */ - case AGX_CHIP_G18G: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + /* G18G: no J873 native capture contains this record yet. */ + return agx_chip_has_record(chip, AGX_RECORD_VDM_STREAM_LINK); } bool diff --git a/src/asahi/lib/agx_vdm_stream_terminate_core.c b/src/asahi/lib/agx_vdm_stream_terminate_core.c index 58a65f7b8d89..80f7b1dca4f2 100644 --- a/src/asahi/lib/agx_vdm_stream_terminate_core.c +++ b/src/asahi/lib/agx_vdm_stream_terminate_core.c @@ -23,32 +23,7 @@ bool agx_vdm_stream_terminate_core_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + return agx_chip_has_record(chip, AGX_RECORD_VDM_STREAM_TERMINATE); } bool diff --git a/src/asahi/lib/agx_vdm_tessellate_core.c b/src/asahi/lib/agx_vdm_tessellate_core.c index 043886fa0839..e9e21b1ac46f 100644 --- a/src/asahi/lib/agx_vdm_tessellate_core.c +++ b/src/asahi/lib/agx_vdm_tessellate_core.c @@ -34,33 +34,8 @@ agx_vdm_tessellate_store_le32(uint8_t *dst, uint32_t value) bool agx_vdm_tessellate_direct_target_supported(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: - case AGX_CHIP_G16P: - case AGX_CHIP_G17A: - /* No J873 native capture contains this record yet. */ - case AGX_CHIP_G18G: - case AGX_CHIP_UNKNOWN: - default: - return false; - } + /* G18G: no J873 native capture contains this record yet. */ + return agx_chip_has_record(chip, AGX_RECORD_VDM_TESSELLATE); } bool diff --git a/src/asahi/lib/tests/test-chip.c b/src/asahi/lib/tests/test-chip.c index a2bcc0919ec7..29a14961c249 100644 --- a/src/asahi/lib/tests/test-chip.c +++ b/src/asahi/lib/tests/test-chip.c @@ -603,50 +603,6 @@ test_classification_invariants(void) CHECK(strcmp(agx_isa_name(AGX_ISA_UNKNOWN), "unknown") == 0); } -/* A record bit of the chip table is what that record's allowlist answers. - * Checked while the allowlists still carry their own chip lists. */ -static void -test_record_bits_match_allowlists(void) -{ - for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { - const enum agx_chip c = (enum agx_chip)i; - const unsigned records = agx_chip_info(c)->records; - -#define RECORD(bit, allowlist) \ - CHECK(!!(records & AGX_RECORD_##bit) == allowlist(c)) - RECORD(VDM_STATE, agx_vdm_state_vertex_pipeline_pair_supported); - RECORD(VDM_PPP_STATE, agx_vdm_ppp_state_core_supported); - RECORD(VDM_BARRIER, agx_vdm_barrier_core_supported); - RECORD(VDM_STREAM_LINK, agx_vdm_stream_link_core_supported); - RECORD(VDM_STREAM_TERMINATE, agx_vdm_stream_terminate_core_supported); - RECORD(VDM_TESSELLATE, agx_vdm_tessellate_direct_target_supported); - RECORD(VDM_INDEX_LIST, - agx_vdm_index_list_direct_target_supported_inline); - RECORD(PPP_HAL300_DEPTH_STENCIL, - agx_ppp_hal300_depth_stencil_core_supported); - RECORD(PPP_HAL300_DEPTH_BIAS_SCISSOR, - agx_ppp_hal300_depth_bias_scissor_core_supported); - RECORD(CDM_LAUNCH, agx3_cdm_launch_target_grounded); - RECORD(CDM_INDIRECT_LAUNCH, agx3_cdm_indirect_launch_target_grounded); - RECORD(CDM_INDIRECT_LAUNCH_36, - agx3_cdm_indirect_launch_36_target_grounded); - RECORD(CDM_STREAM_LINK, agx3_cdm_stream_link_target_grounded); - RECORD(CDM_LINK_PADDING, agx3_cdm_link_padding_target_grounded); - RECORD(CDM_BARRIER, agx3_cdm_barrier_target_grounded); - RECORD(CDM_BARRIER_WIDE_VISIBILITY, - agx3_cdm_barrier_wide_visibility_grounded); - RECORD(CDM_BARRIER_FLUSH_MEMORY, - agx3_cdm_barrier_flush_memory_grounded); - RECORD(CDM_SUBSTREAM_BARRIER, - agx3_cdm_substream_barrier_target_grounded); - RECORD(CDM_SECONDARY_BARRIER, - agx3_cdm_secondary_barrier_target_grounded); - RECORD(IOTO_PROFILE_CONTROL, agx_ioto_profile_control_supported); - RECORD(HAL300_NATIVE_CAPTURE, agx_chip_hal300_records); -#undef RECORD - } -} - int main(void) { @@ -657,7 +613,6 @@ main(void) test_params_contracts(); test_invalid_identity(); test_classification_invariants(); - test_record_bits_match_allowlists(); if (failures) { fprintf(stderr, "agx_chip: %u of %u checks failed\n", failures, checks); From b99e5f850820dce97587ff389f87430cc4543a04 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:33:09 -0300 Subject: [PATCH 06/13] agx: name the chip sets call sites compare against, and use them in lib Call sites spell out which chips they mean, and "runs an AGX3 path" is written with different chips left out: native or M5 (123 times in the tree), native or M5 or G18G (36), native or G18G (12). The sets are not the same, so each gets its own predicate and every site keeps the set it had: agx_chip_agx3_path() native AGX3, M5 or G18G agx_chip_native_or_m5() not G18G agx_chip_native_or_g18g() not M5 agx_chip_hal300_path() M5 or G18G agx_chip_g17p_or_m5() G17P or M5 They name which chips, not why. Which of the sites that leave G18G or M5 out mean to is not decided here. Convert src/asahi/lib, genxml and libagx. A chain is replaced only when it has the same answer as the predicate for all 19 chips and AGX_CHIP_UNKNOWN: each chain was compiled against agx_chip.h and evaluated for every chip before it was rewritten, and a chain that already asks a capability by name (agx_chip_native_preamble() || agx_chip_g17_m5()) keeps its words. tests/test-chip.c has a row for each new predicate and checks it against the chain it replaces. Also here, each with the same answers as before: - Three local "is HAL300" helpers go: the Ioto profile one was agx_chip_g17_m5(), the VDM decode and state update ones agx_chip_hal300_path(). - agx3_cdm_direct_g15x_bit31_allowed() asks for the G15 command-stream generation instead of listing G15G/S/C/D. - agx3_cdm_barrier_flags_grounded() had the same flags for G18G and for the default case. - libagx's agx_vdm_barrier() repeated the VDM barrier allowlist; it asks agx_chip_has_record(). Not converted: agx_vdm_index_list_direct_is_hal300_inline() stays a comparison chain. It is compiled into the libagx kernels, and written as agx_chip_g17_m5() the kernels come out different. With this commit they are byte-identical to those built from b8762aab9. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/genxml/agx3_cmdstream.h | 24 ++++------ .../agx3_cdm_direct_launch_semantic_core.c | 3 +- src/asahi/lib/agx3_compute_program_core.c | 3 +- src/asahi/lib/agx_bg_eot.c | 33 ++++--------- src/asahi/lib/agx_chip.h | 48 ++++++++++++++++++- src/asahi/lib/agx_device.c | 17 +++---- src/asahi/lib/agx_device.h | 3 +- src/asahi/lib/agx_ioto_profile_core.c | 17 ++----- src/asahi/lib/agx_linker.c | 14 ++---- src/asahi/lib/agx_nir_prolog_epilog.c | 2 +- src/asahi/lib/agx_vdm_decode_core.c | 11 +---- src/asahi/lib/agx_vdm_state_update_core.c | 25 ++-------- src/asahi/lib/agx_zls_pixels.h | 2 +- src/asahi/lib/decode.c | 2 +- src/asahi/lib/tests/test-chip.c | 26 ++++++++++ src/asahi/libagx/libagx_dgc.h | 16 ++----- 16 files changed, 124 insertions(+), 122 deletions(-) diff --git a/src/asahi/genxml/agx3_cmdstream.h b/src/asahi/genxml/agx3_cmdstream.h index 90d8a8d5c0c4..8b7b8134c1bf 100644 --- a/src/asahi/genxml/agx3_cmdstream.h +++ b/src/asahi/genxml/agx3_cmdstream.h @@ -525,20 +525,12 @@ agx3_cdm_barrier_flags_grounded(enum agx_chip chip, uint8_t flags) if (!agx3_cdm_barrier_target_grounded(chip) || flags > 0xf) return false; - switch (chip) { - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - return true; - case AGX_CHIP_G18G: - /* The flag-free word is captured on G18G (compute-add), and flags=5 - * is grounded on hardware from rel24b+ chained launches: the weak - * flag-free tail does not give write visibility and flag-free chains - * hung the CDM (hk_cmd_dispatch.c). */ - return flags == 0 || flags == 5; - default: - return flags == 0 || flags == 0x5; - } + /* The M5 parts take every flag combination, the other chips the flag-free + * word and flags=5. On G18G the flag-free word is captured (compute-add), + * and flags=5 is grounded on hardware from rel24b+ chained launches: the + * weak flag-free tail does not give write visibility and flag-free chains + * hung the CDM (hk_cmd_dispatch.c). */ + return agx_chip_g17_m5(chip) || flags == 0 || flags == 5; } /* The wide-visibility barrier forms are only known on G15S and G16G with @@ -674,7 +666,7 @@ agx3_cdm_sstt_flush_invalidate_pack( return false; memset(packed, 0, AGX3_CDM_SSTT_FLUSH_INVALIDATE_SIZE); - if (chip != AGX_CHIP_G17P && !agx_chip_g17_m5(chip)) + if (!agx_chip_g17p_or_m5(chip)) return false; agx3_cmdstream_store_le32(packed, UINT32_C(0x60024102)); @@ -686,7 +678,7 @@ agx3_cdm_sstt_flush_invalidate_validate(enum agx_chip chip, const void *packed, size_t available) { - return (chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && packed && + return agx_chip_g17p_or_m5(chip) && packed && available >= AGX3_CDM_SSTT_FLUSH_INVALIDATE_SIZE && agx3_cmdstream_load_le32((const uint8_t *)packed) == UINT32_C(0x60024102); diff --git a/src/asahi/lib/agx3_cdm_direct_launch_semantic_core.c b/src/asahi/lib/agx3_cdm_direct_launch_semantic_core.c index 830ec32d7206..8073bc83686d 100644 --- a/src/asahi/lib/agx3_cdm_direct_launch_semantic_core.c +++ b/src/asahi/lib/agx3_cdm_direct_launch_semantic_core.c @@ -151,8 +151,7 @@ agx3_cdm_direct_dimension_word(uint8_t dimensions, uint32_t *word) static bool agx3_cdm_direct_g15x_bit31_allowed(enum agx_chip chip) { - return chip == AGX_CHIP_G15G || chip == AGX_CHIP_G15S || - chip == AGX_CHIP_G15C || chip == AGX_CHIP_G15D; + return agx_chip_command_stream_generation(chip) == AGX_CS_GENERATION_G15; } bool diff --git a/src/asahi/lib/agx3_compute_program_core.c b/src/asahi/lib/agx3_compute_program_core.c index e338ddad6380..c63b1336558d 100644 --- a/src/asahi/lib/agx3_compute_program_core.c +++ b/src/asahi/lib/agx3_compute_program_core.c @@ -143,8 +143,7 @@ agx3_g17p_native_compute_launch_pack( memset(packed, 0, AGX3_CDM_DIRECT_LAUNCH_SIZE); if (!program || !grid || - (!agx_chip_native_agx3(program->chip) && - !agx_chip_g17_m5(program->chip) && program->chip != AGX_CHIP_G18G) || + !agx_chip_agx3_path(program->chip) || program->program_va == 0 || program->program_va > UINT64_C(0xffffffffffff) || (program->program_va & (AGX_IOTO_PROGRAM_ALIGNMENT - 1)) != 0 || diff --git a/src/asahi/lib/agx_bg_eot.c b/src/asahi/lib/agx_bg_eot.c index 12db7e14e26d..7cf06a55f349 100644 --- a/src/asahi/lib/agx_bg_eot.c +++ b/src/asahi/lib/agx_bg_eot.c @@ -227,8 +227,7 @@ agx_compile_bg_eot_shader(struct agx_bg_eot_cache *cache, nir_shader *shader, &bindless_base, NULL, NULL, false, cache->dev->chip == AGX_CHIP_G18G, cache->dev->chip == AGX_CHIP_G18G, - agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip), + agx_chip_native_or_m5(cache->dev->chip), cache->dev->chip == AGX_CHIP_G18G); NIR_PASS(_, shader, agx_nir_lower_monolithic_msaa, tib->nr_samples); NIR_PASS(_, shader, agx_nir_lower_multisampled_image_store); @@ -295,8 +294,7 @@ agx_compile_bg_eot_shader(struct agx_bg_eot_cache *cache, nir_shader *shader, } res->info = bin.info; - if (agx_chip_native_agx3(cache->dev->chip) || agx_chip_g17_m5(cache->dev->chip) || - cache->dev->chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(cache->dev->chip)) { if (!agx_g17p_upload_bg_eot(cache, &bin, res)) { free(bin.binary); ralloc_free(shader); @@ -414,14 +412,11 @@ agx_build_background_shader(struct agx_bg_eot_cache *cache, /* Native multisample backgrounds store through the coverage register, * and so do G18G four-sample ones (msaa163). */ .fs.nr_samples = - agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || + agx_chip_native_or_m5(cache->dev->chip) || agx_g18_msaa4_tib(cache->dev, &key->tib) ? key->tib.nr_samples : 0, .reserved_preamble = key->reserved_preamble, - .no_preamble = agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || - cache->dev->chip == AGX_CHIP_G18G, + .no_preamble = agx_chip_agx3_path(cache->dev->chip), }; /* The multi-target background protocol is keyed, not inferred: without @@ -487,9 +482,7 @@ agx_build_background_shader(struct agx_bg_eot_cache *cache, nir_def *color = build_background_op( &b, key->op[rt], rt, nr, source_msaa, layered, - agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || - cache->dev->chip == AGX_CHIP_G18G, clear_base); + agx_chip_agx3_path(cache->dev->chip), clear_base); if (key->preserve_resolve_outside) { assert(rt == 0 && key->op[rt] == AGX_BG_LOAD); nir_def *xy = nir_u2u32(&b, nir_load_pixel_coord(&b)); @@ -718,8 +711,7 @@ agx_build_end_of_tile_shader(struct agx_bg_eot_cache *cache, bool explicit = false; nir_def *coords = layer; - if (agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || g18g) { + if (agx_chip_native_or_m5(cache->dev->chip) || g18g) { /* AGX3's EOT imgwblk has no implicit pixel-coordinate form. Apple's * G17P compiler reads the hardware grid X/Y SRs explicitly. Array * stores append the hardware layer ID; dropping it here made every @@ -742,8 +734,7 @@ agx_build_end_of_tile_shader(struct agx_bg_eot_cache *cache, /* M5 reads the packed word as the packed-float tile format and * converts it to the R11G11B10 PBE (agx_rt0_pbe_format). */ physical = (enum pipe_format)AIL_ISA_FORMAT_RG11B10F; - } else if (((agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip)) && + } else if ((agx_chip_native_or_m5(cache->dev->chip) && (key->tib.logical_format[rt] == PIPE_FORMAT_R11G11B10_FLOAT || key->tib.logical_format[rt] == PIPE_FORMAT_R9G9B9E5_FLOAT)) || (g18g && @@ -755,8 +746,7 @@ agx_build_end_of_tile_shader(struct agx_bg_eot_cache *cache, * R11G11B10 explicitly into one raw word as well; texture views * retain the original decoding format. */ physical = PIPE_FORMAT_R32_UINT; - } else if ((agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || g18g) && + } else if ((agx_chip_native_or_m5(cache->dev->chip) || g18g) && util_format_is_srgb(key->tib.logical_format[rt])) { /* G17P applies the sRGB transfer in the fragment's own packs * (fltnorm/normflt sRGB modes), and G18G lowers it explicitly before @@ -792,8 +782,7 @@ agx_build_end_of_tile_shader(struct agx_bg_eot_cache *cache, struct agx_shader_key compiler_key = { .dev = agx_gather_device_key(cache->dev), .reserved_preamble = key->reserved_preamble, - .no_preamble = agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || g18g, + .no_preamble = agx_chip_native_or_m5(cache->dev->chip) || g18g, .m5_rt0_eot = agx_chip_g17_m5(cache->dev->chip), .m5_rt0_eot_store_and_resolve = key->m5_store_and_resolve, .g17g_rt0_eot = g18g, @@ -964,9 +953,7 @@ agx_get_precompiled_locked(struct agx_bg_eot_cache *cache, unsigned program) /* G18G's kernels (agx3d, compiled as G17G) sit in the same CODE container * as G17P's: the M5 compute profile takes the entry exactly as the API * compute path builds it (agx_g17p_append_compute). */ - const bool agx3_image = agx_chip_native_agx3(cache->dev->chip) || - agx_chip_g17_m5(cache->dev->chip) || - cache->dev->chip == AGX_CHIP_G18G; + const bool agx3_image = agx_chip_agx3_path(cache->dev->chip); if (agx3_image) { const bool m5 = agx_chip_g17_m5(cache->dev->chip); diff --git a/src/asahi/lib/agx_chip.h b/src/asahi/lib/agx_chip.h index 9af1a4b78c4c..c4f9a6d1f906 100644 --- a/src/asahi/lib/agx_chip.h +++ b/src/asahi/lib/agx_chip.h @@ -809,6 +809,52 @@ agx_chip_m5_paths(enum agx_chip chip) return agx_chip_info(chip)->quirks & AGX_QUIRK_M5_PATHS; } +/* + * Chip sets that call sites test without a capability of their own. They say + * which chips and not why, and they are not interchangeable: three of them + * are "runs an AGX3 path" with G18G or the M5 parts left out. Each replaced + * the same comparisons written out at the call sites, so a site keeps the set + * it had. A new site that knows why it asks should get a predicate named for + * that reason instead. + */ + +/* The HAL300 path: the M5 parts and G18G. */ +static inline bool +agx_chip_hal300_path(enum agx_chip chip) +{ + return agx_chip_info(chip)->path == AGX_CHIP_PATH_HAL300; +} + +/* Either AGX3 path: native AGX3, the M5 parts or G18G. */ +static inline bool +agx_chip_agx3_path(enum agx_chip chip) +{ + const enum agx_chip_path path = agx_chip_info(chip)->path; + + return path == AGX_CHIP_PATH_NATIVE_AGX3 || path == AGX_CHIP_PATH_HAL300; +} + +/* Native AGX3 or an M5 part. Not G18G. */ +static inline bool +agx_chip_native_or_m5(enum agx_chip chip) +{ + return agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip); +} + +/* Native AGX3 or G18G. Not the M5 parts. */ +static inline bool +agx_chip_native_or_g18g(enum agx_chip chip) +{ + return agx_chip_native_agx3(chip) || chip == AGX_CHIP_G18G; +} + +/* G17P or an M5 part. Not the other native chips and not G18G. */ +static inline bool +agx_chip_g17p_or_m5(enum agx_chip chip) +{ + return chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip); +} + /* Whether consecutive application dispatches of one CDM stream may omit the * ordering barrier between them. Vulkan orders dispatches only through * explicit barriers; every other record (internal or indirect launch, cache @@ -819,7 +865,7 @@ agx_chip_m5_paths(enum agx_chip chip) static inline bool agx_chip_elide_app_dispatch_barrier(enum agx_chip chip) { - return agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip); + return agx_chip_native_or_m5(chip); } /* Number of helper-table slots in the USC code-container lead block. G15 diff --git a/src/asahi/lib/agx_device.c b/src/asahi/lib/agx_device.c index c47b62f91ba7..1cc8ca5897e4 100644 --- a/src/asahi/lib/agx_device.c +++ b/src/asahi/lib/agx_device.c @@ -1252,7 +1252,7 @@ agx_open_device(void *memctx, struct agx_device *dev) * a practical limit. */ if (agx_chip_native_agx3(dev->chip)) dev->shader_base = AGX_G17P_USC_WINDOW_BASE; - else if (agx_chip_g17_m5(dev->chip) || dev->chip == AGX_CHIP_G18G) + else if (agx_chip_hal300_path(dev->chip)) dev->shader_base = AGX_M5_SHADER_BASE; if (dev->shader_base < reservation) { @@ -1290,9 +1290,7 @@ agx_open_device(void *memctx, struct agx_device *dev) * robustness carveout untouched while making every ordinary VDM payload * directly representable, with no per-run alias option. */ - const bool heap_below_usc = agx_chip_native_agx3(dev->chip) || - agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G; + const bool heap_below_usc = agx_chip_agx3_path(dev->chip); /* * Start the low heap as high as it can go rather than at the reservation. @@ -1346,7 +1344,7 @@ agx_open_device(void *memctx, struct agx_device *dev) /* G17P is bounded by the narrower of the compact VDM aperture and the * absolute USC texture/sampler table pointer, both of which sit below the * USC window. Other chips retain the kernel-reported user limit. */ - if (agx_chip_g17_m5(dev->chip) || dev->chip == AGX_CHIP_G18G) { + if (agx_chip_hal300_path(dev->chip)) { struct agx_m5_va_layout layout; if (!agx_m5_va_layout(dev->params.vm_start, dev->params.vm_end, dev->params.vm_kernel_min_size, dev->shader_base, @@ -1359,7 +1357,7 @@ agx_open_device(void *memctx, struct agx_device *dev) user_start = layout.data_start; } const uint64_t user_limit = - agx_chip_g17_m5(dev->chip) || dev->chip == AGX_CHIP_G18G + agx_chip_hal300_path(dev->chip) ? AGX_M5_DATA_END : agx_va_user_limit(dev->chip, heap_below_usc, vm_create.kernel_start); @@ -1582,9 +1580,7 @@ agx_open_device(void *memctx, struct agx_device *dev) initialized |= AGX_INIT_CONTEXT_SLOTS; } - const bool dynamic_printf = agx_chip_native_agx3(dev->chip) || - agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G; + const bool dynamic_printf = agx_chip_agx3_path(dev->chip); struct agx_bo *bo = dynamic_printf ? agx_bo_create(dev, LIBAGX_PRINTF_BUFFER_SIZE, 0, AGX_BO_WRITEBACK, @@ -1620,8 +1616,7 @@ agx_open_device(void *memctx, struct agx_device *dev) initialized |= AGX_INIT_PRINTF; /* Map the stage helper tables at the USC execution-window base. */ - if (agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->chip)) { const size_t usc_base_size = AIL_PAGESIZE; simple_mtx_lock(&dev->vma_lock); diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 6720d42647b4..6974fddfa0d3 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -618,7 +618,8 @@ agx_stream_sampler_state(const struct agx_device *dev) static inline bool agx_is_m4_pro(const struct agx_device *dev) { - return dev->chip == AGX_CHIP_G17P && dev->params.chip_id == 0x6040 && + return dev->chip == AGX_CHIP_G17P && + dev->params.chip_id == AGX_CHIP_ID_M4_PRO && dev->params.gpu_generation == 16 && dev->params.gpu_variant == 'S'; } diff --git a/src/asahi/lib/agx_ioto_profile_core.c b/src/asahi/lib/agx_ioto_profile_core.c index 96b3a76a42d3..4446e2022b01 100644 --- a/src/asahi/lib/agx_ioto_profile_core.c +++ b/src/asahi/lib/agx_ioto_profile_core.c @@ -26,13 +26,6 @@ static const uint8_t g17s_minimal_profile_loader 0x27, 0x04, 0x04, 0x00, 0x30, 0x00, 0xa4, 0x12, }; -static bool -is_hal300(enum agx_chip chip) -{ - return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G17S || - chip == AGX_CHIP_G17C; -} - bool agx_ioto_profile_control_supported(enum agx_chip chip) { @@ -45,7 +38,7 @@ agx_ioto_profile_control_size(enum agx_chip chip) if (!agx_ioto_profile_control_supported(chip)) return 0; - return is_hal300(chip) ? 6 : 4; + return agx_chip_g17_m5(chip) ? 6 : 4; } bool @@ -59,7 +52,7 @@ agx_ioto_profile_control_pack(const struct agx_ioto_profile_control *profile, if (!profile || !agx_ioto_profile_control_supported(profile->chip)) return false; - if (is_hal300(profile->chip)) { + if (agx_chip_g17_m5(profile->chip)) { if ((profile->payload0 & ~AGX_IOTO_PROFILE_CONTROL_HAL300_PAYLOAD0) != 0 || (profile->payload1 & ~AGX_IOTO_PROFILE_CONTROL_HAL300_PAYLOAD1) != 0) return false; @@ -69,15 +62,15 @@ agx_ioto_profile_control_pack(const struct agx_ioto_profile_control *profile, return false; } - agx_store_le16(out, is_hal300(profile->chip) + agx_store_le16(out, agx_chip_g17_m5(profile->chip) ? AGX_IOTO_PROFILE_CONTROL_HAL300_OPCODE : AGX_IOTO_PROFILE_CONTROL_CLASSIC_OPCODE); agx_store_le16(out + 2, profile->payload0 | - (is_hal300(profile->chip) + (agx_chip_g17_m5(profile->chip) ? AGX_IOTO_PROFILE_CONTROL_HAL300_WORD1_FIXED : 0)); - if (is_hal300(profile->chip)) + if (agx_chip_g17_m5(profile->chip)) agx_store_le16(out + 4, profile->payload1); return true; diff --git a/src/asahi/lib/agx_linker.c b/src/asahi/lib/agx_linker.c index 827ad37c3b50..8d652a196a4e 100644 --- a/src/asahi/lib/agx_linker.c +++ b/src/asahi/lib/agx_linker.c @@ -50,7 +50,7 @@ agx_fs_epilog_apply_device_policy(enum agx_chip chip, /* G18 coverage also dirties color during depth-only or fully masked draws. * Preserve the previous tile value while executing the other side effects. */ - key->preserve_zero_mask = g17p || agx_chip_g17_m5(chip) || chip == AGX_CHIP_G18G; + key->preserve_zero_mask = g17p || agx_chip_hal300_path(chip); key->sample_loop_mrt = chip == AGX_CHIP_G18G && key->nr_samples > 1; /* G18G: both AGX3 tile interfaces move packed bytes. The RGB transfer * function belongs around blending; alpha remains linear. R11G11B10 is @@ -296,8 +296,7 @@ agx3_build_container(const struct agx_device *dev, uint8_t *image, static bool agx3_uses_code_container(const struct agx_device *dev) { - return agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G; + return agx_chip_agx3_path(dev->chip); } /* Give a relocatable vertex program's varyings the indices of the bound @@ -340,8 +339,7 @@ agx_fast_link(struct agx_linked_shader *linked, struct agx_device *dev, /* These literal loop fragments are AGX2 machine code. G17P exposes only * one sample and its Vulkan path folds sample shading before split-FS * lowering; fail closed if a caller ever bypasses that canonicalization. */ - if ((agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G) && + if (agx_chip_agx3_path(dev->chip) && nr_samples_shaded) { fprintf(stderr, "agx_fast_link: external sample loop is not AGX3 machine code\n"); @@ -367,8 +365,7 @@ agx_fast_link(struct agx_linked_shader *linked, struct agx_device *dev, bool nop_entry[ARRAY_SIZE(parts)] = {false}; bool entry_seen = false; int kept_entry = -1; - if ((agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G) && + if (agx_chip_agx3_path(dev->chip) && fragment && !nr_samples_shaded && !colour_fused) { for (unsigned i = 0; i < ARRAY_SIZE(parts); ++i) { struct agx_shader_part *part = parts[i]; @@ -479,8 +476,7 @@ agx_fast_link(struct agx_linked_shader *linked, struct agx_device *dev, /* The staging accounting is per instruction, so a linked software vertex * shader (a compute-stage main behind the vertex prolog) is described the * same way as a hardware vertex or fragment program. */ - if ((agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G) && + if (agx_chip_agx3_path(dev->chip) && (main->info.stage == MESA_SHADER_VERTEX || main->info.stage == MESA_SHADER_FRAGMENT || main->info.stage == MESA_SHADER_COMPUTE || diff --git a/src/asahi/lib/agx_nir_prolog_epilog.c b/src/asahi/lib/agx_nir_prolog_epilog.c index 8a867cc9c169..08e9258ea302 100644 --- a/src/asahi/lib/agx_nir_prolog_epilog.c +++ b/src/asahi/lib/agx_nir_prolog_epilog.c @@ -1617,7 +1617,7 @@ agx_nir_lower_fs_output_to_epilog_for_device( nir_shader *s, enum agx_chip chip, struct agx_fs_epilog_link_info *out) { return lower_fs_output_to_epilog( - s, out, agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip), + s, out, agx_chip_native_or_m5(chip), agx_chip_native_agx3(chip), agx_chip_native_agx3(chip)); } diff --git a/src/asahi/lib/agx_vdm_decode_core.c b/src/asahi/lib/agx_vdm_decode_core.c index 2c96214ea87a..96a1001ed3d3 100644 --- a/src/asahi/lib/agx_vdm_decode_core.c +++ b/src/asahi/lib/agx_vdm_decode_core.c @@ -14,13 +14,6 @@ #include -static bool -agx_vdm_decode_is_hal300(enum agx_chip chip) -{ - return agx_chip_hal300_records(chip) || chip == AGX_CHIP_G17S || - chip == AGX_CHIP_G17C; -} - bool agx_vdm_decode_one(enum agx_chip chip, const void *bytes, size_t available, struct agx_vdm_decoded_record *record) @@ -86,7 +79,7 @@ agx_vdm_decode_one(enum agx_chip chip, const void *bytes, size_t available, return true; case 2: { - const bool hal300 = agx_vdm_decode_is_hal300(chip); + const bool hal300 = agx_chip_hal300_path(chip); const size_t indirect_indexed_length = hal300 ? AGX_VDM_INDEX_LIST_INDIRECT_INDEXED_MAX_LENGTH : AGX_VDM_INDEX_LIST_INDIRECT_INDEXED_MAX_LENGTH - 4; @@ -135,7 +128,7 @@ agx_vdm_decode_one(enum agx_chip chip, const void *bytes, size_t available, } case 3: { - const bool hal300 = agx_vdm_decode_is_hal300(chip); + const bool hal300 = agx_chip_hal300_path(chip); const size_t indexed_length = hal300 ? 32 : 28; const size_t nonindexed_length = agx_vdm_index_list_nonindexed_has_tail(chip) ? 20 : 16; diff --git a/src/asahi/lib/agx_vdm_state_update_core.c b/src/asahi/lib/agx_vdm_state_update_core.c index 12768ae4fcdc..8dbf1b96f5ce 100644 --- a/src/asahi/lib/agx_vdm_state_update_core.c +++ b/src/asahi/lib/agx_vdm_state_update_core.c @@ -97,20 +97,6 @@ agx_vdm_state_update_unpack(enum agx_chip chip, const void *bytes, size_t size, return true; } -static bool -agx_vdm_state_update_is_hal300(enum agx_chip chip) -{ - switch (chip) { - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - return true; - default: - return false; - } -} - /* * Materialize/pack the exact six-template path observed in: * @@ -137,7 +123,7 @@ agx_vdm_state_update_template_materialize( info->variant > AGX_VDM_STATE_UPDATE_TEMPLATE_21) return false; - const bool hal300 = agx_vdm_state_update_is_hal300(chip); + const bool hal300 = agx_chip_hal300_path(chip); if (hal300 && (info->pre_hal300_flag_group_nonzero || info->pre_hal300_flag_bit_4)) return false; @@ -246,7 +232,7 @@ agx_vdm_state_update_vertex_ti_resources( /* Same bounds as the HAL200 fragment record: an 18-bit spill field and * the 12-bit IPR field, whose even rounding caps it at 0xffe. */ - if ((!agx_chip_native_agx3(chip) && !agx_vdm_state_update_is_hal300(chip)) || + if (!agx_chip_agx3_path(chip) || !info || spill_quads > UINT32_C(0x3ffff) || ipr_quads > UINT32_C(0xffe)) return false; @@ -317,7 +303,7 @@ agx_g17p_vertex_program_info( const bool preamble_ok = compiler_info && (compiler_info->has_preamble - ? (agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip)) && + ? agx_chip_native_or_m5(chip) && compiler_info->constant_program_allowed && compiler_info->preamble_staging_known && compiler_info->nr_preamble_gprs != 0 && @@ -325,8 +311,7 @@ agx_g17p_vertex_program_info( : compiler_info->nr_preamble_gprs == 0 && compiler_info->preamble_scratch_size == 0); - if ((!agx_chip_native_agx3(chip) && !agx_chip_g17_m5(chip) && - chip != AGX_CHIP_G18G) || + if (!agx_chip_agx3_path(chip) || !compiler_info || !program || !compiler_info->hardware_vertex || !preamble_ok || compiler_info->position_off != 0 || compiler_info->varyings_off != 4 || @@ -371,7 +356,7 @@ agx_g17p_vertex_program_info( .raw_vs_output_selector = 0, .raw_vs_output_flag_6 = false, .pre_hal300_flag_group_nonzero = - !agx_vdm_state_update_is_hal300(chip), + !agx_chip_hal300_path(chip), .pre_hal300_flag_bit_4 = false, .variant = AGX_VDM_STATE_UPDATE_TEMPLATE_00, .raw_active_context_selector = UINT32_MAX, diff --git a/src/asahi/lib/agx_zls_pixels.h b/src/asahi/lib/agx_zls_pixels.h index cabeb655063d..56f978332fdc 100644 --- a/src/asahi/lib/agx_zls_pixels.h +++ b/src/asahi/lib/agx_zls_pixels.h @@ -30,7 +30,7 @@ agx_zls_pixels(enum agx_chip chip, uint32_t width, uint32_t height, if ((depth_base | depth_meta | stencil_base | stencil_meta) == 0) return 0; - const unsigned shift = (agx_chip_hal300_records(chip) || agx_chip_g17_m5(chip)) ? 16 : 15; + const unsigned shift = agx_chip_hal300_path(chip) ? 16 : 15; assert(width >= 1 && width <= (1u << shift)); assert(height >= 1 && height <= (1u << shift)); return (width - 1) | ((height - 1) << shift); diff --git a/src/asahi/lib/decode.c b/src/asahi/lib/decode.c index 317c7707d4bb..0891c83236e1 100644 --- a/src/asahi/lib/decode.c +++ b/src/asahi/lib/decode.c @@ -1375,7 +1375,7 @@ agxdecode_drm_cmd_render(struct agxdecode_ctx *ctx, { const enum agx_chip chip = agxdecode_chip_from_params(params); decode_cmd graphics_program_decoder = - agx_chip_native_agx3(chip) || chip == AGX_CHIP_G18G ? agxdecode_ioto + agx_chip_native_or_g18g(chip) ? agxdecode_ioto : agxdecode_usc; DUMP_FIELD(c, "%x", flags); diff --git a/src/asahi/lib/tests/test-chip.c b/src/asahi/lib/tests/test-chip.c index 29a14961c249..ef8b4dab8f22 100644 --- a/src/asahi/lib/tests/test-chip.c +++ b/src/asahi/lib/tests/test-chip.c @@ -113,6 +113,11 @@ static unsigned checks; ROW(agx_chip_driver_supported(c), "1111 01110 0100 10000 0 0") \ ROW(agx_chip_uses_legacy_precompiled_programs(c), \ "1111 00000 0000 00000 0 0") \ + ROW(agx_chip_hal300_path(c), "0000 00000 0000 00111 1 0") \ + ROW(agx_chip_agx3_path(c), "0000 01110 0100 10111 1 0") \ + ROW(agx_chip_native_or_m5(c), "0000 01110 0100 10111 0 0") \ + ROW(agx_chip_native_or_g18g(c), "0000 01110 0100 10000 1 0") \ + ROW(agx_chip_g17p_or_m5(c), "0000 00000 0000 10111 0 0") \ /* Capabilities and quirks. */ \ ROW(agx_chip_has_native_render_context(c), "0000 00000 0000 10000 0 0") \ ROW(agx_chip_native_indirect_compute(c), "0000 01110 0100 10000 0 0") \ @@ -346,6 +351,26 @@ test_truth_table(void) } } +/* Each chip-set predicate is the comparison chain it replaced at the call + * sites. */ +static void +test_chip_sets(void) +{ + for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) { + const enum agx_chip c = (enum agx_chip)i; + const bool native = agx_chip_native_agx3(c); + const bool m5 = agx_chip_g17_m5(c); + + CHECK(agx_chip_hal300_path(c) == (m5 || c == AGX_CHIP_G18G)); + CHECK(agx_chip_agx3_path(c) == (native || m5 || c == AGX_CHIP_G18G)); + CHECK(agx_chip_native_or_m5(c) == (native || m5)); + CHECK(agx_chip_native_or_g18g(c) == (native || c == AGX_CHIP_G18G)); + CHECK(agx_chip_g17p_or_m5(c) == (c == AGX_CHIP_G17P || m5)); + CHECK(m5 == (c == AGX_CHIP_G17G || c == AGX_CHIP_G17S || + c == AGX_CHIP_G17C)); + } +} + /* Exact driver-core identities recovered from Apple's readChipInfo table. */ static const struct { uint32_t generation; @@ -607,6 +632,7 @@ int main(void) { test_truth_table(); + test_chip_sets(); test_recovered_table(); test_decoder_identity(); test_variant_is_load_bearing(); diff --git a/src/asahi/libagx/libagx_dgc.h b/src/asahi/libagx/libagx_dgc.h index e3936ba7f06f..b686aff1e638 100644 --- a/src/asahi/libagx/libagx_dgc.h +++ b/src/asahi/libagx/libagx_dgc.h @@ -666,24 +666,14 @@ agx_vdm_barrier(GLOBAL uint32_t *out, enum agx_chip chip, * opcode/field layout. Keep the unwitnessed G16P/G17A identities closed * instead of guessing from their neighbouring families. G18G memory * barriers use the same word. */ - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: + if (agx_chip_has_record(chip, AGX_RECORD_VDM_BARRIER)) { /* With the USC cache invalidate where the kernel admits it * (agx_vdm_barrier_core.h). */ *out++ = agx_vdm_barrier_core_word(chip, kernel_admits_inval); return out; + } + switch (chip) { case AGX_CHIP_G16P: case AGX_CHIP_G17A: case AGX_CHIP_UNKNOWN: From 0c344570322acde55055de7caa3e8b7d796adb61 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:33:26 -0300 Subject: [PATCH 07/13] agx/compiler: use the chip-set predicates Five comparison chains in the compiler become the predicate with the same answer for all 19 chips and AGX_CHIP_UNKNOWN: !agx_chip_native_or_m5() in agx3_graphics_program.c, and agx_chip_g17p_or_m5() in the register allocator and the spiller. Each chain was compiled against agx_chip.h and evaluated for every chip before it was rewritten. test-agx3-g17p-task-kernel-shared.c takes its encoding from the chip table: agx_chip_isa_encoding() of the chip it compiles as, G17G for G18G, as agx_gather_device_key() does. That is AGX3B for G17P and AGX3C for G17G and G18G, the three chips it runs, as before. The single-chip comparisons stay: they are chip identity. So do the per-encoding chip lists of agx3_pack.c, which are not the encoding column of the chip table (they omit chips). Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/compiler/agx3_graphics_program.c | 2 +- src/asahi/compiler/agx_register_allocate.c | 8 +++----- src/asahi/compiler/agx_spill.c | 3 +-- .../compiler/test/test-agx3-g17p-task-kernel-shared.c | 3 ++- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/asahi/compiler/agx3_graphics_program.c b/src/asahi/compiler/agx3_graphics_program.c index 8ffb9b8a914d..2e4e413442a5 100644 --- a/src/asahi/compiler/agx3_graphics_program.c +++ b/src/asahi/compiler/agx3_graphics_program.c @@ -1203,7 +1203,7 @@ agx3_g17p_fragment_blend_constant_base(enum agx_chip chip, unsigned occupied_halfs, uint16_t *base) { - if ((!agx_chip_native_agx3(chip) && !agx_chip_g17_m5(chip)) || !base) + if (!agx_chip_native_or_m5(chip) || !base) return false; const unsigned start = ALIGN_POT(MAX2(occupied_halfs, 8), 2); diff --git a/src/asahi/compiler/agx_register_allocate.c b/src/asahi/compiler/agx_register_allocate.c index ac7cb12e4d5d..0b491140a1e2 100644 --- a/src/asahi/compiler/agx_register_allocate.c +++ b/src/asahi/compiler/agx_register_allocate.c @@ -1156,7 +1156,7 @@ prefer_high_bank(const struct ra_ctx *rctx, const agx_instr *I, unsigned d, enum ra_class cls, unsigned minimum, unsigned limit) { const enum agx_chip chip = rctx->shader->key->dev.chip; - if ((chip != AGX_CHIP_G17P && !agx_chip_g17_m5(chip)) || + if (!agx_chip_g17p_or_m5(chip) || !rctx->shader->has_spill_pcopy_reserved || cls != RA_GPR || minimum != 0 || limit != rctx->bound[cls] || limit <= G17P_LOW_BANK_HALVES || @@ -1621,8 +1621,7 @@ static bool pick_phi_source_agreement(struct ra_ctx *rctx, agx_instr *I, unsigned *out) { if (I->op != AGX_OPCODE_PHI || - (rctx->shader->key->dev.chip != AGX_CHIP_G17P && - !agx_chip_g17_m5(rctx->shader->key->dev.chip))) + !agx_chip_g17p_or_m5(rctx->shader->key->dev.chip)) return false; enum ra_class cls = ra_class_for_index(I->dest[0]); @@ -1659,8 +1658,7 @@ pick_phi_unclaimed(struct ra_ctx *rctx, agx_instr *I, unsigned d, unsigned count, unsigned align, unsigned *out) { if (I->op != AGX_OPCODE_PHI || - (rctx->shader->key->dev.chip != AGX_CHIP_G17P && - !agx_chip_g17_m5(rctx->shader->key->dev.chip))) + !agx_chip_g17p_or_m5(rctx->shader->key->dev.chip)) return false; enum ra_class cls = ra_class_for_index(I->dest[d]); diff --git a/src/asahi/compiler/agx_spill.c b/src/asahi/compiler/agx_spill.c index 8e5df0157c07..6f3137a52b36 100644 --- a/src/asahi/compiler/agx_spill.c +++ b/src/asahi/compiler/agx_spill.c @@ -1245,8 +1245,7 @@ compute_w_entry_loop_header(struct spill_ctx *ctx) BITSET_WORD *used = NULL; unsigned room = 0; - if ((ctx->shader->key->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(ctx->shader->key->dev.chip)) && + if (agx_chip_g17p_or_m5(ctx->shader->key->dev.chip) && !ctx->remat_only) { used = BITSET_CALLOC(ctx->n); room = loop_room_for_live_through(ctx, used); diff --git a/src/asahi/compiler/test/test-agx3-g17p-task-kernel-shared.c b/src/asahi/compiler/test/test-agx3-g17p-task-kernel-shared.c index 4a448e78ccf4..032e5b80fe8a 100644 --- a/src/asahi/compiler/test/test-agx3-g17p-task-kernel-shared.c +++ b/src/asahi/compiler/test/test-agx3-g17p-task-kernel-shared.c @@ -328,9 +328,10 @@ check_agx2_compute_shared_not_vectorized(void) static bool check_agx3_generic_preprocess_shared_byte_offsets(enum agx_chip chip) { + /* G18G compiles as G17G and re-encodes as agx3d (agx_gather_device_key) */ const bool g18g = chip == AGX_CHIP_G18G; const enum agx_isa_encoding encoding = - chip == AGX_CHIP_G17P ? AGX_ISA_ENCODING_AGX3B : AGX_ISA_ENCODING_AGX3C; + agx_chip_isa_encoding(g18g ? AGX_CHIP_G17G : chip); nir_builder b = nir_builder_init_simple_shader( MESA_SHADER_COMPUTE, &agx_nir_options, From 80fcfeab1a187f8a2797222f5a295c92c5fb9692 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:35:17 -0300 Subject: [PATCH 08/13] borealis: use the chip-set predicates 162 comparison chains in Borealis become the predicate with the same answer for all 19 chips and AGX_CHIP_UNKNOWN. Most are "native or M5", spelled agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip), and "G17P or M5". Each chain was compiled against agx_chip.h and evaluated for every chip before it was rewritten; one in hk_cmd_meta.c, whose two terms named the same chip differently, was done by hand. hk_shader_binary_version() listed the AGX2 chips and G17P plus M5. It asks agx_chip_isa() and agx_chip_g17p_or_m5(), with the same three answers. Four more sites are converted by hand, each to a predicate with the same answers: - hk_cs_init_graphics() spelled two sets through a local `g18g`. The fragment-span capture tested native or G18G, which is agx_chip_native_or_g18g(), and the context selector native, M5 or G18G, which is agx_chip_agx3_path(). - Two gates were written "G17G or G18G", the chips of both agx_chip_m5_paths() and agx_chip_hal300_records(). hk_agx3_g17g_basic_graphics_program_generate() builds the G17G-form Ioto program, which G18G runs re-encoded: that is a path the driver takes, so agx_chip_m5_paths(), whose comment now names it. hk_agx3_g17g_vertex_program_info() admits the vertex program words of the VDM state update and holds G17G to the layouts its captures witness: that is agx_chip_hal300_records(). Every site keeps its set. In particular the 102 "native or M5" sites still leave G18G out, and the five "native or G18G" ones still leave M5 out. Chains that ask a capability by name (agx_chip_sampler_has_lod_bias(), agx_chip_native_preamble()) and single-chip comparisons are unchanged. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/lib/agx_chip.h | 14 +-- src/asahi/vulkan/hk_agx3_ioto_program_core.c | 2 +- src/asahi/vulkan/hk_agx3_vdm_decode.c | 2 +- src/asahi/vulkan/hk_agx3_vdm_decode.h | 16 +-- src/asahi/vulkan/hk_buffer.c | 3 +- src/asahi/vulkan/hk_buffer_view.c | 9 +- src/asahi/vulkan/hk_cmd_buffer.c | 26 ++--- src/asahi/vulkan/hk_cmd_buffer.h | 5 +- src/asahi/vulkan/hk_cmd_draw.c | 108 ++++++++----------- src/asahi/vulkan/hk_cmd_meta.c | 37 +++---- src/asahi/vulkan/hk_cmd_pool.c | 4 +- src/asahi/vulkan/hk_descriptor_set.c | 2 +- src/asahi/vulkan/hk_descriptor_set_layout.c | 11 +- src/asahi/vulkan/hk_device.c | 20 ++-- src/asahi/vulkan/hk_device.h | 2 +- src/asahi/vulkan/hk_format.c | 2 +- src/asahi/vulkan/hk_g17p_compression.h | 2 +- src/asahi/vulkan/hk_g17p_meta_copy_core.c | 7 +- src/asahi/vulkan/hk_image.c | 15 ++- src/asahi/vulkan/hk_image_view.c | 16 ++- src/asahi/vulkan/hk_physical_device.c | 9 +- src/asahi/vulkan/hk_ppp_state.h | 2 +- src/asahi/vulkan/hk_query_oq.c | 2 +- src/asahi/vulkan/hk_query_pool.c | 3 +- src/asahi/vulkan/hk_queue.c | 21 ++-- src/asahi/vulkan/hk_ray_tracing_pipeline.c | 2 +- src/asahi/vulkan/hk_shader.c | 84 +++++++-------- src/asahi/vulkan/hk_sync.c | 11 +- 28 files changed, 176 insertions(+), 261 deletions(-) diff --git a/src/asahi/lib/agx_chip.h b/src/asahi/lib/agx_chip.h index c4f9a6d1f906..3aedd7d9122a 100644 --- a/src/asahi/lib/agx_chip.h +++ b/src/asahi/lib/agx_chip.h @@ -792,12 +792,14 @@ agx_chip_g17_m5(enum agx_chip chip) /* * Whether the Gallium driver takes its M5 paths on this chip: draw admission, - * native descriptors, the VDM/PPP streams and the M5 kernel contract. G18G - * does: its records and texture/PBE descriptors are byte-identical to M5's - * on every J873 native capture (agx_chip_hal300_records), its code is G17G - * code re-encoded (agx_device_key::emit_agx3d), and the chip-specific deltas - * (the tailed non-indexed Index List, the point-size rule) stay keyed on the - * chip inside the record packers. + * native descriptors, the VDM/PPP streams and the M5 kernel contract. Both + * drivers ask it for the G17G-form compute dispatch, and the Vulkan driver + * for its G17G-form graphics program. G18G does: its records and texture/PBE + * descriptors are byte-identical to M5's on every J873 native capture + * (agx_chip_hal300_records), its code is G17G code re-encoded + * (agx_device_key::emit_agx3d), and the chip-specific deltas (the tailed + * non-indexed Index List, the point-size rule) stay keyed on the chip inside + * the record packers. * * These are the chips of agx_chip_hal300_records() today. That one says which * record layouts native captures witness, this one which paths the driver diff --git a/src/asahi/vulkan/hk_agx3_ioto_program_core.c b/src/asahi/vulkan/hk_agx3_ioto_program_core.c index ba52df2a0bd5..6b85ef0e2518 100644 --- a/src/asahi/vulkan/hk_agx3_ioto_program_core.c +++ b/src/asahi/vulkan/hk_agx3_ioto_program_core.c @@ -554,7 +554,7 @@ hk_agx3_g17g_basic_graphics_program_generate( enum agx_chip chip, const struct hk_agx3_g17p_graphics_program_desc *desc, struct hk_agx3_g17p_graphics_program *program) { - if ((chip != AGX_CHIP_G17G && chip != AGX_CHIP_G18G) || !desc || !program) + if (!agx_chip_m5_paths(chip) || !desc || !program) return false; const struct agx3_g17p_graphics_program_desc shared_desc = hk_agx3_g17p_shared_graphics_desc(desc); diff --git a/src/asahi/vulkan/hk_agx3_vdm_decode.c b/src/asahi/vulkan/hk_agx3_vdm_decode.c index a980b08981f9..6b7c4fb47b8f 100644 --- a/src/asahi/vulkan/hk_agx3_vdm_decode.c +++ b/src/asahi/vulkan/hk_agx3_vdm_decode.c @@ -158,7 +158,7 @@ hk_agx3_g17g_vertex_program_info( (compiler_info->layer_viewport_off == 8 || compiler_info->layer_viewport_off == 9) && compiler_info->clip_off == compiler_info->layer_viewport_off; - if ((chip != AGX_CHIP_G17G && chip != AGX_CHIP_G18G) || !compiler_info || + if (!agx_chip_hal300_records(chip) || !compiler_info || (chip == AGX_CHIP_G17G && (!color && ((!position && !position_psiz) || compiler_info->user_size != 0)))) { diff --git a/src/asahi/vulkan/hk_agx3_vdm_decode.h b/src/asahi/vulkan/hk_agx3_vdm_decode.h index 8788f95789d6..814f3ee03e0e 100644 --- a/src/asahi/vulkan/hk_agx3_vdm_decode.h +++ b/src/asahi/vulkan/hk_agx3_vdm_decode.h @@ -39,21 +39,11 @@ extern "C" { static inline uint32_t hk_shader_binary_version(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G13G: - case AGX_CHIP_G13X: - case AGX_CHIP_G14G: - case AGX_CHIP_G14X: - case AGX_CHIP_G15P: + if (agx_chip_isa(chip) == AGX_ISA_AGX2) return HK_AGX2_SHADER_BINARY_VERSION; - case AGX_CHIP_G17P: - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: + if (agx_chip_g17p_or_m5(chip)) return HK_AGX3_SHADER_BINARY_VERSION; - default: - return HK_CLASSIC_SHADER_BINARY_VERSION; - } + return HK_CLASSIC_SHADER_BINARY_VERSION; } /* API outputs include position. Unlinked shaders additionally reserve a diff --git a/src/asahi/vulkan/hk_buffer.c b/src/asahi/vulkan/hk_buffer.c index 560b4d3e1c8c..f1df2beaaf1d 100644 --- a/src/asahi/vulkan/hk_buffer.c +++ b/src/asahi/vulkan/hk_buffer.c @@ -350,8 +350,7 @@ hk_CreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, } } - if ((dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && (buffer->vk.create_flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT)) { const uint64_t entries = DIV_ROUND_UP(vma_size_B, AIL_PAGESIZE); diff --git a/src/asahi/vulkan/hk_buffer_view.c b/src/asahi/vulkan/hk_buffer_view.c index dfd5455c6eb8..1e75a4a1d19a 100644 --- a/src/asahi/vulkan/hk_buffer_view.c +++ b/src/asahi/vulkan/hk_buffer_view.c @@ -79,8 +79,7 @@ hk_get_buffer_format_features(struct hk_physical_device *pdev, if (p_format == PIPE_FORMAT_R32_UINT || p_format == PIPE_FORMAT_R32_SINT || (p_format == PIPE_FORMAT_R32_FLOAT && - (pdev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(pdev->dev.chip)))) + agx_chip_g17p_or_m5(pdev->dev.chip))) features |= VK_FORMAT_FEATURE_2_STORAGE_TEXEL_BUFFER_ATOMIC_BIT; } @@ -103,8 +102,7 @@ hk_CreateBufferView(VkDevice _device, const VkBufferViewCreateInfo *pCreateInfo, enum pipe_format format = hk_format_to_pipe_format(view->vk.format); const struct util_format_description *desc = util_format_description(format); - const bool g17p = agx_native_graphics(&device->dev) || - agx_chip_g17_m5(device->dev.chip); + const bool g17p = agx_chip_native_or_m5(device->dev.chip); const bool rgb32 = ail_pixel_format[format].channels == AGX_CHANNELS_R32G32B32_EMULATED; @@ -266,8 +264,7 @@ hk_CreateBufferView(VkDevice _device, const VkBufferViewCreateInfo *pCreateInfo, if (hk_native_pbe_supported(generation)) { hk_pack_native_pbe(generation, &view->pbe, &pbe); - } else if (agx_native_graphics(&device->dev) || - agx_chip_g17_m5(device->dev.chip)) { + } else if (agx_chip_native_or_m5(device->dev.chip)) { /* AGX3's linear PBE is architectural and has no software tail field, * exactly like the texture above: the store lowering adds the tail from * the buffer metadata. A format the native packer cannot represent (the diff --git a/src/asahi/vulkan/hk_cmd_buffer.c b/src/asahi/vulkan/hk_cmd_buffer.c index ce163222b9e7..fd350a5d1554 100644 --- a/src/asahi/vulkan/hk_cmd_buffer.c +++ b/src/asahi/vulkan/hk_cmd_buffer.c @@ -1253,7 +1253,7 @@ hk_CmdPipelineBarrier2(VkCommandBuffer commandBuffer, } /* M5 records its barriers with the native dependency tracker. */ - if (!agx_native_graphics(&dev->dev) && !agx_chip_g17_m5(dev->dev.chip)) { + if (!agx_chip_native_or_m5(dev->dev.chip)) { hk_cmd_buffer_end_compute(cmd); hk_cmd_buffer_end_graphics(cmd); /* Preserve the same conservative ordering in the shared submit graph, @@ -1344,7 +1344,7 @@ hk_CmdPipelineBarrier2(VkCommandBuffer commandBuffer, * alone leaves the data in the GPU caches, and the end of the command * does not reliably write it back before completion is reported when * render work shares the queue. */ - if ((dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && hk_dependency_has_host_access(pDependencyInfo)) { struct hk_sync_dep dep[HK_SYNC_NUM_SQ]; hk_sync_src_dep(cmd, src_kinds, cmd->current_cs.cs, dep); @@ -1737,7 +1737,7 @@ hk_m5_note_push_writes(struct hk_cmd_buffer *cmd, uint32_t count, const VkWriteDescriptorSet *writes) { const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; - if (!agx_chip_native_agx3(chip) && !agx_chip_g17_m5(chip)) + if (!agx_chip_native_or_m5(chip)) return; for (uint32_t i = 0; i < count; ++i) { @@ -1758,7 +1758,7 @@ hk_m5_note_push_template(struct hk_cmd_buffer *cmd, const void *data) { const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; - if (!agx_chip_native_agx3(chip) && !agx_chip_g17_m5(chip)) + if (!agx_chip_native_or_m5(chip)) return; for (uint32_t i = 0; i < template->entry_count; ++i) { @@ -4400,12 +4400,10 @@ hk_cs_init_graphics(struct hk_cmd_buffer *cmd, struct hk_cs *cs) /* Only the native AGX3 path submits the spans (hk_queue.c). G18G * submits them too, as it did before the paths were split. */ - const bool g18g = dev->dev.chip == AGX_CHIP_G18G; - if (agx_native_graphics(&dev->dev) || g18g) + if (agx_chip_native_or_g18g(dev->dev.chip)) hk_cs_capture_fragment_attachments(dev, render, cs); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - g18g) { + if (agx_chip_agx3_path(dev->dev.chip)) { /* The final VDM word stays zero when this selector is the * UINT32_MAX sentinel. This reproduces m1n1's direct-triangle prefix. */ cs->agx3_active_context_selector_valid = true; @@ -4677,8 +4675,7 @@ hk_ensure_cs_has_space(struct hk_cmd_buffer *cmd, struct hk_cs *cs, cs->stream_linked |= linked; /* Conservative: G17P and the M5 re-emit their restart state after a * link. */ - if (vdm && (hk_cmd_buffer_device(cmd)->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip))) + if (vdm && agx_chip_g17p_or_m5(hk_cmd_buffer_device(cmd)->dev.chip)) cs->restart_index_set = false; } @@ -4741,8 +4738,7 @@ hk_optimize_empty_vdm(struct hk_cmd_buffer *cmd) /* An empty final stream of a pass with earlier draws is not an empty * render. Replacing it with the load-op clears would erase those draws. */ const bool continuation = cmd->sync.pass_vdm != cs; - if (continuation && !agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip)) + if (continuation && !agx_chip_native_or_m5(dev->dev.chip)) return false; /* Two reasons to keep the graphics representation on AGX3 rather than @@ -4769,8 +4765,7 @@ hk_optimize_empty_vdm(struct hk_cmd_buffer *cmd) * common finalizer will append the native VDM terminator without uploading * any ordinary vertex or fragment program. */ - const bool native_eot = agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip); + const bool native_eot = agx_chip_native_or_m5(dev->dev.chip); const bool output_only_through_eot = native_eot && render->g17p_direct_color_resolve; @@ -4912,8 +4907,7 @@ hk_defer_clear(struct hk_cmd_buffer *cmd, struct hk_image *image, ? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT : VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - if ((!agx_chip_native_agx3(dev->dev.chip) && - !agx_chip_g17_m5(dev->dev.chip)) || + if (!agx_chip_native_or_m5(dev->dev.chip) || cmd->in_meta || cmd->vk.pool->queue_family_index >= pdev->queue_family_count || !(pdev->queue_families[cmd->vk.pool->queue_family_index].queue_flags & diff --git a/src/asahi/vulkan/hk_cmd_buffer.h b/src/asahi/vulkan/hk_cmd_buffer.h index d52d38c7e9c2..3a571217412f 100644 --- a/src/asahi/vulkan/hk_cmd_buffer.h +++ b/src/asahi/vulkan/hk_cmd_buffer.h @@ -2862,8 +2862,7 @@ hk_reserve_scratch(struct hk_cmd_buffer *cmd, struct hk_cs *cs, * SPECTPR. There is no helper-program stack, and the kernel rejects a * command that names one. */ if ((s->b.info.scratch_size == 0 && s->b.info.preamble_scratch_size == 0) || - agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip)) + agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip)) return; hk_reserve_scratch_slow(cmd, cs, s); @@ -2875,7 +2874,7 @@ static inline bool hk_sync_image_class(const struct hk_cmd_buffer *cmd) { const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; - return chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip); + return agx_chip_g17p_or_m5(chip); } /* AGX2 returns its shader-base-relative USC offset. G17P returns the absolute diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index eb866bea3896..9a3fabc2448b 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -199,7 +199,7 @@ hk_g17p_xfb_vertex_side_effects(struct hk_cmd_buffer *cmd, struct hk_api_shader *gs = gfx->shaders[MESA_SHADER_GEOMETRY]; const struct hk_device *dev = hk_cmd_buffer_device(cmd); - return (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + return agx_chip_native_or_m5(dev->dev.chip) && gfx->xfb_enabled && gs && gs->is_passthrough && hw_vs == &gs->variants[HK_GS_VARIANT_RAST]; } @@ -2730,8 +2730,7 @@ hk_build_bg_eot_program(struct hk_cmd_buffer *cmd, const VkRenderingInfo *info, * there's nothing to do. */ if (key.tib.spilled[i] && - (partial_render || store || agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip))) + (partial_render || store || agx_chip_native_or_m5(dev->dev.chip))) continue; if (store) { @@ -3411,7 +3410,7 @@ hk_g17p_note_first_draw(struct hk_cmd_buffer *cmd, struct hk_cs *cs, render->first_draw_seen = true; render->color_covered = 0; - if ((dev->dev.chip != AGX_CHIP_G17P && !agx_chip_g17_m5(dev->dev.chip)) || + if (!agx_chip_g17p_or_m5(dev->dev.chip) || cmd->in_meta || cs != render->zls_first_cs || cs->stats.cmds || cs->m5_continued_pass || hk_conditional_render_is_active(&cmd->state.conditional, cmd->in_meta, @@ -3524,7 +3523,7 @@ hk_tilebuffer_layout(const struct hk_device *dev, const VkFormat *vk_formats, const VkFormat format = *(const VkFormat *)((const uint8_t *)vk_formats + i * stride); formats[i] = hk_format_to_pipe_format(format); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { formats[i] = hk_padded_image_format(formats[i]); const enum pipe_format integer = hk_scaled_texture_format(formats[i]); if (integer != PIPE_FORMAT_NONE) @@ -3571,7 +3570,7 @@ static uint8_t hk_resident_attachments(const struct hk_device *dev, const struct hk_rendering_state *render) { - if ((!agx_chip_g17_m5(dev->dev.chip) && dev->dev.chip != AGX_CHIP_G17P) || + if (!agx_chip_g17p_or_m5(dev->dev.chip) || render->tilebuffer.nr_samples <= 1) return 0; @@ -3905,8 +3904,7 @@ hk_m5_pass_merge_candidate(struct hk_cmd_buffer *cmd, const struct hk_cs *cs) /* The instance is one ordinary render stream with draws, with no * pre/post-graphics streams, heap use or timestamps attached. */ - if ((!agx_chip_native_agx3(dev->dev.chip) && - !agx_chip_g17_m5(dev->dev.chip)) || + if (!agx_chip_native_or_m5(dev->dev.chip) || cmd->in_meta || cs->stats.cmds == 0 || cmd->sync.pass_vdm != cs || cmd->current_cs.pre_gfx || cmd->current_cs.post_gfx || cmd->uses_heap || cs->timestamp.start.handle || @@ -4064,7 +4062,7 @@ hk_m5_pass_merge_classify(struct hk_cmd_buffer *cmd, const char *what, * instance would load. */ const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; if (transition && image && - (chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && + agx_chip_g17p_or_m5(chip) && !hk_m5_image_is_attachment(&m->render, image) && !(image->create_flags & (VK_IMAGE_CREATE_ALIAS_BIT | VK_IMAGE_CREATE_SPARSE_BINDING_BIT))) @@ -4208,7 +4206,7 @@ hk_m5_attachments_exclude_descriptors(const struct hk_cmd_buffer *cmd, const VkRenderingInfo *info) { const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; - if (chip != AGX_CHIP_G17P && !agx_chip_g17_m5(chip)) + if (!agx_chip_g17p_or_m5(chip)) return false; const VkRenderingAttachmentInfo *ds[] = {info->pDepthAttachment, @@ -4612,8 +4610,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, * their producer even for a whole-tile render area: an earlier * attachment clear may have been lowered to compute. */ preserve_loaded_color[nr_written] = - (dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_g17p_or_m5(dev->dev.chip) && pRenderingInfo->pColorAttachments[i].loadOp == VK_ATTACHMENT_LOAD_OP_LOAD; written[nr_written++] = render->color_att[i].iview; @@ -4648,8 +4645,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, /* On G17P, zero dimensions are the native inactive-ZLS encoding. Keep * them zero for attachmentless and colour-only rendering; every control * stream, including a partial stream, inherits that state from render. */ - if (!render->cr.zls_width && !agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip)) { + if (!render->cr.zls_width && !agx_chip_native_or_m5(dev->dev.chip)) { render->cr.zls_width = render->cr.width; render->cr.zls_height = render->cr.height; } @@ -4687,11 +4683,11 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, render->tilebuffer = hk_tilebuffer_layout( dev, &render->color_att[0].vk_format, sizeof(render->color_att[0]), render->color_att_count, render->tilebuffer.nr_samples, - (!agx_native_graphics(&dev->dev) && !agx_chip_g17_m5(dev->dev.chip)) || + !agx_chip_native_or_m5(dev->dev.chip) || !hk_agx3_g17p_single_layer_rendering(render->view_mask, layer_count), g17p_wide_ms_to_memory, hk_resident_attachments(dev, render)); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) render->g17p_rt0_layout_supported = hk_agx3_g17p_rt0_tile_layout_supported(&render->tilebuffer); @@ -4838,7 +4834,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, * The stride is unused for one layer; Apple's G17P Framebuffer writes * 0 for a sub-cacheline layer and cacheline units below one page, a * form the G17P kernel's ZLS validation does not accept. Send 0. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && stride_pages == 0) { assert(z_layout->depth_px == 1); render->cr.depth.stride = 0; @@ -4904,7 +4900,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); return; } - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && stride_pages == 0) { assert(s_layout->depth_px == 1); render->cr.stencil.stride = 0; @@ -4936,8 +4932,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, hk_pack_zls_control(&render->cr.zls_control_partial, z_layout, s_layout, attach_z, attach_s, incomplete_render_area, true); - const bool agx3 = agx_chip_native_agx3(dev->dev.chip) || - agx_chip_g17_m5(dev->dev.chip); + const bool agx3 = agx_chip_native_or_m5(dev->dev.chip); render->zls_precise = agx3 && z_layout != NULL; render->g17p_zls_touched = 0; render->g17p_zls_written = 0; @@ -5057,8 +5052,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, /* Resident targets retain compression. Only memory-backed targets * need their compressed contents converted before shader stores. */ - if ((agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G17P) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && !render->tilebuffer.spilled[i]) continue; @@ -5208,8 +5202,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, clear_count++; const bool clear_spills = - (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && agx_tilebuffer_spills(&render->tilebuffer); /* A G17P multisample tilebuffer wider than eight bytes per sample cannot @@ -5480,8 +5473,7 @@ hk_CmdEndRendering2KHR(VkCommandBuffer commandBuffer, * overlap. Retain upstream ordering on AGX2, including across command * buffers/submissions through the tracker's prior requirements. M5 * schedules its render passes like native AGX3. */ - if (!agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) && - !agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip)) + if (!agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip)) hk_sync_barrier(cmd, HK_SYNC_GFX, HK_SYNC_GFX); if (continuable && !need_resolve && cs->end == end_before && @@ -6167,7 +6159,7 @@ hk_launch_gs_prerast(struct hk_cmd_buffer *cmd, struct hk_cs *cs, grid_vs = agx_1d(gfx->tess.tes_direct_threads); /* Launch the vertex shader first */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { hk_dispatch_with_local_size(cmd, cs, vs, grid_vs, wg); } else { hk_reserve_scratch(cmd, cs, vs); @@ -6342,7 +6334,7 @@ hk_launch_tess(struct hk_cmd_buffer *cmd, struct hk_cs *cs, if (batch) { hk_launch_tess_batched(cmd, vs, tcs, grid_vs, grid_tcs, grid_tess, info, state); - } else if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + } else if (agx_chip_native_or_m5(dev->dev.chip)) { hk_dispatch_with_local_size(cmd, cs, vs, grid_vs, agx_workgroup(64, 1, 1)); hk_dispatch_with_local_size( @@ -6907,8 +6899,7 @@ hk_get_fast_linked_locked_vs(struct hk_device *dev, struct hk_shader *shader, { struct agx_shader_part *prolog = hk_get_prolog_epilog(dev, &key->prolog, sizeof(key->prolog), - (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) + agx_chip_native_or_m5(dev->dev.chip) ? agx_nir_vs_prolog_raw : agx_nir_vs_prolog, false, false, 0, 0, 0); if (!prolog) @@ -7571,7 +7562,7 @@ hk_get_fast_linked_locked_fs(struct hk_device *dev, struct hk_shader *shader, /* A G17P epilog selects each written target's pixel classes from its * position among all of the framebuffer's colour targets. */ BITSET_DECLARE(g17p_tile_partitions, AGX_G17P_MAX_BYTES_PER_SAMPLE) = {0}; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { const struct agx_tilebuffer_layout tib = key->epilog.native_imageblock ? agx_build_tilebuffer_layout_resident( @@ -7661,8 +7652,7 @@ hk_get_fast_linked_locked_fs(struct hk_device *dev, struct hk_shader *shader, ? build_g17p_fs_epilog : agx_nir_fs_epilog, true, epilog_stop, 0, g17p_tile_partitions, - (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) + agx_chip_native_or_m5(dev->dev.chip) ? key->epilog.nr_samples : 0); if (!epilog) { @@ -10299,7 +10289,7 @@ hk_vs_link_key_build(struct hk_device *dev, struct hk_shader *sw_vs, bool hw, /* G17P materialises adjacency into an index buffer before the hardware * vertex program. Applying the remap again in the prolog is wrong. */ - if (!agx_native_graphics(&dev->dev) && !agx_chip_g17_m5(dev->dev.chip)) + if (!agx_chip_native_or_m5(dev->dev.chip)) key->prolog.adjacency = prim; } @@ -10413,8 +10403,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, bool defer_api_sample_mask = agx_native_graphics(&dev->dev) && has_sample_mask && !nontrivial_force_early; - const bool native_samples = agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip); + const bool native_samples = agx_chip_native_or_m5(dev->dev.chip); if (native_samples && fs->info.fs.uses_sample_shading && dyn->ms.rasterization_samples > 1) { if (report_errors) @@ -10457,8 +10446,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, * (agx_nir_apply_api_mask_to_force_early()). */ .prolog.api_sample_mask = has_sample_mask && !defer_api_sample_mask && - ((!agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip)) || + (!agx_chip_native_or_m5(dev->dev.chip) || !nontrivial_force_early) ? api_sample_mask : 0xff, @@ -10500,8 +10488,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, agx_fs_epilog_apply_device_policy(dev->dev.chip, &key->epilog); key->epilog.native_spills = - (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && agx_tilebuffer_spills(in->tib); if (key->epilog.native_spills) { uint16_t base; @@ -10520,7 +10507,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, } if (!key->epilog.native_spills && - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && hk_uses_blend_constant(&dyn->cb) && (fs->info.agx3_combined_sampler_valid || fs->info.agx3_indexed_sampler_valid) && @@ -10545,7 +10532,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, const VkFormat format = *(const VkFormat *)( (const uint8_t *)in->color_formats + i * in->color_formats_stride); key->epilog.rt_formats[i] = hk_format_to_pipe_format(format); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { const enum pipe_format logical = key->epilog.rt_formats[i]; key->epilog.rt_formats[i] = hk_padded_image_format(logical); const enum pipe_format integer = @@ -10563,8 +10550,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, bool write_enable = dyn->cb.color_write_enables & BITFIELD_BIT(i); unsigned write_mask = write_enable ? cb->write_mask : 0; - if ((dev->dev.chip == AGX_CHIP_G16G || - agx_native_graphics(&dev->dev)) && !write_enable) { + if (agx_chip_native_agx3(dev->dev.chip) && !write_enable) { key->epilog.preserve_rt |= BITFIELD_BIT(i); key->epilog.blend.rt[i] = (struct agx_blend_rt_key){ .colormask = BITFIELD_MASK(4), @@ -11067,7 +11053,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, } if (IS_DIRTY(VP_VIEWPORTS) && - (dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip))) { + agx_chip_g17p_or_m5(dev->dev.chip)) { const float height = dyn->vp.viewports[0].height; const float bias = height != 0.0f ? 1.0f / (32.0f * height) : 0.0f; if (desc->root.line_y_bias != bias) { @@ -11414,9 +11400,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, size_t linkage_size = AGX_CF_BINDING_HEADER_LENGTH + (bindings * AGX_CF_BINDING_LENGTH); - const bool native_vit = agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G; + const bool native_vit = agx_chip_agx3_path(dev->dev.chip); struct agx_ptr t = hk_pool_usc_alloc(cmd, linkage_size, native_vit ? 64 : 16); if (!t.cpu) @@ -11801,7 +11785,7 @@ hk_needs_index_robustness(struct hk_cmd_buffer *cmd, struct agx_draw *draw, * page instead. */ if (draw->index_buffer_range_B == 0 || - ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + (agx_chip_native_or_m5(dev->dev.chip) && draw->index_buffer == AGX_ZERO_PAGE_ADDRESS && draw->index_buffer_range_B == 4)) { draw->index_buffer = AGX_ZERO_PAGE_ADDRESS; @@ -12110,7 +12094,7 @@ hk_flush_gfx_state(struct hk_cmd_buffer *cmd, uint32_t draw_id, * dereference the heap. Direct adjacency without restart uses no heap. */ const bool needs_heap = geom || tess || (*needs_idx_robust && !adj) || (adj && (draw->restart || - ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + (agx_chip_native_or_m5(dev->dev.chip) && agx_is_indirect(draw->b)))); if (needs_heap && !hk_cmd_ensure_geometry_heap(cmd)) return NULL; @@ -12121,7 +12105,7 @@ hk_flush_gfx_state(struct hk_cmd_buffer *cmd, uint32_t draw_id, * publication path as well; the generated body carries the matching * context-relative selector when that publication is fresh. */ const bool g17p_robust_index_path = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && *needs_idx_robust; const bool ordinary_draw_path = !geom && !tess && !adj && @@ -12137,7 +12121,7 @@ hk_flush_gfx_state(struct hk_cmd_buffer *cmd, uint32_t draw_id, * adjacency topology failed at vkEndCommandBuffer with * VK_ERROR_FEATURE_NOT_PRESENT. */ const bool g17p_transformed_path = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && (geom || tess || adj); if (desc->push_dirty) hk_cmd_buffer_flush_push_descriptors(cmd, desc); @@ -12146,8 +12130,7 @@ hk_flush_gfx_state(struct hk_cmd_buffer *cmd, uint32_t draw_id, * record. Geometry/XFB lowers even a non-indexed API draw to that packet, * so emitting the legacy state here as well produces two consecutive * restart records before the synthetic indexed draw. */ - if ((draw->restart || geom) && !agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip)) + if ((draw->restart || geom) && !agx_chip_native_or_m5(dev->dev.chip)) hk_flush_index(cmd, cs); /* Everything that can dirty render state for this draw has now run, so @@ -12742,7 +12725,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, * older path does in hk_needs_index_robustness. The one-dword range bounds * hardware fetches to the zero page; it is not a count limit. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && draw_.indexed && draw_.index_buffer_range_B == 0) { draw_.index_buffer = AGX_ZERO_PAGE_ADDRESS; draw_.index_buffer_range_B = 4; @@ -12751,7 +12734,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, const struct agx_draw api_draw = draw_; bool conditional_direct_indexed = false; const uint64_t primitive_bound = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + agx_chip_native_or_m5(dev->dev.chip) ? hk_draw_primitive_bound(cmd, &api_draw) : 0; /* There is no native conditional-render packet on AGX. Lower the command @@ -12958,7 +12941,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, uint64_t out_draw = hk_pool_alloc(cmd, size, 4).gpu; struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { /* As in the direct case above, a G17P hardware vertex shader * never sees the prolog's remap, so the mapping has to reach * the input assembler as real indices. The output count is @@ -13001,7 +12984,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, * mapping as an index buffer instead and let the input assembler * apply it, which is the one path the vertex stage does see. */ if (count > 0 && - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip))) { + agx_chip_native_or_m5(dev->dev.chip)) { unsigned ib_B = count * sizeof(uint32_t); uint64_t ib = hk_pool_alloc(cmd, ib_B, 4).gpu; @@ -13085,7 +13068,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, /* G17P: its GPU-written indexed indirect packets set the restart * index. M5: for an empty draw the kernel writes a Stream Link over * the slot, which counts as a link (hk_cmd_buffer.c). */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) cs->restart_index_set = false; } else { if (agx_native_graphics(&dev->dev)) { @@ -13836,8 +13819,7 @@ hk_g17p_emit_indirect_record(struct hk_cmd_buffer *cmd, uint16_t draw_id, /* A record after the first of a multi-draw republishes the previous * record's program with its own draw parameters. */ const uint64_t pipeline_program = - continuing && (agx_chip_native_agx3(dev->dev.chip) || - agx_chip_g17_m5(dev->dev.chip)) + continuing && agx_chip_native_or_m5(dev->dev.chip) ? hk_m5_multi_draw_vertex_program(cmd, hw_vs, linked_hw_vs) : hk_upload_usc_words(cmd, hw_vs, linked_hw_vs); @@ -13942,7 +13924,7 @@ hk_draw_indirect_inner(VkCommandBuffer commandBuffer, uint64_t base, const struct hk_device *dev = hk_cmd_buffer_device(cmd); int eligible = - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) ? -1 : 0; + agx_chip_native_or_m5(dev->dev.chip) ? -1 : 0; for (unsigned draw_id = 0; draw_id < drawCount; ++draw_id) { uint64_t addr = base + stride * draw_id; hk_draw_indirect_record(cmd, draw_id, agx_draw_indirect(addr), @@ -14056,7 +14038,7 @@ hk_draw_indexed_indirect_inner(VkCommandBuffer commandBuffer, uint64_t buffer, const struct hk_device *dev = hk_cmd_buffer_device(cmd); int eligible = - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) ? -1 : 0; + agx_chip_native_or_m5(dev->dev.chip) ? -1 : 0; for (unsigned draw_id = 0; draw_id < drawCount; ++draw_id) { uint64_t addr = buffer + stride * draw_id; struct hk_addr_range buf = cmd->state.gfx.index.buffer; diff --git a/src/asahi/vulkan/hk_cmd_meta.c b/src/asahi/vulkan/hk_cmd_meta.c index 745ad55fd455..474bb89c7a0c 100644 --- a/src/asahi/vulkan/hk_cmd_meta.c +++ b/src/asahi/vulkan/hk_cmd_meta.c @@ -521,8 +521,7 @@ hk_g17p_sparse_buffer_copy(struct hk_cmd_buffer *cmd, uint64_t dst_addr, VkDeviceSize size) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - assert((agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) && src_buffer->sparse_map); + assert(agx_chip_native_or_m5(dev->dev.chip) && src_buffer->sparse_map); /* Resident writes use the primary VA while nonresident reads must use the * zero-page shadow. Read the live map in the copy shader so a sparse bind @@ -1347,11 +1346,7 @@ get_image_copy_pipeline(struct vk_device *device, struct vk_meta_device *meta, * The existing NIR pack/unpack path retains a single aligned raw store. * Meta pipelines are cached per device, so no extra key is needed. */ .nir = build_image_copy_shader(key, - !agx_native_graphics(&container_of(device, struct hk_device, vk)->dev) && - !agx_chip_g17_m5(container_of(device, struct hk_device, vk)->dev.chip) && - container_of(device, struct hk_device, vk)->dev.chip != AGX_CHIP_G16G && - /* G18G (AGX3) stores raw packed bytes too. */ - container_of(device, struct hk_device, vk)->dev.chip != AGX_CHIP_G18G, + !agx_chip_agx3_path(container_of(device, struct hk_device, vk)->dev.chip), container_of(device, struct hk_device, vk)->dev.chip == AGX_CHIP_G18G), }; @@ -1418,9 +1413,7 @@ hk_meta_copy_image_to_buffer2(struct vk_command_buffer *cmd, const enum agx_chip chip = container_of(device, struct hk_device, vk)->dev.chip; const bool g17p_color = - (agx_native_graphics( - &container_of(device, struct hk_device, vk)->dev) || - agx_chip_g17_m5(chip)) && + agx_chip_native_or_m5(chip) && !vk_format_is_depth_or_stencil(image->format); const struct hk_image *hk_image = container_of(image, struct hk_image, vk); @@ -3270,8 +3263,7 @@ hk_xfer_copybuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *info VK_FROM_HANDLE(hk_cmd_buffer, cmd, commandBuffer); struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { struct hk_meta_save save; hk_meta_begin(cmd, &save, VK_PIPELINE_BIND_POINT_COMPUTE); struct hk_copy_batch batch = {0}; @@ -3401,8 +3393,7 @@ hk_g17p_copy_buffer_to_image_supported( static bool hk_g17p_block_copy_format(struct hk_device *dev, VkFormat format) { - if (!dev || (!agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip))) + if (!dev || !agx_chip_native_or_m5(dev->dev.chip)) return false; switch (hk_g17p_block_format_family(format)) { @@ -3682,7 +3673,7 @@ hk_g17p_copy_padded_rgb_buffer_image( VkImageLayout image_layout, bool to_image) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if ((!agx_native_graphics(&dev->dev) && !agx_chip_g17_m5(dev->dev.chip)) || + if (!agx_chip_native_or_m5(dev->dev.chip) || region_count == 0 || image->vk.samples != VK_SAMPLE_COUNT_1_BIT || (image_layout != (to_image ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL @@ -4078,8 +4069,7 @@ hk_g17p_copy_uncompressed_buffer_to_image_supported( struct hk_device *dev, const struct hk_buffer *buffer, const struct hk_image *image, const VkCopyBufferToImageInfo2 *info) { - if ((!agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip)) || info->regionCount == 0) + if (!agx_chip_native_or_m5(dev->dev.chip) || info->regionCount == 0) return false; for (uint32_t r = 0; r < info->regionCount; ++r) { @@ -4400,7 +4390,7 @@ hk_g17p_raw_image_copy_supported(struct hk_device *dev, const struct hk_image *dst, const VkCopyImageInfo2 *info) { - if ((!agx_native_graphics(&dev->dev) && !agx_chip_g17_m5(dev->dev.chip)) || + if (!agx_chip_native_or_m5(dev->dev.chip) || info->regionCount == 0 || src->vk.samples != dst->vk.samples || (src->vk.samples != VK_SAMPLE_COUNT_1_BIT && @@ -4647,7 +4637,7 @@ hk_xfer_copybuffertoimage2(VkCommandBuffer commandBuffer, * cause was not isolated). Its draws work, so upload through the common * graphics copy. */ bool gfx = hk_copy_requires_gfx(dst_image) || dev->dev.chip == AGX_CHIP_G18G; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { uint8_t plane; VkFormat format; uint32_t api_block_B, physical_block_B; @@ -4815,7 +4805,7 @@ hk_xfer_copyimagetobuffer2(VkCommandBuffer commandBuffer, VkFormat format; uint32_t api_block_B, physical_block_B; const bool padded_rgb = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && pCopyImageToBufferInfo->regionCount > 0 && hk_g17p_buffer_upload_plane( src_image, @@ -4868,9 +4858,7 @@ hk_xfer_copyimage2(VkCommandBuffer commandBuffer, /* G17P copies through its native tile renderer, as buffer uploads do. * The common meta path preserves partial rectangles, layers and format * reinterpretation without the AGX2 compute imageblock protocol. */ - bool gfx = agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G || /* see the upload above */ + bool gfx = agx_chip_agx3_path(dev->dev.chip) || /* see the upload above */ hk_copy_requires_gfx(dst_image); VkPipelineBindPoint bind_point = hk_bind_point(gfx); @@ -4878,8 +4866,7 @@ hk_xfer_copyimage2(VkCommandBuffer commandBuffer, hk_meta_begin(cmd, &save, bind_point); if (gfx) { - const bool native = agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip); + const bool native = agx_chip_native_or_m5(dev->dev.chip); /* Both sides of a depth/stencil copy use the same views: per-plane * aliases when either depth plane is compressed. */ const bool zs_planes = diff --git a/src/asahi/vulkan/hk_cmd_pool.c b/src/asahi/vulkan/hk_cmd_pool.c index a8b4710e4b9b..5ab203b416e1 100644 --- a/src/asahi/vulkan/hk_cmd_pool.c +++ b/src/asahi/vulkan/hk_cmd_pool.c @@ -132,7 +132,7 @@ hk_cmd_bo_create(struct hk_cmd_pool *pool, enum hk_cmd_bo_type type, * through a draw. These BOs are recycled by the command pool, so populate * and initialize their shared mappings once at creation; subsequent command * buffers reuse already-resident pages without adding per-draw work. */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { memset(bo->map, 0, bo->bo->size); if (hk_g17p_cached_cmd_memory(&dev->dev)) util_flush_range(bo->map, bo->bo->size); @@ -451,7 +451,7 @@ hk_cmd_pool_free_bo_list(struct hk_cmd_pool *pool, enum hk_cmd_bo_type type, /* Under virtio every BO is an external object, which the host kernel locks * on every submit: a pool hoarding hundreds of idle BOs slows all submits. */ const unsigned max_free = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && type == HK_CMD_BO_MAIN && !dev->dev.is_virtio ? HK_G17P_CMD_POOL_MAIN_BO_MAX : HK_CMD_POOL_BO_MAX; diff --git a/src/asahi/vulkan/hk_descriptor_set.c b/src/asahi/vulkan/hk_descriptor_set.c index c1c0e8f672fb..8f901582ec68 100644 --- a/src/asahi/vulkan/hk_descriptor_set.c +++ b/src/asahi/vulkan/hk_descriptor_set.c @@ -1470,7 +1470,7 @@ hk_GetDescriptorEXT(VkDevice _device, layout->descriptor_generation = agx_chip_descriptor_generation(dev->dev.chip); layout->native_sampler_indices = - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip); + agx_chip_native_or_m5(dev->dev.chip); layout->binding_count = 1; layout->binding[0] = (struct hk_descriptor_set_binding_layout){ .type = type, diff --git a/src/asahi/vulkan/hk_descriptor_set_layout.c b/src/asahi/vulkan/hk_descriptor_set_layout.c index a6f64e94fb33..b9ac65e2f352 100644 --- a/src/asahi/vulkan/hk_descriptor_set_layout.c +++ b/src/asahi/vulkan/hk_descriptor_set_layout.c @@ -59,8 +59,7 @@ hk_descriptor_stride_align_for_type( * sideband (+72) did not fit the bare 64-byte texture/PBE pair, the * shader read zero tile geometry there, and atomics addressed the * twiddled image row-major. */ - if (agx_native_graphics(&pdev->dev) || agx_chip_g17_m5(pdev->dev.chip) || - pdev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(pdev->dev.chip)) { *stride += HK_G17P_STORAGE_SW_SIZE; /* imgwci addresses PBE records in a heap, and stores treat the * descriptor set as that heap. The PBE descriptor starts 32 bytes @@ -83,7 +82,7 @@ hk_descriptor_stride_align_for_type( * heap indices and 24 bytes of buffer size/offset/address metadata. * The shader must never decode AGX2 software fields from Gen9 bytes. */ - if (agx_native_graphics(&pdev->dev) || agx_chip_g17_m5(pdev->dev.chip)) { + if (agx_chip_native_or_m5(pdev->dev.chip)) { *stride = AGX_G17P_BUFFER_TEXTURE_DESCRIPTOR_SIZE; /* Texel-buffer stores address the PBE through the set's PBE heap, * like storage images. */ @@ -123,8 +122,7 @@ hk_descriptor_stride_align_for_type( hk_sampled_image_descriptor_layout(generation).stride; } else { *stride = HK_MAX_DESCRIPTOR_SIZE; - *alignment = (agx_native_graphics(&pdev->dev) || - agx_chip_g17_m5(pdev->dev.chip)) + *alignment = agx_chip_native_or_m5(pdev->dev.chip) ? HK_G17P_STORAGE_ALIGNMENT : 8; } @@ -315,8 +313,7 @@ hk_CreateDescriptorSetLayout(VkDevice device, layout->binding_count = num_bindings; layout->descriptor_generation = agx_chip_descriptor_generation(pdev->dev.chip); - layout->native_sampler_indices = agx_native_graphics(&pdev->dev) || - agx_chip_g17_m5(pdev->dev.chip); + layout->native_sampler_indices = agx_chip_native_or_m5(pdev->dev.chip); for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) { const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[j]; diff --git a/src/asahi/vulkan/hk_device.c b/src/asahi/vulkan/hk_device.c index 7a3c6c593393..2d23a3ccda81 100644 --- a/src/asahi/vulkan/hk_device.c +++ b/src/asahi/vulkan/hk_device.c @@ -156,8 +156,7 @@ hk_upload_rodata(struct hk_device *dev) memcpy(map + offs + i * sampler_size, &txf, sampler_size); offs += sampler_count * sampler_size; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { const uint64_t pointers[2] = { dev->sampled_images.base_va, dev->samplers.table.bo->va->addr, @@ -277,8 +276,7 @@ hk_init_sampler_heap(struct hk_device *dev, struct hk_sampler_heap *h) VkResult result = hk_descriptor_table_init(dev, &h->table, sampler_size, 1024, agx_native_graphics(&dev->dev) ? 4096 - : (agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) ? 2048 + : agx_chip_hal300_path(dev->dev.chip) ? 2048 : 1024); if (result != VK_SUCCESS) { @@ -286,8 +284,7 @@ hk_init_sampler_heap(struct hk_device *dev, struct hk_sampler_heap *h) return result; } - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { /* Native indexed read() and sample() share the sampler table prefix. * Reserve texel-fetch sampler zero once, so mixed shaders need no * per-fetch pointer switch or descriptor copy. Preserve at least the @@ -1197,8 +1194,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice, if (result != VK_SUCCESS) goto fail_dev; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { /* Capacity stays HK_MAX_DESCRIPTORS, but memory is added a chunk at a * time as image and buffer views are created. */ result = hk_descriptor_table_init(dev, &dev->sampled_images, 32, @@ -1248,7 +1244,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice, * M5. Upload their immutable internal kernels with the device instead of * making the first vkCmdDraw that needs each kernel serialize on the * cache lock and allocate its executable image. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && !hk_g17p_prewarm_poly_kernels(dev)) { result = VK_ERROR_OUT_OF_DEVICE_MEMORY; goto fail_bg_eot; @@ -1374,8 +1370,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice, hk_descriptor_table_finish(dev, &dev->occlusion_queries); fail_sampled_images: hk_texel_windows_finish(dev); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) + if (agx_chip_agx3_path(dev->dev.chip)) hk_descriptor_table_finish(dev, &dev->sampled_images); fail_samplers: hk_destroy_sampler_heap(dev, &dev->samplers); @@ -1462,8 +1457,7 @@ hk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) hk_destroy_sampler_heap(dev, &dev->samplers); hk_texel_windows_finish(dev); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) + if (agx_chip_agx3_path(dev->dev.chip)) hk_descriptor_table_finish(dev, &dev->sampled_images); hk_descriptor_table_finish(dev, &dev->occlusion_queries); agx_bo_unreference(&dev->dev, dev->rodata.heap_bo); diff --git a/src/asahi/vulkan/hk_device.h b/src/asahi/vulkan/hk_device.h index 82846f8c6bbd..57d6d6662a7c 100644 --- a/src/asahi/vulkan/hk_device.h +++ b/src/asahi/vulkan/hk_device.h @@ -563,7 +563,7 @@ hk_cdm_alias_scope(const struct hk_device *dev) static inline bool hk_cdm_memory_scope_form(const struct hk_device *dev) { - return dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip); + return agx_chip_g17p_or_m5(dev->dev.chip); } /* Whether it is still unknown if the GPU's caches are tagged by virtual diff --git a/src/asahi/vulkan/hk_format.c b/src/asahi/vulkan/hk_format.c index 93c4971aaf64..c99d8f2b2e08 100644 --- a/src/asahi/vulkan/hk_format.c +++ b/src/asahi/vulkan/hk_format.c @@ -48,7 +48,7 @@ hk_modifier_features(const struct agx_device *dev, uint64_t mod, /* G17P and M5 share compressed images without storage or host-copy * access (hk_g17p_shared_compression_shape()). */ - if (dev->chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->chip)) + if (agx_chip_g17p_or_m5(dev->chip)) return props->optimalTilingFeatures & ~(VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT | VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT | diff --git a/src/asahi/vulkan/hk_g17p_compression.h b/src/asahi/vulkan/hk_g17p_compression.h index 9210e7b6da85..5533d27b08fb 100644 --- a/src/asahi/vulkan/hk_g17p_compression.h +++ b/src/asahi/vulkan/hk_g17p_compression.h @@ -407,7 +407,7 @@ hk_g17p_shared_compression_shape(enum agx_chip chip, VkFormat format, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT; - return (chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && + return agx_chip_g17p_or_m5(chip) && type == VK_IMAGE_TYPE_2D && !(flags & ~allowed_flags) && !(usage & ~allowed_usage) && hk_g17p_compression_color_format(format); diff --git a/src/asahi/vulkan/hk_g17p_meta_copy_core.c b/src/asahi/vulkan/hk_g17p_meta_copy_core.c index 1a51cdf3915b..e11a524ea5e5 100644 --- a/src/asahi/vulkan/hk_g17p_meta_copy_core.c +++ b/src/asahi/vulkan/hk_g17p_meta_copy_core.c @@ -235,7 +235,7 @@ hk_g17p_compressed_copy_plan( memset(plan, 0, sizeof(*plan)); if (!copy || !plan || - (!agx_chip_native_agx3(copy->chip) && !agx_chip_g17_m5(copy->chip)) || + !agx_chip_native_or_m5(copy->chip) || hk_g17p_block_format_family(copy->format) == HK_G17P_BLOCK_FORMAT_NONE || !(image_is_source @@ -509,8 +509,7 @@ hk_g17p_buffer_to_image_copy_supported( const bool one_dimensional = copy && copy->image_type == VK_IMAGE_TYPE_1D; const bool volume = copy && copy->image_type == VK_IMAGE_TYPE_3D; - if (!copy || (!agx_chip_native_agx3(copy->chip) && - !agx_chip_g17_m5(copy->chip)) || + if (!copy || !agx_chip_native_or_m5(copy->chip) || !hk_g17p_transfer_dst_layout_supported(copy->layout) || (!one_dimensional && copy->image_type != VK_IMAGE_TYPE_2D && !volume) || copy->samples != VK_SAMPLE_COUNT_1_BIT || @@ -676,7 +675,7 @@ hk_g17p_image_copy_slice(enum agx_chip chip, VkImageType src_type, const bool two_d_three_d = (src_1d_or_2d && dst_3d) || (dst_1d_or_2d && src_3d); const bool valid_pair = same_type || one_d_two_d || two_d_three_d; - if ((!agx_chip_native_agx3(chip) && !agx_chip_g17_m5(chip)) || + if (!agx_chip_native_or_m5(chip) || !region || !out || !valid_types || !valid_pair || src_layers == 0 || src_layers != dst_layers || slice >= src_layers || diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index f35f2783d823..cd39d142915b 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -92,7 +92,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, /* D16S8 uses the existing independent D16 and S8 planes, as D32S8 does * on G17P and M5. */ if (vk_format == VK_FORMAT_D16_UNORM_S8_UINT) { - if (pdev->dev.chip != AGX_CHIP_G17P && !agx_chip_g17_m5(pdev->dev.chip)) + if (!agx_chip_g17p_or_m5(pdev->dev.chip)) return 0; p_format = PIPE_FORMAT_Z16_UNORM; } @@ -100,7 +100,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, return 0; enum pipe_format padded = hk_padded_image_format(p_format); - if ((agx_native_graphics(&pdev->dev) || agx_chip_g17_m5(pdev->dev.chip)) && + if (agx_chip_native_or_m5(pdev->dev.chip) && padded != p_format) { /* Linear and external modifier layouts must retain the API's packed * texel stride. This path is restricted to driver-owned optimal images. */ @@ -232,8 +232,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, /* Our image atomic lowering doesn't bother to handle linear */ if ((p_format == PIPE_FORMAT_R32_UINT || p_format == PIPE_FORMAT_R32_SINT || (p_format == PIPE_FORMAT_R32_FLOAT && - (pdev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(pdev->dev.chip)))) && + agx_chip_g17p_or_m5(pdev->dev.chip))) && tiling == VK_IMAGE_TILING_OPTIMAL) { features |= VK_FORMAT_FEATURE_2_STORAGE_IMAGE_ATOMIC_BIT; @@ -456,7 +455,7 @@ hk_can_compress(const struct agx_device *dev, VkFormat format, unsigned plane, * S8_UINT here, and zink gives its depth/stencil images feedback-loop * usage. */ const bool depth_feedback = - (dev->chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->chip)) && + agx_chip_g17p_or_m5(dev->chip) && allow_agx3 && hk_g17p_compression_depth_format(api_format); if ((usage & (VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT | VK_IMAGE_USAGE_STORAGE_BIT)) || @@ -957,7 +956,7 @@ hk_GetPhysicalDeviceImageFormatProperties2( return VK_ERROR_FORMAT_NOT_SUPPORTED; const bool g17p_compressed = - (pdev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(pdev->dev.chip)) && + agx_chip_g17p_or_m5(pdev->dev.chip) && pImageFormatInfo->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT && drm_mod_info && drm_mod_info->drmFormatModifier == @@ -1573,7 +1572,7 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, /* G17P and M5 share compressed colour images only in the shape both sides * allocate identically (hk_g17p_shared_compression_eligible()). */ if (image->vk.drm_format_mod == DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED && - (dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_g17p_or_m5(dev->dev.chip) && !(hk_g17p_shared_compression_supported( &dev->dev, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->flags, pCreateInfo->usage, pCreateInfo->pNext) && @@ -1598,7 +1597,7 @@ hk_image_init(struct hk_device *dev, struct hk_image *image, const enum pipe_format p_format = hk_format_to_pipe_format(format); const enum pipe_format layout_format = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && pCreateInfo->tiling == VK_IMAGE_TILING_OPTIMAL ? hk_padded_image_format(p_format) : p_format; diff --git a/src/asahi/vulkan/hk_image_view.c b/src/asahi/vulkan/hk_image_view.c index 2dbaa6b54614..fae2c36315fa 100644 --- a/src/asahi/vulkan/hk_image_view.c +++ b/src/asahi/vulkan/hk_image_view.c @@ -242,7 +242,7 @@ pack_texture(struct hk_device *dev, struct hk_image_view *view, p_format = packed_ycbcr == 8 ? PIPE_FORMAT_R8G8B8A8_UNORM : PIPE_FORMAT_R16G16B16A16_UNORM; const bool padded_rgb = - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && hk_padded_image_format(p_format) != p_format; if (padded_rgb) p_format = hk_padded_image_format(p_format); @@ -481,7 +481,7 @@ pack_pbe(struct hk_device *dev, struct hk_image_view *view, unsigned view_plane, unsigned layer = view->vk.base_array_layer; enum pipe_format p_format = format_for_plane(view, view_plane); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { p_format = hk_padded_image_format(p_format); enum pipe_format integer = hk_scaled_texture_format(p_format); if (integer != PIPE_FORMAT_NONE) @@ -497,8 +497,7 @@ pack_pbe(struct hk_device *dev, struct hk_image_view *view, unsigned view_plane, if (eot) p_format = util_format_linear(p_format); - if (eot && (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip))) + if (eot && agx_chip_native_or_m5(dev->dev.chip)) p_format = hk_eot_pbe_format(&dev->dev, p_format); const struct util_format_description *desc = @@ -894,8 +893,7 @@ hk_image_view_init(struct hk_device *dev, struct hk_image_view *view, if (!textures_valid) return VK_ERROR_FORMAT_NOT_SUPPORTED; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { VkResult result = hk_image_view_heap_add( dev, view, replay, p, HK_VIEW_HEAP_SAMPLED, &view->planes[p].sampled, &view->planes[p].sampled_heap_index); @@ -949,8 +947,7 @@ hk_image_view_init(struct hk_device *dev, struct hk_image_view *view, view->planes[p].emrt_pbe_valid = pack_pbe( dev, view, p, HK_DESC_USAGE_EMRT, &view->planes[p].emrt_pbe, &view->planes[p].emrt_atomic_sw, NULL); - if ((agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && (view->vk.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && view->planes[p].emrt_pbe_valid) { const struct ail_layout *layout = @@ -985,8 +982,7 @@ hk_DestroyImageView(VkDevice _device, VkImageView imageView, if (!view) return; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { for (unsigned p = 0; p < view->plane_count; ++p) { if (view->planes[p].emrt_read_heap_index) hk_image_view_heap_remove(dev, view, diff --git a/src/asahi/vulkan/hk_physical_device.c b/src/asahi/vulkan/hk_physical_device.c index 766ea1860a20..02f9cce28e1c 100644 --- a/src/asahi/vulkan/hk_physical_device.c +++ b/src/asahi/vulkan/hk_physical_device.c @@ -91,7 +91,7 @@ hk_hash_device_generation_contract(blake3_hasher *ctx, static bool hk_shader_fma_supported(enum agx_chip chip) { - return (chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && + return agx_chip_g17p_or_m5(chip) && agx_chip_exact_fma32(chip); } @@ -427,8 +427,7 @@ hk_get_device_features( .storagePushConstant16 = true, /* HAL200 interpolation is 32-bit, but the compiler performs matching * type-correct widening at ST_VARY and narrowing after interpolation. */ - .storageInputOutput16 = agx_chip_native_agx3(dev->chip) || - agx_chip_g17_m5(dev->chip), + .storageInputOutput16 = agx_chip_native_or_m5(dev->chip), .multiview = true, /* ViewIndex is lowered into the layer output of the last * pre-rasterization stage and the draw is duplicated per view, so @@ -1170,7 +1169,7 @@ hk_get_device_properties(const struct agx_device *dev, .apiVersion = hk_get_vk_version(), .driverVersion = vk_get_driver_version(), .vendorID = instance->drirc.debug.force_vk_vendor ?: VK_VENDOR_ID_MESA, - .deviceID = (agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip)) + .deviceID = agx_chip_native_or_m5(dev->chip) ? dev->params.chip_id : 0, .deviceType = VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, @@ -2267,7 +2266,7 @@ hk_create_drm_physical_device(struct vk_instance *_instance, /* Counted by the pre-graphics helpers, which every native chip runs; * hardware-qualified on M5 and G17P. */ supported_extensions.EXT_primitives_generated_query = - agx_chip_g17_m5(pdev->dev.chip) || pdev->dev.chip == AGX_CHIP_G17P; + agx_chip_g17p_or_m5(pdev->dev.chip); supported_extensions.EXT_mesh_shader = pdev->dev.chip == AGX_CHIP_G17S && (pdev->dev.params.features & DRM_ASAHI_FEATURE_RENDER_RESOURCES_V2); diff --git a/src/asahi/vulkan/hk_ppp_state.h b/src/asahi/vulkan/hk_ppp_state.h index f53c22306a6d..7fc471209198 100644 --- a/src/asahi/vulkan/hk_ppp_state.h +++ b/src/asahi/vulkan/hk_ppp_state.h @@ -14,7 +14,7 @@ static inline bool hk_ppp_emit_state(enum agx_chip chip, uint8_t **out, uint64_t gpu_base, size_t size) { - if (agx_chip_g17_m5(chip) || chip == AGX_CHIP_G18G) { + if (agx_chip_hal300_path(chip)) { if (!agx_m5_vdm_compact(gpu_base, &gpu_base)) return false; } diff --git a/src/asahi/vulkan/hk_query_oq.c b/src/asahi/vulkan/hk_query_oq.c index 73e03537384b..cd8497d883bf 100644 --- a/src/asahi/vulkan/hk_query_oq.c +++ b/src/asahi/vulkan/hk_query_oq.c @@ -287,7 +287,7 @@ hk_oq_render_stamps_supported(enum agx_chip chip) * end-of-render maintenance, and the host then writes its four stage * timestamps into the requested slots before signalling the fence * (g17/queue/render/retirement.rs, g17/completion.rs). */ - return chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip); + return agx_chip_g17p_or_m5(chip); } void diff --git a/src/asahi/vulkan/hk_query_pool.c b/src/asahi/vulkan/hk_query_pool.c index 510378d1aff0..dc493e8a91d0 100644 --- a/src/asahi/vulkan/hk_query_pool.c +++ b/src/asahi/vulkan/hk_query_pool.c @@ -117,8 +117,7 @@ hk_query_command_cs(struct hk_cmd_buffer *cmd) struct hk_sync_dep dep[HK_SYNC_NUM_SQ]; hk_sync_src_dep(cmd, HK_SYNC_ALL, cmd->current_cs.cs, dep); struct hk_cs *cs = hk_sync_get_cs_after(cmd, dep); - if (cs && (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip))) + if (cs && agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip)) cs->g17p_timestamp_query = true; return cs; } diff --git a/src/asahi/vulkan/hk_queue.c b/src/asahi/vulkan/hk_queue.c index 83e7ad0c496c..ced12b6de8c7 100644 --- a/src/asahi/vulkan/hk_queue.c +++ b/src/asahi/vulkan/hk_queue.c @@ -273,7 +273,7 @@ asahi_fill_vdm_command(struct hk_device *dev, struct hk_cs *cs, memcpy(&c->zls_ctrl, &cs->cr.zls_control, sizeof(cs->cr.zls_control)); const bool g18g = dev->dev.chip == AGX_CHIP_G18G; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || + if (agx_chip_native_or_m5(dev->dev.chip) || g18g) { c->isp_zls_pixels = agx_chip_g17_m5(dev->dev.chip) || g18g ? hk_drm_m5_zls_pixels( @@ -309,7 +309,7 @@ asahi_fill_vdm_command(struct hk_device *dev, struct hk_cs *cs, * render pass whose known primitive count is at most four, and never for * a continued pass or one with uncounted (indirect, mesh) work. This * stream's bound counts every draw of the whole pass, so it proves that. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && (dev->dev.params.features & DRM_ASAHI_FEATURE_FEW_PRIMITIVES) && cs->g17p_pass_begins && cs->g17p_pass_ends && cs->g17p_primitive_bound <= 4) { @@ -462,7 +462,7 @@ asahi_append_compute_attachments(struct hk_device *dev, /* Attachment spans are hints for the native AGX3 firmware interface. * AGX2 has never sent them, so G13 and G14 keep that submission. G18G * (M6) sends them as well. */ - if (!agx_native_graphics(&dev->dev) && dev->dev.chip != AGX_CHIP_G18G) + if (!agx_chip_native_or_g18g(dev->dev.chip)) return; const struct hk_drm_attachment_set *set = &cs->compute_attachments; @@ -486,7 +486,7 @@ asahi_append_fragment_attachments(struct hk_device *dev, const struct hk_cs *cs) { /* See asahi_append_compute_attachments(). */ - if (!agx_native_graphics(&dev->dev) && dev->dev.chip != AGX_CHIP_G18G) + if (!agx_chip_native_or_g18g(dev->dev.chip)) return; const struct hk_drm_attachment_set *set = &cs->fragment_attachments; @@ -1376,7 +1376,7 @@ hk_queue_restart_sync(struct hk_queue *queue) static bool hk_queue_admits_at_entry(const struct hk_device *dev) { - return agx_chip_g17_m5(dev->dev.chip) || dev->dev.chip == AGX_CHIP_G17P; + return agx_chip_g17p_or_m5(dev->dev.chip); } /* Admission must precede the common runtime's semaphore payload moves and @@ -1611,8 +1611,7 @@ queue_submit_recordings(struct hk_device *dev, struct hk_queue *queue, if (result != VK_SUCCESS) return result; - flush_sstt = (dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + flush_sstt = agx_chip_g17p_or_m5(dev->dev.chip) && hk_sparse_submission_updates_sstt(submit); } @@ -2264,8 +2263,7 @@ queue_submit_recordings(struct hk_device *dev, struct hk_queue *queue, hk_frame_anatomy_render(anatomy, dev, cs, &cmd.legacy, i, nr_vdm + nr_cdm, payload.size); header.size = hk_drm_render_command_size( - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G, + agx_chip_agx3_path(dev->dev.chip), queue->sync.exact_prior); if (queue->sync.exact_prior) { cmd.prior_vdm = command_prior[HK_SYNC_VDM]; @@ -2488,7 +2486,7 @@ hk_pack_runs_enabled(const struct hk_device *dev) static uint32_t hk_pack_attachment_limit(const struct hk_device *dev) { - if ((!agx_native_graphics(&dev->dev) && dev->dev.chip != AGX_CHIP_G18G) || + if (!agx_chip_native_or_g18g(dev->dev.chip) || !dev->dev.params.max_attachments) return UINT32_MAX; return dev->dev.params.max_attachments; @@ -3073,8 +3071,7 @@ hk_queue_create(struct hk_device *dev, queue->drm.timeline_value = initial_value; queue->drm.signalled_value = initial_value; - if ((dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && dev->vk.enabled_features.sparseBinding && !kick) { queue->g17p_sstt_flush_bo = agx_bo_create(&dev->dev, AIL_PAGESIZE, 0, 0, "SSTT flush stream"); diff --git a/src/asahi/vulkan/hk_ray_tracing_pipeline.c b/src/asahi/vulkan/hk_ray_tracing_pipeline.c index 286ab79a378c..3bf869168a0e 100644 --- a/src/asahi/vulkan/hk_ray_tracing_pipeline.c +++ b/src/asahi/vulkan/hk_ray_tracing_pipeline.c @@ -3975,7 +3975,7 @@ enum hk_rt_binary_executable { static bool hk_rt_binaries_native(const struct hk_device *dev) { - return dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip); + return agx_chip_g17p_or_m5(dev->dev.chip); } static void diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index 87adc7e55d03..0d75a9ea3546 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -515,8 +515,7 @@ hk_preprocess_nir_internal(struct vk_physical_device *vk_pdev, nir_shader *nir) * move, and nir_opt_large_constants only ever looks at function_temp * (nir_opt_large_constants.c:545-561). */ - if (agx_native_graphics(&((struct hk_physical_device *)vk_pdev)->dev) || - agx_chip_g17_m5(((struct hk_physical_device *)vk_pdev)->dev.chip)) { + if (agx_chip_native_or_m5(((struct hk_physical_device *)vk_pdev)->dev.chip)) { if (nir->info.stage == MESA_SHADER_COMPUTE) { NIR_PASS(_, nir, nir_opt_large_constants, NULL, 32); } else if ((nir->info.stage == MESA_SHADER_VERTEX || @@ -558,7 +557,7 @@ hk_preprocess_nir(struct vk_physical_device *vk_pdev, nir_shader *nir, * invocations to lanes as compute does, so they take the same derivatives * (meshAndTaskShaderDerivatives). */ const bool g17p_compute_derivatives = - (((chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && + ((agx_chip_g17p_or_m5(chip) && nir->info.stage == MESA_SHADER_COMPUTE) || (chip == AGX_CHIP_G17P && (nir->info.stage == MESA_SHADER_TASK || nir->info.stage == MESA_SHADER_MESH))) && @@ -658,7 +657,7 @@ hk_populate_fs_key(struct hk_fs_key *key, key->m5_position_samples = state->ms->rasterization_samples; /* M5 has no read-only early reject to rule out. */ - if ((agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip)) && + if (agx_chip_native_or_m5(chip) && state->ms != NULL && !BITSET_TEST(state->dynamic, MESA_VK_DYNAMIC_MS_ALPHA_TO_COVERAGE_ENABLE) && @@ -706,7 +705,7 @@ hk_populate_fs_key(struct hk_fs_key *key, /* A fragment library without output-interface state may acquire color * attachments later. Alpha-to-coverage also consumes color even without * an attachment, so require it to be statically disabled. */ - if ((chip == AGX_CHIP_G17P || agx_chip_g17_m5(chip)) && + if (agx_chip_g17p_or_m5(chip) && state->rp && (state->cal || BITSET_TEST(state->dynamic, MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP)) && @@ -1022,7 +1021,7 @@ hk_hash_graphics_state(struct vk_physical_device *device, * (hk_compile_shader_impl): a cached shader was compiled the same way. */ struct hk_physical_device *pdev = container_of(device, struct hk_physical_device, vk); - if (agx_native_graphics(&pdev->dev) || agx_chip_g17_m5(pdev->dev.chip)) { + if (agx_chip_native_or_m5(pdev->dev.chip)) { const uint32_t border = p_atomic_read(&pdev->border_emulation); _mesa_blake3_update(&blake3_ctx, &border, sizeof(border)); } @@ -3137,7 +3136,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, dev->dev.chip == AGX_CHIP_G17P && rs->images != VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_DISABLED_EXT; const bool lower_agx3_robust_fetches = - (dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_g17p_or_m5(dev->dev.chip) && rs->images != VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_DISABLED_EXT; const bool native_robust_images = agx_chip_explicit_robust_image_bounds(dev->dev.chip) && @@ -3192,7 +3191,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, * an encoder with no offset field at all. */ /* M5 keeps a depth comparison's bias in the sampler descriptor, as the * M5 path always has; only a Gen4 sampler moves it into the shader. */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) NIR_PASS(_, nir, agx_nir_lower_g17p_texture_early, support_lod_bias, agx_chip_sampler_has_lod_bias(dev->dev.chip) || agx_chip_g17_m5(dev->dev.chip)); @@ -3248,8 +3247,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, * generations keep their exact existing lowering sequence. A uniform buffer * does not change during a draw or dispatch, so its loads may also be * marked reorderable before CSE and vectorization. */ - const bool agx3_ssbo_vec = - dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip); + const bool agx3_ssbo_vec = agx_chip_g17p_or_m5(dev->dev.chip); if (!agx3_ssbo_vec) { NIR_PASS(_, nir, nir_lower_explicit_io, nir_var_mem_ssbo, hk_buffer_addr_format(rs->storage_buffers, @@ -3409,7 +3407,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, if (nir->info.stage == MESA_SHADER_FRAGMENT) { lower_indirect_modes |= nir_var_shader_out; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) lower_indirect_modes |= nir_var_shader_in; } else if (nir->info.stage == MESA_SHADER_VERTEX) { lower_indirect_modes |= nir_var_shader_in | nir_var_shader_out; @@ -3425,7 +3423,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, * shader input here, after the generic system-value lowering but before IO * lowering, so the regular varying linker builds the coefficient binding. */ if (nir->info.stage == MESA_SHADER_FRAGMENT && - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip))) { + agx_chip_native_or_m5(dev->dev.chip)) { const nir_lower_sysvals_to_varyings_options sysvals_to_varyings = { .layer_id = true, }; @@ -3473,7 +3471,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, hk_device_physical(dev)); } - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { /* hk_nir_lower_robust_image_access() leaves formatless loads to this * pass. */ NIR_PASS(_, nir, agx_nir_lower_texture_with_buffer_metadata, @@ -3510,7 +3508,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, * child-grid words, and the G17P task kernel after its payload lowering. */ if (nir->info.stage != MESA_SHADER_MESH && !(nir->info.stage == MESA_SHADER_TASK && - (agx_chip_g17_m5(dev->dev.chip) || dev->dev.chip == AGX_CHIP_G17P))) { + agx_chip_g17p_or_m5(dev->dev.chip))) { if (agx_native_graphics(&dev->dev)) agx_preprocess_nir_native(nir, dev->dev.chip); else if (dev->dev.chip == AGX_CHIP_G18G) @@ -4774,7 +4772,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, const bool writes_external_memory = hk_shader_writes_external_memory(nir); const bool reads_images = hk_shader_reads_images(nir); /* Facts hk_g17p_note_first_draw() needs, before lowering obscures them. */ - if ((dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && sw_stage == MESA_SHADER_FRAGMENT) shader->info.fs.may_kill = hk_fs_may_kill(nir); unsigned nr_vbos = 0; @@ -4856,8 +4854,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * the vertex program (hk_g17p_graphics_uniform_ranges()). */ if (agx_nir_lower_g17p_indexed_samplers(nir, g17p)) shader->info.agx3_indexed_sampler_valid = true; - } else if ((agx_native_graphics(&dev->dev) || - dev->dev.chip == AGX_CHIP_G18G) && + } else if (agx_chip_native_or_g18g(dev->dev.chip) && nir->info.stage == MESA_SHADER_FRAGMENT) { /* The combined-sampler lowering can refuse after changing the shader, * so it works on a copy -- made only for a shader it may apply to. */ @@ -5128,8 +5125,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * unconditional testing coverage update of the native form instead of * a uniform branch between a testing and a killing one. */ const bool fold_tests = - (agx_chip_native_agx3(dev->dev.chip) || - agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && key && (key->fs.static_tests || a2c_in_main) && !shader->info.fs.epilog_key.write_z && !shader->info.fs.epilog_key.write_s; @@ -5143,7 +5139,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, NIR_PASS(_, nir, agx_nir_apply_api_mask_to_force_early, dev->dev.chip); if (nir->info.fs.uses_sample_shading && - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip))) { + agx_chip_native_or_m5(dev->dev.chip)) { /* A split shader exports each sample through fixed registers. M5 * fragments that exceed that file retain one sample's NIR until * the epilog can be inlined, then unroll the complete body. */ @@ -5235,7 +5231,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * refuses it. M5 keys the count as m5_position_samples. */ const unsigned native_samples = hk_native_fs_samples(dev->dev.chip, &key->fs); - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && native_samples) NIR_PASS(_, nir, agx_nir_specialize_sample_count, native_samples); @@ -5245,7 +5241,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * SR28 is the compute grid-Z register and does not hold a fragment * layer on this generation. */ NIR_PASS(_, nir, agx_nir_lower_interpolation, - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)); + agx_chip_native_or_m5(dev->dev.chip)); if (agx_native_graphics(&dev->dev)) { NIR_PASS(_, nir, nir_shader_intrinsics_pass, hk_g17p_lower_is_first_fan, @@ -5307,11 +5303,10 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, nir_metadata_control_flow, NULL); } if (sw_stage == MESA_SHADER_VERTEX && - (dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip))) + agx_chip_g17p_or_m5(dev->dev.chip)) NIR_PASS(_, nir, agx_nir_preserve_position_order); hk_lower_hw_vs(dev, nir, shader, kill_psiz, - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip), + agx_chip_native_or_m5(dev->dev.chip), default_layer, hk_clip_m1_1(dev, features), agx_native_graphics(&dev->dev) ? hk_root_descriptor_offset(draw.no_attachments) @@ -5371,8 +5366,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * without it a shader that reads the root but binds no descriptor set -- * push constants -- got no root range and read its push constants from * address 0 + offset, i.e. as zero. */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) { + if (agx_chip_agx3_path(dev->dev.chip)) { shader->info.agx3_uses_root = hk_nir_uses_root(nir); shader->info.agx3_root_reads = hk_nir_root_reads(nir); } @@ -5394,7 +5388,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, NIR_PASS(_, nir, nir_shader_intrinsics_pass, lower_uniforms, nir_metadata_control_flow, &root); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { NIR_PASS(_, nir, nir_shader_intrinsics_pass, hk_g17p_lower_storage_records, nir_metadata_control_flow, NULL); @@ -5609,7 +5603,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, bool compiled = vs_cprog && hk_g17p_compile_vs_cprog(dev, &nir, &backend_key, shader); if (!compiled && - (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + agx_chip_native_or_m5(dev->dev.chip) && nir->info.stage == MESA_SHADER_FRAGMENT && !backend_key.no_preamble) compiled = hk_g17p_compile_fs_cprog(&nir, &backend_key, shader); /* An M5 compute constant program can need a form the AGX3 packer does not @@ -5701,8 +5695,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * geometry only changes how its input vertices were produced. Build the * same byte-grounded VertexProgramVariant payload from the final UVS * layout, while leaving compute-only GS variants untouched. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip) || - dev->dev.chip == AGX_CHIP_G18G) && + if (agx_chip_agx3_path(dev->dev.chip) && hw && shader->b.info.stage == MESA_SHADER_VERTEX) { struct hk_agx3_g17p_vertex_compile_info compiler_info; hk_g17p_vertex_compile_info_init(shader, vs_cprog, &compiler_info); @@ -6985,8 +6978,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf * never qualifies then. */ const bool vs_covers_clip_square = vs_covers >= 0 ? vs_covers > 0 - : (dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + : agx_chip_g17p_or_m5(dev->dev.chip) && info->stage == MESA_SHADER_VERTEX && !info->nir->info.io_lowered && hk_vs_covers_clip_square(info->nir); @@ -7069,7 +7061,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf void *border_nir = NULL; size_t border_nir_size = 0; bool border_emulating = false; - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { struct hk_physical_device *pdev = hk_device_physical(dev); struct util_dynarray ifs; util_dynarray_init(&ifs, NULL); @@ -7168,8 +7160,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf (nir->info.outputs_written & (BITFIELD64_BIT(FRAG_RESULT_DEPTH) | BITFIELD64_BIT(FRAG_RESULT_STENCIL)))); - sample_variants = (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) && + sample_variants = agx_chip_native_or_m5(dev->dev.chip) && hk_native_fs_samples(dev->dev.chip, &key_tmp.fs) == 0 && (nir->info.fs.uses_sample_shading || key_tmp.fs.force_sample_shading || coverage_updates || agx_nir_needs_sample_count(nir)); @@ -7240,7 +7231,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf * Canonicalization is exact only at one sample; keep the draw-time * refusal for unsupported fixed-count export footprints. */ - if ((agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_native_or_m5(dev->dev.chip) && nir->info.fs.uses_sample_shading && !sample_variants && !hk_native_sample_shading_supported(nir, &key->fs, dev->dev.chip)) { @@ -7300,7 +7291,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf NIR_PASS(_, nir, agx_nir_m5_canonicalize_empty_mesh); else NIR_PASS(_, nir, hk_g17p_mesh_default_counts); - if ((dev->dev.chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->dev.chip)) && + if (agx_chip_g17p_or_m5(dev->dev.chip) && nir->info.mesh.primitive_type == MESA_PRIM_POINTS && !(nir->info.outputs_written & VARYING_BIT_PSIZ)) NIR_PASS(_, nir, nir_shader_intrinsics_pass, @@ -7702,7 +7693,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf NULL); } hk_lower_hw_vs(dev, rast, shader, false, - agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip), + agx_chip_native_or_m5(dev->dev.chip), true, hk_clip_m1_1(dev, features), agx_native_graphics(&dev->dev) ? hk_root_descriptor_offset(draw.no_attachments) @@ -7874,8 +7865,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf : AGX_ROBUSTNESS_DISABLED, }; - if (agx_native_graphics(&dev->dev) || - agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) agx_nir_lower_vbo_raw(clone, attribs, agx_rs, !key->vs.static_strides); else @@ -8290,8 +8280,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, } } - vs_covers[i] = (dev->dev.chip == AGX_CHIP_G17P || - agx_chip_g17_m5(dev->dev.chip)) && + vs_covers[i] = agx_chip_g17p_or_m5(dev->dev.chip) && nir->info.stage == MESA_SHADER_VERTEX && hk_vs_covers_clip_square(nir); if (!hk_mesh_task_grid(dev, nir, info->flags)) { @@ -8320,7 +8309,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, hk_fs_mesh_builtin_per_primitive, nir_metadata_control_flow, NULL); - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { enum hk_nir_widen_16bit_varyings_mode mode = 0; if (nir->info.stage == MESA_SHADER_FRAGMENT) { @@ -8355,7 +8344,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, nir_io_add_intrinsic_xfb_info(nir); } - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) + if (agx_chip_native_or_m5(dev->dev.chip)) NIR_PASS(_, nir, nir_shader_intrinsics_pass, hk_widen_integer_io, nir_metadata_control_flow, NULL); @@ -8504,7 +8493,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, * now rather than at the first draw on the recording thread: for the state * a complete pipeline fixes, or for the most common state when compiling * shader objects. */ - if (agx_native_graphics(&dev->dev) || agx_chip_g17_m5(dev->dev.chip)) { + if (agx_chip_native_or_m5(dev->dev.chip)) { struct hk_api_shader *api[MESA_SHADER_MESH + 1] = {NULL}; for (uint32_t i = 0; i < shader_count; i++) { if (infos[i].stage <= MESA_SHADER_MESH) @@ -8763,8 +8752,7 @@ hk_deserialize_api_shader_impl(struct vk_device *vk_dev, (agx_chip_g17_m5(dev->dev.chip) ? !m5_sample_variants : !agx_native_graphics(&dev->dev)))) || (has_mono && (stage != MESA_SHADER_FRAGMENT || - (!agx_native_graphics(&dev->dev) && - !agx_chip_g17_m5(dev->dev.chip))))) + !agx_chip_native_or_m5(dev->dev.chip)))) return vk_error(dev, VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT); /* Compiled with a custom-border emulation that this GPU, with no sampler diff --git a/src/asahi/vulkan/hk_sync.c b/src/asahi/vulkan/hk_sync.c index d9e93f0c28be..ea9d18a4fdeb 100644 --- a/src/asahi/vulkan/hk_sync.c +++ b/src/asahi/vulkan/hk_sync.c @@ -555,7 +555,7 @@ hk_sync_barrier(struct hk_cmd_buffer *cmd, uint8_t src_kinds, const uint8_t render_kinds = HK_SYNC_GFX | HK_SYNC_XFER; const enum agx_chip chip = hk_cmd_buffer_device(cmd)->dev.chip; if ((src_kinds & render_kinds) && (dst_kinds & HK_SYNC_GFX) && - (agx_chip_g17_m5(chip) || chip == AGX_CHIP_G17P)) { + agx_chip_g17p_or_m5(chip)) { struct hk_sync_dep vtx = dep[HK_SYNC_VDM]; vtx.cut = memory_cut(vtx.cut); if (vtx.prior & render_kinds) @@ -987,8 +987,7 @@ hk_sync_check_cs(struct hk_cmd_buffer *cmd) cs->sync.kind |= HK_SYNC_GFX_MEM; note_last(cmd, cs); - if ((agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip)) && + if (agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip) && cmd->sync.pending_start_ts.handle && !cs->timestamp.start.handle && !cs->timestamp.end.handle) { cs->timestamp.start = cmd->sync.pending_start_ts; @@ -1052,8 +1051,7 @@ hk_sync_end_cs_if_timestamped(struct hk_cmd_buffer *cmd) return; const bool g17p_start = - (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip)) && + agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip) && cs->timestamp.start.handle; if (cs->timestamp.end.handle || g17p_start) { stamp_carrier_launch(cmd); @@ -1381,8 +1379,7 @@ hk_sync_write_timestamp(struct hk_cmd_buffer *cmd, VkPipelineStageFlags2 stage, /* A query reset or earlier dispatch may have left a reusable stream. * Consume the start stamp before recording work into it too, rather * than resolving it as an end stamp at the next timestamp write. */ - if (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || - agx_chip_g17_m5(hk_cmd_buffer_device(cmd)->dev.chip)) + if (agx_chip_native_or_m5(hk_cmd_buffer_device(cmd)->dev.chip)) st->cs_check_pending = true; return; } From b51d63cde2305793bad8f851d67e9c6efdfc408b Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:35:25 -0300 Subject: [PATCH 09/13] asahi: use the chip-set predicates 46 comparison chains in the Gallium driver become the predicate with the same answer for all 19 chips and AGX_CHIP_UNKNOWN: agx_chip_hal300_path() for "M5 or G18G", agx_chip_agx3_path(), agx_chip_native_or_m5() and agx_chip_native_or_g18g(). Each chain was compiled against agx_chip.h and evaluated for every chip before it was rewritten. Two more in agx_batch.c were written "G17G or G18G" and become agx_chip_m5_paths(), by hand. One splits a compute prepass into a submission per dispatch, which is the M5 kernel contract that G18G's bring-up path follows. The other logs a batch that lists a BO another active batch writes, a diagnostic of the Gallium M5 paths. Neither is about which record layouts captures witness, so neither is agx_chip_hal300_records(), which has the same chips. Every site keeps its set: the seven "native or G18G" sites still leave M5 out. Single-chip comparisons are unchanged. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216, and the Gallium driver builds. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/gallium/drivers/asahi/agx_batch.c | 5 +- src/gallium/drivers/asahi/agx_disk_cache.c | 3 +- .../drivers/asahi/agx_native_descriptor.c | 6 +- src/gallium/drivers/asahi/agx_pipe.c | 4 +- src/gallium/drivers/asahi/agx_state.c | 80 +++++++++---------- src/gallium/drivers/asahi/agx_uniforms.c | 5 +- 6 files changed, 46 insertions(+), 57 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_batch.c b/src/gallium/drivers/asahi/agx_batch.c index ac501bed16a0..4ccf557dca79 100644 --- a/src/gallium/drivers/asahi/agx_batch.c +++ b/src/gallium/drivers/asahi/agx_batch.c @@ -1858,8 +1858,7 @@ agx_batch_submit(struct agx_context *ctx, struct agx_batch *batch, * submission. */ const bool m5_compute_commands = agx_m5_render_resources(dev) && compute; const bool m5_split_prepass = - (dev->chip == AGX_CHIP_G17G || dev->chip == AGX_CHIP_G18G) && compute && - !m5_compute_commands; + agx_chip_m5_paths(dev->chip) && compute && !m5_compute_commands; const unsigned m5_split_count = !m5_split_prepass ? 0 : render ? cdm_dispatch_count @@ -2321,7 +2320,7 @@ agx_batch_submit(struct agx_context *ctx, struct agx_batch *batch, continue; /* But any BOs written by active batches are ours */ - if (unlikely(writer != batch) && (dev->chip == AGX_CHIP_G18G || dev->chip == AGX_CHIP_G17G)) { + if (unlikely(writer != batch) && agx_chip_m5_paths(dev->chip)) { mesa_loge("asahi: batch %u lists BO %u (%s, %zu bytes @ 0x%" PRIx64 ") whose active writer is batch %u", agx_batch_idx(batch), bo->handle, diff --git a/src/gallium/drivers/asahi/agx_disk_cache.c b/src/gallium/drivers/asahi/agx_disk_cache.c index 09a34318188e..9199b81701ce 100644 --- a/src/gallium/drivers/asahi/agx_disk_cache.c +++ b/src/gallium/drivers/asahi/agx_disk_cache.c @@ -124,8 +124,7 @@ read_shader(struct agx_screen *screen, struct blob_reader *blob, * work and the identical cached dispatch fail descriptor validation. */ binary->bo = agx_bo_create(&screen->dev, size, 0, AGX_BO_EXEC | AGX_BO_LOW_VA, "Executable"); - if (agx_native_graphics(&screen->dev) || - agx_chip_g17_m5(screen->dev.chip)) { + if (agx_chip_native_or_m5(screen->dev.chip)) { /* Native compute Ioto programs need the cached CPU shader bytes. */ binary->b.binary = malloc(size); blob_copy_bytes(blob, binary->b.binary, size); diff --git a/src/gallium/drivers/asahi/agx_native_descriptor.c b/src/gallium/drivers/asahi/agx_native_descriptor.c index 9a85d761dbe3..dda70746c44a 100644 --- a/src/gallium/drivers/asahi/agx_native_descriptor.c +++ b/src/gallium/drivers/asahi/agx_native_descriptor.c @@ -121,7 +121,7 @@ agx_gallium_pack_g17p_txf_sampler( memset(out, 0, sizeof(*out)); - if (agx_chip_g17_m5(chip) || chip == AGX_CHIP_G18G) { + if (agx_chip_hal300_path(chip)) { /* The same texel-fetch state in G17G's Gen5 record, as * hk_pack_native_txf_sampler() and the G17G tile reload use it: the * compare-mode selector is set even without a comparison. */ @@ -160,7 +160,7 @@ bool agx_gallium_g17p_sampler_handle(enum agx_chip chip, unsigned api_sampler, uint16_t *native_handle) { - if ((!agx_chip_native_agx3(chip) && chip != AGX_CHIP_G18G && !agx_chip_g17_m5(chip)) || + if (!agx_chip_agx3_path(chip) || api_sampler >= AGX_GALLIUM_G17P_API_SAMPLERS || !native_handle) return false; @@ -173,7 +173,7 @@ agx_gallium_g17p_custom_border_handle(enum agx_chip chip, unsigned api_sampler, uint16_t *native_handle) { - if ((!agx_chip_native_agx3(chip) && chip != AGX_CHIP_G18G && !agx_chip_g17_m5(chip)) || + if (!agx_chip_agx3_path(chip) || api_sampler >= AGX_GALLIUM_G17P_API_SAMPLERS || !native_handle) return false; diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 5bb9dcbd5347..74a4b4ea6b55 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -1172,7 +1172,7 @@ agx_transfer_map(struct pipe_context *pctx, struct pipe_resource *resource, agx_prepare_for_map(ctx, rsrc, level, usage, box, staging_blit); struct agx_device *dev = agx_device(pctx->screen); - const bool trace_read = (dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip)) && + const bool trace_read = agx_chip_hal300_path(dev->chip) && (dev->debug & AGX_DBG_FAULTTRACE) && (usage & PIPE_MAP_READ); if (trace_read) { @@ -1736,7 +1736,7 @@ agx_cmdbuf(struct agx_device *dev, struct drm_asahi_cmd_render *c, * zero is only a real clear value when depth or stencil storage exists. * Honeykrisp submits M5 renders on the G17 runtime the same way * (hk_drm_g17p_depth_clear). */ - if ((agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || + if ((agx_chip_native_or_g18g(dev->chip) || agx_m5_render_resources(dev)) && !zres && !sres) c->isp_bgobjdepth = fui(1.0f); diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 0bebcaf7ca5f..ba1b782adae2 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -152,7 +152,7 @@ static bool agx_gallium_ppp_record(enum agx_chip chip, uint64_t address, uint32_t words, struct agx_vdm_ppp_state_core *out) { - if ((chip == AGX_CHIP_G18G || agx_chip_g17_m5(chip)) && !agx_m5_vdm_compact(address, &address)) + if (agx_chip_hal300_path(chip) && !agx_m5_vdm_compact(address, &address)) return false; return agx_vdm_ppp_state_core_pack(chip, address, words, out); } @@ -165,7 +165,7 @@ agx_gallium_ppp_fini(struct agx_batch *batch, uint8_t **out, return false; struct agx_device *dev = agx_device(batch->ctx->base.screen); - if ((dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip))) { + if (agx_chip_hal300_path(dev->chip)) { struct agx_ppp_update compact = *ppp; if (!agx_m5_vdm_compact(ppp->gpu_base, &compact.gpu_base)) return false; @@ -1604,8 +1604,7 @@ agx_set_framebuffer_state(struct pipe_context *pctx, * target, losing that source. Preserve the samples and let the frontend's * normal blit perform the resolve, as for explicit framebuffer blits. */ - if (agx_chip_g17_m5(agx_device(pctx->screen)->chip) || - agx_device(pctx->screen)->chip == AGX_CHIP_G18G) + if (agx_chip_hal300_path(agx_device(pctx->screen)->chip)) pipe_resource_reference(&ctx->framebuffer.resolve, NULL); for (unsigned i = 0; i < state->nr_cbufs; ++i) { @@ -1964,7 +1963,7 @@ agx_g17p_direct_resolve_surface(struct agx_batch *batch, target->width0 != fb->width || target->height0 != fb->height || source->texture->width0 != fb->width || source->texture->height0 != fb->height || - (dev->chip != AGX_CHIP_G18G && !agx_chip_g17_m5(dev->chip) && + (!agx_chip_hal300_path(dev->chip) && !agx_g17p_rt0_tile_layout_supported(&batch->tilebuffer_layout))) return false; @@ -2683,7 +2682,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, * uniforms and proven compute/vertex promotion, but materialize fragment * literals through the native immediate path. */ .promote_constants = - !((agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip)) && + !(agx_chip_native_or_m5(dev->chip) && stage == MESA_SHADER_FRAGMENT), .no_stop = !terminal, .secondary = secondary, @@ -2698,8 +2697,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, * could never launch there. M5 likewise, now that its tessellation * and geometry stages run on the GPU too (hk refuses their * preambles on M5 as well). */ - .no_preamble = agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || - agx_chip_g17_m5(dev->chip), + .no_preamble = agx_chip_agx3_path(dev->chip), .g18_native_mixed = g18_native_mixed && dev->chip == AGX_CHIP_G18G, }; @@ -2707,7 +2705,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, /* G17P fragment Layer is a flat coefficient, as in Honeykrisp. The * compute grid-Z register is not a fragment Layer system value. */ NIR_PASS(_, nir, agx_nir_lower_interpolation, - agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G); + agx_chip_native_or_g18g(dev->chip)); } /* Coverage updates (gl_SampleMask writes, discards) are compiled for the @@ -2758,8 +2756,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, * halves 0..7. G17G publishes the same table for every stage but the * fragment one too. */ compiled->g17p_texture_resources = - (agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || - agx_chip_g17_m5(dev->chip)) && + agx_chip_agx3_path(dev->chip) && stage != MESA_SHADER_FRAGMENT && (BITSET_LAST_BIT(nir->info.textures_used) != 0 || BITSET_LAST_BIT(nir->info.images_used) != 0); @@ -2782,8 +2779,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, * other shape, which dropped most GL fragment programs there. */ NIR_PASS(_, nir, agx_nir_layout_uniforms, compiled, &key.reserved_preamble, uniform_base, - agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip) || - dev->chip == AGX_CHIP_G18G); + agx_chip_agx3_path(dev->chip)); if (agx_native_graphics(dev)) NIR_PASS(_, nir, agx_nir_lower_g17p_storage_records, texture_descriptor_size); @@ -3004,7 +3000,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, /* G17G has no proven custom border colour either; it shares G17P's * sampler table with the clamp-to-zero bank. */ const bool custom_borders = - ((agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G) && + (agx_chip_native_or_g18g(dev->chip) && ((so->type == MESA_SHADER_FRAGMENT && key_->fs.custom_borders) || ((so->type == MESA_SHADER_VERTEX || so->type == MESA_SHADER_TESS_EVAL) && @@ -3248,7 +3244,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, &rt_spill, NULL, &translucent, false, dev->chip == AGX_CHIP_G18G, dev->chip == AGX_CHIP_G18G, - agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip), + agx_chip_native_or_m5(dev->chip), dev->chip == AGX_CHIP_G18G); if (rt0_resident) NIR_PASS(_, nir, agx_nir_rebind_spilled_rts); @@ -3957,16 +3953,16 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, ? &so->info.image_address_mask : NULL, .image_pbe_mask = dev->chip == AGX_CHIP_G18G ? &so->info.image_pbe_mask : NULL, - .g17p_plain_txf_crawl = agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip), - .table_index_crawls = dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip), + .g17p_plain_txf_crawl = agx_chip_native_or_m5(dev->chip), + .table_index_crawls = agx_chip_hal300_path(dev->chip), .native_buffer_metadata = dev->chip == AGX_CHIP_G18G, .g17p_native_sampler_handles = - agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip), + agx_chip_agx3_path(dev->chip), .g18 = dev->chip == AGX_CHIP_G18G, .g17p_bindless_storage = agx_native_graphics(dev), .image_records = agx_native_graphics(dev) ? 3 : 2, .bindful_sampler_count = - agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip) + agx_chip_agx3_path(dev->chip) ? AGX_GALLIUM_G17P_IMMEDIATE_API_SAMPLERS : 16, }; @@ -4080,11 +4076,11 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, else NIR_PASS(_, nir, agx_nir_lower_texture_for_generation, descriptor_generation | - ((dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip)) ? AGX_NIR_TEXTURE_GENERATION_G18G + (agx_chip_hal300_path(dev->chip) ? AGX_NIR_TEXTURE_GENERATION_G18G : 0)); /* G18 indexed fetches also consume the native texture-table index, not * the base-plus-byte-offset handle retained for descriptor crawls. */ - if (agx_native_graphics(dev) || (dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip))) + if (agx_chip_agx3_path(dev->chip)) NIR_PASS(_, nir, agx_nir_rebind_g17p_texture_crawls); if (agx_chip_g17_m5(dev->chip)) NIR_PASS(_, nir, agx_nir_rebind_g17g_image_loads); @@ -4124,7 +4120,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, NIR_PASS(_, nir, agx_nir_lower_sample_intrinsics, true); so->info.uses_sample_shading = nir->info.fs.uses_sample_shading; so->info.needs_sample_count = - (agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G) && + agx_chip_native_or_g18g(dev->chip) && agx_nir_needs_sample_count(nir); } @@ -4668,8 +4664,7 @@ asahi_fast_link(struct agx_context *ctx, struct agx_uncompiled_shader *so, * G17P prolog does, and converts them explicitly. */ prolog = agx_build_meta_shader_internal( ctx, - agx_native_graphics(agx_device(ctx->base.screen)) || - agx_chip_g17_m5(agx_device(ctx->base.screen)->chip) + agx_chip_native_or_m5(agx_device(ctx->base.screen)->chip) ? agx_nir_vs_prolog_raw : agx_nir_vs_prolog, &key->prolog.vs, sizeof(key->prolog.vs), true, @@ -4838,7 +4833,7 @@ agx_update_gs_copy_link(struct agx_context *ctx, struct agx_batch *batch) ctx->linked.gs_copy = NULL; if (!ctx->gs || !ctx->gs->gs_copy || - (!agx_native_graphics(dev) && dev->chip != AGX_CHIP_G18G)) + !agx_chip_native_or_g18g(dev->chip)) return; struct agx_compiled_shader *copy = ctx->gs->gs_copy; @@ -5067,7 +5062,7 @@ agx_update_fs(struct agx_batch *batch) * sample count on the native AGX3 parts and on G17G, as the main * fragment's. */ .prolog.fs.nr_samples = - (agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip)) + agx_chip_native_or_m5(dev->chip) ? nr_samples : 0, .epilog.fs.nr_samples = nr_samples, @@ -5183,7 +5178,7 @@ agx_update_fs(struct agx_batch *batch) * sampler pointer, and every constant-colour blend from a textured * fragment used a constant of zero (Qt Quick's default text material). */ const bool g18g = dev->chip == AGX_CHIP_G18G; - if ((agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip) || g18g) && + if ((agx_chip_native_or_m5(dev->chip) || g18g) && agx_nr_tex_descriptors(batch, ctx->fs) != 0 && !agx_g17p_fragment_blend_constant_base( g18g ? AGX_CHIP_G17P : dev->chip, ctx->fs, @@ -5510,7 +5505,7 @@ agx_build_meta_shader_internal(struct agx_context *ctx, NIR_PASS(_, b.shader, agx_nir_hoist_g17p_zs_writes); NIR_PASS(_, b.shader, agx_nir_lower_g17p_tile_samples, compile_samples); } else if (builder == build_fs_prolog && - (agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip))) { + agx_chip_native_or_m5(dev->chip)) { compile_samples = ((const struct agx_fs_prolog_key *)data)->nr_samples; } @@ -5563,8 +5558,7 @@ translate_sampler_state_count(struct agx_context *ctx, mesa_shader_stage stage) /* Clamp to binding table maximum, anything larger will be bindless */ return agx_translate_sampler_state_count(MIN2(sampler_count(ctx, stage), 16), - !agx_native_graphics(dev) && - dev->chip != AGX_CHIP_G18G && + !agx_chip_native_or_g18g(dev->chip) && ctx->stage[stage].custom_borders); } @@ -6014,7 +6008,7 @@ agx_upload_textures(struct agx_batch *batch, struct agx_compiled_shader *cs, struct pipe_image_view *view = &ctx->stage[stage].images[i]; agx_batch_track_image(batch, view); - if ((agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G) && + if (agx_chip_native_or_g18g(dev->chip) && view->resource->target == PIPE_BUFFER) batch->stage_uniforms[stage].image_buffer_size[i] = agx_texture_buffer_size_el(view->format, view->u.buf.size); @@ -6132,7 +6126,7 @@ agx_upload_textures(struct agx_batch *batch, struct agx_compiled_shader *cs, batch->texture_count[stage] = nr_tex_descriptors; batch->stage_uniforms[stage].texture_base = T_tex.gpu; - if (agx_native_graphics(dev) || (dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip))) { + if (agx_chip_agx3_path(dev->chip)) { for (unsigned i = 0; i < PIPE_MAX_SAMPLERS; ++i) batch->stage_uniforms[stage].texture_handle[i] = i; } @@ -6177,7 +6171,7 @@ agx_pack_g17_api_sampler(enum agx_chip chip, void *out, compare ? agx_compare_funcs[state->compare_func] : AGX_COMPARE_FUNC_LEQUAL; - if (chip == AGX_CHIP_G18G || agx_chip_g17_m5(chip)) { + if (agx_chip_hal300_path(chip)) { agx_pack(out, SAMPLER_GEN5, cfg) { cfg.minimum_lod = state->min_lod; cfg.maximum_lod = state->max_lod; @@ -10194,7 +10188,7 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) /* A persistent attachment or partial render must keep each sample. * Resolving it here would discard data needed by the next reload. */ .multisample_store = - (agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip) || + (agx_chip_native_or_m5(dev->chip) || agx_g18_msaa4_tile_layout(dev, &batch->tilebuffer_layout)) && store && batch->tilebuffer_layout.nr_samples > 1 && (partial_render || !batch->key.resolve || @@ -10880,7 +10874,7 @@ agx_batch_init_state(struct agx_batch *batch) /* None of the J873 native render or compute streams (sessions-20260925 * a, b, g1, g2) contains the barrier word 0x21000960, so its G18G * encoding has no witness. Emit none, as Apple's streams do. */ - } else if (agx_native_graphics(dev) || agx_chip_g17_m5(dev->chip)) { + } else if (agx_chip_native_or_m5(dev->chip)) { struct agx_vdm_barrier_core barrier; const bool packed = agx_vdm_barrier_core_pack( dev->chip, @@ -10898,7 +10892,7 @@ agx_batch_init_state(struct agx_batch *batch) } } - if ((dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip))) { + if (agx_chip_hal300_path(dev->chip)) { /* Same fixed-layout initial state as Honeykrisp's M5 path. These * records establish the processor's initial state even for clear-only * batches; the AGX2 selector graph cannot initialize HAL300. @@ -13052,7 +13046,7 @@ agx_encode_state(struct agx_batch *batch, uint8_t *out, if (draw_state_offset) *draw_state_offset = 0; - if ((dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip))) { + if (agx_chip_hal300_path(dev->chip)) { uint8_t *encoded = agx_chip_g17_m5(dev->chip) ? agx_encode_native_g17g_state(batch, out) : agx_encode_g17g_state(batch, out); @@ -14204,8 +14198,7 @@ agx_get_passthrough_gs(struct agx_context *ctx, * varyings drawn through transform feedback. G17G needs them like the * AGX3 chips. */ - if (agx_native_graphics(agx_device(ctx->base.screen)) || - agx_chip_g17_m5(agx_device(ctx->base.screen)->chip)) { + if (agx_chip_native_or_m5(agx_device(ctx->base.screen)->chip)) { gs->info.known_interpolation_qualifiers = prev->info.known_interpolation_qualifiers; gs->info.linear_varyings = prev->info.linear_varyings; @@ -15586,8 +15579,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, * utility before command construction. Vertex values, index bias and * the restart index remain unchanged; only the storage width changes. */ if (info->index_size == 1 && - (agx_device(pctx->screen)->chip == AGX_CHIP_G18G || - agx_chip_g17_m5(agx_device(pctx->screen)->chip)) && + agx_chip_hal300_path(agx_device(pctx->screen)->chip) && agx_vdm_index_list_direct_is_hal300_inline(agx_device(pctx->screen)->chip)) { if (indirect) { util_draw_indirect(pctx, info, drawid_offset, indirect); @@ -16117,7 +16109,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, * that state block alone; overread padding is not command storage. */ const size_t command_space = - (dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip)) + agx_chip_hal300_path(dev->chip) ? AGX_VDM_STATE_UPDATE_LENGTH + (2 + AGX_PPP_HAL300_GRAPHICS_RECORDS) * AGX_VDM_PPP_STATE_CORE_LENGTH + AGX_VDM_STATE_LENGTH + AGX_VDM_STATE_RESTART_INDEX_LENGTH + @@ -16229,7 +16221,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, dev->params.features & DRM_ASAHI_FEATURE_VDM_USC_INVALIDATE); } - assert((dev->chip != AGX_CHIP_G18G && !agx_chip_g17_m5(dev->chip)) || + assert(!agx_chip_hal300_path(dev->chip) || (size_t)(out - batch->vdm.current) <= command_space); batch->vdm.current = out; assert((batch->vdm.current + AGX_VDM_STREAM_LINK_LENGTH) <= batch->vdm.end && @@ -16560,7 +16552,7 @@ agx_launch(struct agx_batch *batch, struct agx_grid grid, /* Only G17G reaches this path: every native AGX3 part, G17P included, * took the block above. dev is the declaration that block uses. */ - if (dev->chip == AGX_CHIP_G17P || agx_chip_g17_m5(dev->chip)) { + if (agx_chip_g17p_or_m5(dev->chip)) { struct agx3_ioto_uniform_range ranges[AGX_MAX_PUSH_RANGES + 2]; size_t range_count = 0; const bool resource_pair = batch->texture_count[stage] != 0; diff --git a/src/gallium/drivers/asahi/agx_uniforms.c b/src/gallium/drivers/asahi/agx_uniforms.c index 66eeef3d9103..63aed95aa67c 100644 --- a/src/gallium/drivers/asahi/agx_uniforms.c +++ b/src/gallium/drivers/asahi/agx_uniforms.c @@ -117,8 +117,7 @@ agx_set_sampler_uniforms(struct agx_batch *batch, mesa_shader_stage stage) struct agx_stage_uniforms *unif = &batch->stage_uniforms[stage]; struct agx_device *dev = agx_device(ctx->base.screen); - const bool custom_border = agx_native_graphics(dev) || - dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip); + const bool custom_border = agx_chip_agx3_path(dev->chip); if (custom_border) { for (unsigned s = 0; s < PIPE_MAX_SAMPLERS; ++s) { unif->custom_border_sampler_handle[s] = -1; @@ -169,7 +168,7 @@ agx_set_sampler_uniforms(struct agx_batch *batch, mesa_shader_stage stage) * GLES3 texture.units.all_units). */ if (st->shader && st->shader->uses_bindless_samplers) { u_foreach_bit(s, st->valid_samplers) { - if (agx_native_graphics(dev) || dev->chip == AGX_CHIP_G18G || agx_chip_g17_m5(dev->chip)) { + if (agx_chip_agx3_path(dev->chip)) { /* The G17P graphics Ioto program publishes the per-stage HAL200 * table directly. Indirect operands therefore name the same * i+1 entries as immediate operands; the old 28+index handle From 38b283df2027d244123f6937a0afabb02702bffa Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:37:02 -0300 Subject: [PATCH 10/13] borealis: spell the native path test agx_chip_native_agx3() agx_native_graphics(dev) is agx_chip_native_agx3(dev->chip) and nothing else (agx_device.h), so the tree had two names for one predicate. Keep the one that needs only a chip, which the compiler, the record codecs and asahi_clc can also call. This is the Borealis half: 123 calls, rewritten by script from agx_native_graphics(&x) to agx_chip_native_agx3(x.chip). The lines that grew past 80 columns are re-wrapped. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/vulkan/hk_cmd_buffer.c | 20 ++++---- src/asahi/vulkan/hk_cmd_buffer.h | 4 +- src/asahi/vulkan/hk_cmd_dispatch.c | 8 +-- src/asahi/vulkan/hk_cmd_draw.c | 73 ++++++++++++++------------- src/asahi/vulkan/hk_cmd_meta.c | 31 ++++++------ src/asahi/vulkan/hk_cmd_upload.c | 13 ++--- src/asahi/vulkan/hk_descriptor_set.c | 4 +- src/asahi/vulkan/hk_device.c | 6 +-- src/asahi/vulkan/hk_image.c | 7 +-- src/asahi/vulkan/hk_image_view.c | 8 +-- src/asahi/vulkan/hk_physical_device.c | 8 +-- src/asahi/vulkan/hk_query_pool.c | 13 ++--- src/asahi/vulkan/hk_sampler.c | 10 ++-- src/asahi/vulkan/hk_shader.c | 65 ++++++++++++------------ src/asahi/vulkan/hk_sync.c | 7 +-- 15 files changed, 144 insertions(+), 133 deletions(-) diff --git a/src/asahi/vulkan/hk_cmd_buffer.c b/src/asahi/vulkan/hk_cmd_buffer.c index fd350a5d1554..9a0fdaadca1b 100644 --- a/src/asahi/vulkan/hk_cmd_buffer.c +++ b/src/asahi/vulkan/hk_cmd_buffer.c @@ -668,7 +668,7 @@ hk_pool_cs_alloc(struct hk_cmd_buffer *cmd, uint32_t size, uint32_t alignment) * roots on their own bump cursor so allocating one cannot evict a partially * used main-upload BO and move that allocator's slow path into the next * application command. Ownership remains on the ordinary main BO list. */ - struct hk_uploader *uploader = agx_native_graphics(&dev->dev) + struct hk_uploader *uploader = agx_chip_native_agx3(dev->dev.chip) ? &cmd->uploader.streams : &cmd->uploader.main; return hk_pool_alloc_from(cmd, uploader, size, alignment, HK_CMD_BO_MAIN); @@ -954,7 +954,7 @@ static void hk_cmd_buffer_publish_root_uploads(struct hk_cmd_buffer *cmd) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev) || + if (!agx_chip_native_agx3(dev->dev.chip) || list_is_empty(&cmd->uploader.root.bos)) return; @@ -1394,7 +1394,7 @@ hk_g17p_can_retain_descriptor_root(struct hk_cmd_buffer *cmd, const struct hk_descriptor_state *desc) { struct hk_graphics_state *gfx = &cmd->state.gfx; - if (!agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || + if (!agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip) || desc != &gfx->descriptors || gfx->shaders[MESA_SHADER_GEOMETRY] || gfx->shaders[MESA_SHADER_TESS_CTRL] || @@ -3808,7 +3808,7 @@ hk_upload_usc_words_internal(struct hk_cmd_buffer *cmd, struct hk_shader *s, if (agx_chip_g17_m5(dev->dev.chip)) return hk_m5_upload_graphics_program(cmd, s, linked); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { const unsigned stage = s->info.stage == MESA_SHADER_FRAGMENT ? 1 : 0; struct hk_g17p_graphics_ioto_cache_entry *cached = &cmd->state.gfx.g17p_ioto[stage]; @@ -3841,7 +3841,7 @@ hk_upload_usc_words_internal(struct hk_cmd_buffer *cmd, struct hk_shader *s, * earlier compact publication in this recording with the same inputs * was already admitted. */ const bool spills = agx_tilebuffer_spills(&agfx->render.tilebuffer); - const bool same_program = agx_native_graphics(&dev->dev) && + const bool same_program = agx_chip_native_agx3(dev->dev.chip) && cached->admit.s == s && cached->admit.linked == linked; const bool vertex_admitted = @@ -3854,7 +3854,7 @@ hk_upload_usc_words_internal(struct hk_cmd_buffer *cmd, struct hk_shader *s, cached->admit.provoking == agfx->provoking && hw_vs && cached->admit.hw_vs == hw_vs; if (!vertex_admitted && !fragment_admitted) { - if (!agx_native_graphics(&dev->dev) || + if (!agx_chip_native_agx3(dev->dev.chip) || !hk_g17p_basic_graphics_program_supported(cmd, s, linked)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); @@ -4006,7 +4006,7 @@ hk_dispatch_precomp(struct hk_cmd_buffer *cmd, struct agx_grid grid, void *data, size_t data_size) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { hk_dispatch_precomp_g17p(cmd, grid, barrier, idx, data, data_size); return; } @@ -4324,7 +4324,7 @@ hk_cs_capture_fragment_attachments(const struct hk_device *dev, * is a later meta pass that retains its own attachments. Eight multisample * targets and their resolve targets would otherwise overflow the table and * fail the submit. */ - const bool g17p = agx_native_graphics(&dev->dev); + const bool g17p = agx_chip_native_agx3(dev->dev.chip); const bool resolves_written = !g17p || render->g17p_direct_color_resolve; for (unsigned i = 0; i < render->color_att_count; ++i) { @@ -4539,7 +4539,7 @@ hk_cs_init_graphics(struct hk_cmd_buffer *cmd, struct hk_cs *cs) memcpy(map, records, sizeof(records)); map += sizeof(records); - } else if (agx_native_graphics(&dev->dev)) { + } else if (agx_chip_native_agx3(dev->dev.chip)) { /* PPPEncoderGen6's inspected G17P fixed-layout opening is one exact * W-clamp/Cull-2 payload, not the legacy AGX2 selector graph below. * Keep the payload in the compact VDM window just like every other @@ -4626,7 +4626,7 @@ hk_cs_init_graphics(struct hk_cmd_buffer *cmd, struct hk_cs *cs) /* All graphics state must be reemited in each control stream */ hk_cmd_buffer_dirty_all(cmd); - if (agx_native_graphics(&dev->dev)) + if (agx_chip_native_agx3(dev->dev.chip)) assert((cs->current - cs->start) == HK_G17P_VDM_INITIAL_SIZE); return true; diff --git a/src/asahi/vulkan/hk_cmd_buffer.h b/src/asahi/vulkan/hk_cmd_buffer.h index 3a571217412f..fb59b2fed2dc 100644 --- a/src/asahi/vulkan/hk_cmd_buffer.h +++ b/src/asahi/vulkan/hk_cmd_buffer.h @@ -2700,7 +2700,7 @@ hk_cmd_buffer_end_graphics(struct hk_cmd_buffer *cmd) if (cs) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - const bool full_usc_state = agx_native_graphics(&dev->dev); + const bool full_usc_state = agx_chip_native_agx3(dev->dev.chip); /* Scissor and depth bias arrays are staged to dynamic arrays on the * CPU. When we end the control stream, they're done growing and are * ready for upload. G17P's ISP consumes these as full bit-40-set GART @@ -3020,7 +3020,7 @@ hk_dispatch_with_local_size(struct hk_cmd_buffer *cmd, struct hk_cs *cs, hk_dispatch_m5_native(cmd, cs, s, grid, local_size); return; } - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { hk_reserve_scratch(cmd, cs, s); hk_dispatch_g17p_native(cmd, cs, s, grid, local_size); /* Software graphics stages communicate through memory: VS outputs, diff --git a/src/asahi/vulkan/hk_cmd_dispatch.c b/src/asahi/vulkan/hk_cmd_dispatch.c index 4958c5816952..711680f06c40 100644 --- a/src/asahi/vulkan/hk_cmd_dispatch.c +++ b/src/asahi/vulkan/hk_cmd_dispatch.c @@ -1211,7 +1211,7 @@ hk_g17p_prewarm_linked_compute_program_kind( struct hk_linked_shader *linked, bool internal_graphics, enum agx_ioto_g17p_compute_ldshdr_f1 kind) { - if (!agx_native_graphics(&dev->dev) || + if (!agx_chip_native_agx3(dev->dev.chip) || !hk_g17p_compute_shader_supported(dev->dev.chip, s, linked, AGX3_G17P_MAX_COMPUTE_SPILL_B)) return; @@ -1507,7 +1507,7 @@ hk_dispatch_precomp_g17p(struct hk_cmd_buffer *cmd, struct agx_grid grid, vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); return; } - if (!agx_native_graphics(&dev->dev) || !prog->bo || + if (!agx_chip_native_agx3(dev->dev.chip) || !prog->bo || !prog->info.main_size || !prog->info.nr_gprs || prog->info.nr_preamble_gprs || (prog->info.rodata.size_16 && !prog->rodata_offset) || @@ -2029,7 +2029,7 @@ hk_dispatch_g17p_native(struct hk_cmd_buffer *cmd, struct hk_cs *cs, static_assert(HK_MAX_SETS == HK_AGX3_G17P_MAX_ROOT_SETS, "G17P root range must cover every Honeykrisp set"); - if (!agx_native_graphics(&dev->dev) || cs->type != HK_CS_CDM || + if (!agx_chip_native_agx3(dev->dev.chip) || cs->type != HK_CS_CDM || !hk_g17p_compute_shader_supported(dev->dev.chip, s, linked, AGX3_G17P_MAX_COMPUTE_SPILL_B)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); @@ -3198,7 +3198,7 @@ hk_CmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer _buffer, * arguments through the shadow there. */ const bool have_sparse_helper = dev->g17p_grid_helper_sparse != NULL; const bool use_primary = - agx_native_graphics(&dev->dev) && buffer->va && + agx_chip_native_agx3(dev->dev.chip) && buffer->va && (!buffer->sparse_map || have_sparse_helper); uint64_t dispatch_addr = hk_buffer_address(buffer, offset, !use_primary); diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index 9a3fabc2448b..a9effbe659c3 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -784,7 +784,7 @@ void hk_g17p_bg_eot_dev_cache_init(struct hk_device *dev) { dev->g17p_bg_eot_dev_cache = NULL; - if (!agx_native_graphics(&dev->dev)) + if (!agx_chip_native_agx3(dev->dev.chip)) return; struct hk_g17p_bg_eot_dev_cache *dc = calloc(1, sizeof(*dc)); if (!dc) @@ -1287,9 +1287,9 @@ hk_build_g17p_bg_eot(struct hk_cmd_buffer *cmd, * diagnostic. Refuse that combination instead of storing wrong pixels. */ const bool multisample_store = - agx_native_graphics(&dev->dev) && key->multisample_store; + agx_chip_native_agx3(dev->dev.chip) && key->multisample_store; if (!iview || !target || - (agx_native_graphics(&dev->dev) && !direct_resolve && + (agx_chip_native_agx3(dev->dev.chip) && !direct_resolve && !multisample_store && target->vk.image->samples != 1) || (multisample_store && (direct_resolve || target != iview || @@ -1632,7 +1632,7 @@ hk_g17p_bg_eot_cache_get(struct hk_cmd_buffer *cmd, "G17P BG/EOT cache key storage"); struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev)) + if (!agx_chip_native_agx3(dev->dev.chip)) return NULL; struct hk_g17p_bg_eot_cache_key cache_key = { @@ -2816,7 +2816,7 @@ hk_build_bg_eot_program(struct hk_cmd_buffer *cmd, const VkRenderingInfo *info, } } - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { const unsigned variant = (store ? 2 : 0) | (partial_render ? 1 : 0); if (cache && (cache->valid_variants & BITFIELD_BIT(variant))) { render->g17p_direct_color_resolve |= @@ -3548,7 +3548,7 @@ hk_tilebuffer_layout(const struct hk_device *dev, const VkFormat *vk_formats, } return agx_build_tilebuffer_layout_with_limits_resident( formats, count, samples, layered, max_sample_size_B, - imageblock ? 32768 : 0, agx_native_graphics(&dev->dev) ? 2048 : 0, + imageblock ? 32768 : 0, agx_chip_native_agx3(dev->dev.chip) ? 2048 : 0, resident_mask); } @@ -4567,8 +4567,9 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, /* vkd3d-proton renders without attachments at the Vulkan maximum, layers * included, which cannot fit in a tiler allocation. Nothing is stored per * layer, so one hardware layer serves all of them. */ - bool no_attachments = agx_native_graphics(&dev->dev) && !render->view_mask && - !render->depth_att.iview && !render->stencil_att.iview; + bool no_attachments = agx_chip_native_agx3(dev->dev.chip) && + !render->view_mask && !render->depth_att.iview && + !render->stencil_att.iview; for (uint32_t i = 0; i < render->color_att_count; i++) no_attachments &= !render->color_att[i].iview; if (cmd->state.gfx.descriptors.root.draw.no_attachments != no_attachments) { @@ -4691,7 +4692,7 @@ hk_begin_rendering(VkCommandBuffer commandBuffer, render->g17p_rt0_layout_supported = hk_agx3_g17p_rt0_tile_layout_supported(&render->tilebuffer); - if (agx_native_graphics(&dev->dev) && + if (agx_chip_native_agx3(dev->dev.chip) && !render->g17p_rt0_layout_supported) { mesa_loge_once("G17P tilebuffer layout refused: attachments=%u " "samples=%u sample_size=%u tile_size=%u", @@ -7589,7 +7590,7 @@ hk_get_fast_linked_locked_fs(struct hk_device *dev, struct hk_shader *shader, !shader->info.fs.m5_inline_sample_shading && hk_m5_uniform_blend_key(&key->epilog); if ((uniform_blend || shader->info.fs.m5_inline_sample_shading || - (agx_native_graphics(&dev->dev) && + (agx_chip_native_agx3(dev->dev.chip) && (agx_get_fs_structure_flags() & AGX_FS_STRUCTURE_INLINE_BLEND))) && !prolog && key->nr_samples_shaded == 0 && shader->g17p_mono_nir) { struct agx_shader_part *mono = hk_g17p_inline_epilog_part( @@ -7645,7 +7646,7 @@ hk_get_fast_linked_locked_fs(struct hk_device *dev, struct hk_shader *shader, struct agx_shader_part *epilog = hk_get_prolog_epilog(dev, &key->epilog, sizeof(key->epilog), - (agx_native_graphics(&dev->dev) || + (agx_chip_native_agx3(dev->dev.chip) || (agx_chip_g17_m5(dev->dev.chip) && (key->epilog.link.sample_shading || key->epilog.native_spills))) @@ -8402,7 +8403,7 @@ hk_g17p_build_native_bind_tail(struct hk_cmd_buffer *cmd, if (prepared) prepared->valid = false; - if (!agx_native_graphics(&dev->dev) || !prepared) + if (!agx_chip_native_agx3(dev->dev.chip) || !prepared) return hk_g17p_bind_tail_refused(__LINE__); if (!hk_g17p_viewport_state_supported(dyn->vp.viewport_count, dyn->vp.scissor_count)) @@ -9869,7 +9870,7 @@ hk_flush_ppp_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, uint8_t **out) .viewport_count = 1, /* irrelevant */ }; - if (!agx_native_graphics(&dev->dev)) + if (!agx_chip_native_agx3(dev->dev.chip)) dirty.fragment_shader &= !linked_fs->b.no_op; /* Calculate the update size. If it equals the header, there is nothing to @@ -10178,8 +10179,8 @@ hk_g17p_read_only_early_reject_in(const struct hk_device *dev, /* Moving a test ahead of a discard is unobservable only when neither the * test nor the skipped fragment has a side effect. The all-live prolog * also must not inherit an API-mask or cull-distance kill. */ - return agx_native_graphics(&dev->dev) && fs->b.info.writes_sample_mask && - !fs->info.fs.static_tests && + return agx_chip_native_agx3(dev->dev.chip) && + fs->b.info.writes_sample_mask && !fs->info.fs.static_tests && !fs->b.info.early_fragment_tests && !fs->info.fs.writes_memory && !fs->info.fs.epilog_key.write_z && !fs->info.fs.epilog_key.write_s && samples == 1 && in->depth_attachment && dyn->ds.depth.test_enable && @@ -10400,7 +10401,7 @@ hk_fs_link_key_build(const struct hk_device *dev, struct hk_shader *fs, fs && (fs->b.info.early_fragment_tests && (fs->b.info.writes_sample_mask || fs->info.fs.writes_memory)); bool epilog_discards = hk_fs_epilog_discards(fs, dyn, nontrivial_force_early); - bool defer_api_sample_mask = agx_native_graphics(&dev->dev) && + bool defer_api_sample_mask = agx_chip_native_agx3(dev->dev.chip) && has_sample_mask && !nontrivial_force_early; const bool native_samples = agx_chip_native_or_m5(dev->dev.chip); @@ -10963,7 +10964,7 @@ hk_agx3_publish_vertex_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, cs->anatomy_vdm_new++; cs->anatomy_last_program = pipeline_program; } - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { if (!hk_g17p_emit_native_bind_tail(cmd, cs, &out, tail_known_match)) { mesa_loge("failed to emit native HAL200 bind tail for %s", @@ -11112,7 +11113,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, const bool early_reject_has_api_mask = (dyn->ms.sample_mask & early_reject_full_mask) != early_reject_full_mask; const bool early_reject_defer_api_mask = - agx_native_graphics(&dev->dev) && early_reject_has_api_mask && + agx_chip_native_agx3(dev->dev.chip) && early_reject_has_api_mask && !nontrivial_force_early; const bool early_reject_prolog_discards = (early_reject_has_api_mask && !early_reject_defer_api_mask) || @@ -11332,7 +11333,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, /* The provisional attachmentless layout was admitted at begin time; * enforce the hardware contract again once the sample count is known. */ - if (agx_native_graphics(&dev->dev) && + if (agx_chip_native_agx3(dev->dev.chip) && !(gfx->render.g17p_rt0_layout_supported = hk_agx3_g17p_rt0_tile_layout_supported( &gfx->render.tilebuffer))) { @@ -11385,7 +11386,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, bool linked_vs_dirty = IS_LINKED_DIRTY(VERTEX); bool linked_fs_dirty = IS_LINKED_DIRTY(FRAGMENT); const bool prepared_varyings = - agx_native_graphics(&dev->dev) && + agx_chip_native_agx3(dev->dev.chip) && hk_g17p_prepared_bind_tail_matches(cmd, &gfx->g17p_bind_tail); /* Between here and the bind-tail emission below only the root can move * one of the tail's inputs (varyings are relinked only when this is @@ -11490,7 +11491,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, * Letting those changes fall through to hk_flush_ppp_state() emits the * legacy aggregate layout into an otherwise native stream. The initial * draw hid this because all shader state was dirty on stream creation. */ - if (agx_native_graphics(&dev->dev) || + if (agx_chip_native_agx3(dev->dev.chip) || (gfx->dirty & (HK_DIRTY_PROVOKING | HK_DIRTY_VARYINGS)) || IS_DIRTY(RS_RASTERIZER_DISCARD_ENABLE) || linked_vs_dirty || vgt_dirty || gfx->descriptors.root_dirty || gfx->draw_id_ptr || gfx->draw_params || @@ -11667,7 +11668,7 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs, /* A pure cull/winding update needs new immutable fragment state, but * leaves the vertex program and its VDM state unchanged. */ - if (agx_native_graphics(&dev->dev) && !g17p_native_bind_tail_emitted && + if (agx_chip_native_agx3(dev->dev.chip) && !g17p_native_bind_tail_emitted && (IS_DIRTY(RS_CULL_MODE) || IS_DIRTY(RS_FRONT_FACE))) { if (!hk_g17p_emit_native_bind_tail(cmd, cs, &out, false)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); @@ -12147,7 +12148,7 @@ hk_flush_gfx_state(struct hk_cmd_buffer *cmd, uint32_t draw_id, * before the republication instead of failing the draw. */ const unsigned ppp_margin = AGX_PPP_VIEWPORT_PAYLOAD_MAX_VIEWPORTS + 1; const bool ppp_index_limit = - agx_native_graphics(&dev->dev) && + agx_chip_native_agx3(dev->dev.chip) && (cs->scissor.size / AGX_SCISSOR_LENGTH + ppp_margin > UINT16_MAX || cs->depth_bias.size / AGX_DEPTH_BIAS_LENGTH + ppp_margin > UINT16_MAX); @@ -12279,7 +12280,8 @@ hk_ia_update(struct hk_cmd_buffer *cmd, struct agx_draw draw, * scratch page, like a disabled one. */ if (geom || tess) { - c_prims = agx_native_graphics(&dev->dev) ? AGX_SCRATCH_PAGE_ADDRESS : 0; + c_prims = + agx_chip_native_agx3(dev->dev.chip) ? AGX_SCRATCH_PAGE_ADDRESS : 0; c_inv = c_prims; } @@ -12293,7 +12295,7 @@ hk_ia_update(struct hk_cmd_buffer *cmd, struct agx_draw draw, */ uint64_t index_buffer = agx_draw_index_buffer(draw); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { /* Disabled statistics are represented by the writable scratch page, * so all five addresses are valid. Use the native specialization * that does not need to reduce nullable 64-bit pointers. */ @@ -12497,7 +12499,7 @@ hk_g17p_emit_draw(struct hk_cmd_buffer *cmd, struct hk_cs *cs, uint8_t *out, static void hk_g17p_note_layer_zero_draw(struct hk_cmd_buffer *cmd, struct hk_cs *cs) { - if (!agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || + if (!agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip) || cmd->state.gfx.render.view_mask) { cs->g17p_layer_zero_unknown = true; return; @@ -12606,7 +12608,7 @@ hk_emit_robust_index(struct hk_cmd_buffer *cmd, struct hk_cs *cs, { struct hk_device *dev = hk_cmd_buffer_device(cmd); uint32_t draw_state_offset = 0; - if (agx_native_graphics(&dev->dev) && tail_emitted) { + if (agx_chip_native_agx3(dev->dev.chip) && tail_emitted) { struct agx_ptr draw_state = hk_pool_vdm_alloc(cmd, 8, 4); if (!draw_state.cpu || !hk_g17p_upload_draw_indices( @@ -12624,7 +12626,7 @@ hk_emit_robust_index(struct hk_cmd_buffer *cmd, struct hk_cs *cs, uint64_t target = hk_cs_alloc_for_indirect(cs, size_B); uint64_t empty_draw_jump = 0; - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { const uint64_t compact = hk_g17p_vdm_compact(cmd, target + size_B); if (!compact || compact >= (UINT64_C(1) << 40)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_OUT_OF_DEVICE_MEMORY); @@ -12801,7 +12803,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, const bool software_index_fetch = cmd->state.gfx.shaders[MESA_SHADER_GEOMETRY] || cmd->state.gfx.shaders[MESA_SHADER_TESS_EVAL]; - if (agx_native_graphics(&dev->dev) && draw_.indexed && + if (agx_chip_native_agx3(dev->dev.chip) && draw_.indexed && !software_index_fetch) { uint64_t address; uint32_t size_word; @@ -13018,7 +13020,8 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, /* The bind tail was already published before lowering determined * there were no complete primitives. Its selector word must still * be present, even though no Index List follows it. */ - if (agx_native_graphics(&dev->dev) && g17p_native_bind_tail_emitted) { + if (agx_chip_native_agx3(dev->dev.chip) && + g17p_native_bind_tail_emitted) { struct agx_ptr state = hk_pool_vdm_alloc(cmd, 8, 4); uint32_t offset; if (!state.cpu || !hk_g17p_upload_draw_indices( @@ -13040,7 +13043,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, enum agx_primitive topology = cmd->state.gfx.topology; /* Admit with the chip whose Index List words agx_vdm_draw() writes * below (G18G writes G17G's), not the raw chip. */ - if ((!agx_native_graphics(&dev->dev) || agx_is_indirect(draw.b)) && + if ((!agx_chip_native_agx3(dev->dev.chip) || agx_is_indirect(draw.b)) && !agx_vdm_draw_supported(agx_vdm_index_list_record_chip(dev->dev.chip), draw, topology)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); @@ -13071,7 +13074,7 @@ hk_draw_impl(struct hk_cmd_buffer *cmd, uint16_t draw_id, struct agx_draw draw_, if (agx_chip_native_or_m5(dev->dev.chip)) cs->restart_index_set = false; } else { - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { if (!hk_g17p_emit_draw(cmd, cs, out, draw, topology, g17p_native_bind_tail_emitted)) return; @@ -13807,7 +13810,7 @@ hk_g17p_emit_indirect_record(struct hk_cmd_buffer *cmd, uint16_t draw_id, /* Only the native bind tail consumes this (hk_agx3_publish_vertex_state), * as in hk_flush_dynamic_state_slow(). */ const bool prepared_varyings = - agx_native_graphics(&dev->dev) && + agx_chip_native_agx3(dev->dev.chip) && hk_g17p_prepared_bind_tail_matches(cmd, &gfx->g17p_bind_tail); const uint64_t prepared_varyings_root = gfx->root; @@ -13847,7 +13850,7 @@ hk_g17p_emit_indirect_record(struct hk_cmd_buffer *cmd, uint16_t draw_id, hk_upload_stat(cmd, draws, 1); if (batch) { hk_emit_robust_index(cmd, cs, draw, gfx->topology, tail_emitted, batch); - } else if (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev)) { + } else if (agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip)) { if (!hk_g17p_emit_draw(cmd, cs, cs->current, draw, gfx->topology, tail_emitted)) return; @@ -13952,7 +13955,7 @@ hk_g17p_draw_robust_multi(struct hk_cmd_buffer *cmd, uint64_t buffer, uint32_t draw_count, uint32_t stride) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev) || draw_count <= 1) + if (!agx_chip_native_agx3(dev->dev.chip) || draw_count <= 1) return false; struct hk_graphics_state *gfx = &cmd->state.gfx; diff --git a/src/asahi/vulkan/hk_cmd_meta.c b/src/asahi/vulkan/hk_cmd_meta.c index 474bb89c7a0c..3a78a79a524c 100644 --- a/src/asahi/vulkan/hk_cmd_meta.c +++ b/src/asahi/vulkan/hk_cmd_meta.c @@ -81,27 +81,28 @@ hk_device_init_meta(struct hk_device *dev) dev->meta.use_gs_for_layer = false; dev->meta.use_layer_output = true; - dev->meta.use_view_relative_3d_layer = agx_native_graphics(&dev->dev); + dev->meta.use_view_relative_3d_layer = agx_chip_native_agx3(dev->dev.chip); /* hk never uses layered rendering for meta, so a one-layer attachment * view always renders Layer 0: the specialization holds on every chip. */ dev->meta.specialize_single_layer_buffer_upload = true; /* Other native chips lower a stencil blit to eight bit-selective discard * passes. G17P exports stencil in one draw, which also resolves depth and * stencil together: 1.50 to 0.48 ms for a 2x D32S8 at 3456x2234. */ - dev->meta.use_stencil_export = !agx_native_graphics(&dev->dev) || + dev->meta.use_stencil_export = !agx_chip_native_agx3(dev->dev.chip) || dev->dev.chip == AGX_CHIP_G17P; /* A scaled image is read through an exact integer descriptor or a * filterable normalized one depending on whether the sampler filters, so * a blit source has to arrive together with its sampler for the driver to * choose. See hk_descriptor_set.c. */ - dev->meta.use_combined_blit_descriptors = agx_native_graphics(&dev->dev); + dev->meta.use_combined_blit_descriptors = + agx_chip_native_agx3(dev->dev.chip); dev->meta.use_masked_rgba8_buffer_unpack = - agx_native_graphics(&dev->dev); + agx_chip_native_agx3(dev->dev.chip); dev->meta.use_rect_list_pipeline = true; dev->meta.cmd_bind_map_buffer = hk_cmd_bind_map_buffer; dev->meta.max_bind_map_buffer_size_B = 64 * 1024; dev->meta.buffer_access.max_fill_chunk_size = - agx_native_graphics(&dev->dev) ? 16 : 0; + agx_chip_native_agx3(dev->dev.chip) ? 16 : 0; for (unsigned i = 0; i < VK_META_BUFFER_CHUNK_SIZE_COUNT; ++i) { dev->meta.buffer_access.optimal_wg_size[i] = 64; @@ -315,7 +316,7 @@ hk_g17p_meta_fill_addr(struct hk_cmd_buffer *cmd, struct hk_cs **target, uint64_t address, uint64_t size, uint32_t value) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev) || !target || !address || + if (!agx_chip_native_agx3(dev->dev.chip) || !target || !address || ((address | size) & 3)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); return; @@ -672,7 +673,7 @@ hk_g17p_meta_wait_addr(struct hk_cmd_buffer *cmd, uint64_t address, uint32_t value) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev) || !address || (address & 3)) { + if (!agx_chip_native_agx3(dev->dev.chip) || !address || (address & 3)) { vk_command_buffer_set_error(&cmd->vk, VK_ERROR_FEATURE_NOT_PRESENT); return; } @@ -2191,7 +2192,7 @@ hk_g17p_compute_blit_supported(const struct hk_device *dev, const struct hk_image *dst, const VkBlitImageInfo2 *info) { - if (!agx_native_graphics(&dev->dev) || info->regionCount == 0) + if (!agx_chip_native_agx3(dev->dev.chip) || info->regionCount == 0) return false; for (uint32_t r = 0; r < info->regionCount; ++r) { @@ -2809,7 +2810,7 @@ hk_xfer_blitimage2(VkCommandBuffer commandBuffer, struct hk_meta_save save; hk_meta_begin(cmd, &save, VK_PIPELINE_BIND_POINT_GRAPHICS); - if (agx_native_graphics(&dev->dev) && + if (agx_chip_native_agx3(dev->dev.chip) && src_image->vk.image_type == VK_IMAGE_TYPE_2D && dst_image->vk.image_type == VK_IMAGE_TYPE_2D) { for (uint32_t r = 0; r < pBlitImageInfo->regionCount; ++r) { @@ -2879,7 +2880,7 @@ hk_xfer_resolveimage2(VkCommandBuffer commandBuffer, const struct ail_layout *src_layout = &src_image->planes[0].layout; const struct ail_layout *dst_layout = &dst_image->planes[0].layout; bool raw_unorm8x4 = - agx_native_graphics(&dev->dev) && + agx_chip_native_agx3(dev->dev.chip) && src_image->vk.image_type == VK_IMAGE_TYPE_2D && dst_image->vk.image_type == VK_IMAGE_TYPE_2D && src_image->vk.format == VK_FORMAT_R8G8B8A8_UNORM && @@ -4724,10 +4725,10 @@ hk_xfer_copybuffertoimage2(VkCommandBuffer commandBuffer, struct vk_meta_copy_image_properties dst_props = hk_meta_copy_get_image_properties( dst_image, dev, - agx_native_graphics(&dev->dev) || m5_split_zs || m5_color, + agx_chip_native_agx3(dev->dev.chip) || m5_split_zs || m5_color, m5_split_zs); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { /* Native single-slice EOT views already select the mip and array * layer or 3D Z slice. Keep source row/image strides intact while * splitting multi-layer and volume regions; no staging copy. */ @@ -4879,7 +4880,7 @@ hk_xfer_copyimage2(VkCommandBuffer commandBuffer, struct vk_meta_copy_image_properties dst_props = hk_meta_copy_get_image_properties(dst_image, dev, native, zs_planes); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { /* The qualified HAL200 BG/EOT contract is single-layer. Preserve * arbitrary mip and rectangle selection while expanding array and * 3D regions into per-slice native meta draws. */ @@ -5119,7 +5120,7 @@ hk_xfer_fillbuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VK_FROM_HANDLE(hk_buffer, buffer, dstBuffer); struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { /* VK_WHOLE_SIZE fills only complete 32-bit words. */ VkDeviceSize size = vk_buffer_range(&buffer->vk, dstOffset, dstRange) & ~(VkDeviceSize)3; @@ -5161,7 +5162,7 @@ hk_xfer_updatebuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VK_FROM_HANDLE(hk_cmd_buffer, cmd, commandBuffer); VK_FROM_HANDLE(hk_buffer, buffer, dstBuffer); struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { struct hk_meta_save save; hk_meta_begin(cmd, &save, VK_PIPELINE_BIND_POINT_COMPUTE); vk_meta_update_buffer(&cmd->vk, &dev->meta, dstBuffer, dstOffset, dstRange, diff --git a/src/asahi/vulkan/hk_cmd_upload.c b/src/asahi/vulkan/hk_cmd_upload.c index 134dca90604b..fd2111887dfd 100644 --- a/src/asahi/vulkan/hk_cmd_upload.c +++ b/src/asahi/vulkan/hk_cmd_upload.c @@ -11,7 +11,7 @@ hk_pool_root_alloc(struct hk_cmd_buffer *cmd, uint32_t size, uint32_t alignment) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (!agx_native_graphics(&dev->dev)) + if (!agx_chip_native_agx3(dev->dev.chip)) return hk_pool_alloc(cmd, size, alignment); return hk_pool_alloc_from(cmd, &cmd->uploader.root, size, alignment, @@ -52,7 +52,7 @@ hk_cmd_buffer_upload_root(struct hk_cmd_buffer *cmd, const size_t tail_B = hk_root_descriptor_offset(set_dynamic_buffer_start); /* CPU-decoded descriptor programs use a new root identity to invalidate * their native program caches, even when only set memory changed. */ - if (agx_native_graphics(&dev->dev) && desc->uploaded_root.gpu && + if (agx_chip_native_agx3(dev->dev.chip) && desc->uploaded_root.gpu && desc->uploaded_root_size == root_size && desc->generation == desc->uploaded_root_generation && desc->dynamic_buffer_end == desc->uploaded_dynamic_buffer_end) { @@ -101,7 +101,7 @@ hk_cmd_buffer_upload_root(struct hk_cmd_buffer *cmd, /* Cached G17P roots need explicit CPU-to-GPU publication. Clean just this * table now; vkEndCommandBuffer completes all recorded root cleans with a * single fence before submission can consume them. */ - if (agx_native_graphics(&dev->dev) && util_has_cache_ops()) { + if (agx_chip_native_agx3(dev->dev.chip) && util_has_cache_ops()) { util_flush_range_no_fence(root_ptr.cpu, head_B); if (tail_B < root_size) util_flush_range_no_fence((uint8_t *)root_ptr.cpu + tail_B, @@ -125,7 +125,8 @@ hk_cmd_upload_constants(struct hk_cmd_buffer *cmd, const struct hk_shader *s, return 0; assert(stage < MESA_SHADER_STAGES); - const bool native = agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev); + const bool native = + agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip); if (native && s->constant_data_id && cmd->state.constant_data[stage].id == s->constant_data_id) { hk_upload_stat(cmd, constant_reuses, 1); @@ -151,7 +152,7 @@ hk_cmd_upload_draw_params(struct hk_cmd_buffer *cmd, uint32_t first, { struct hk_graphics_state *gfx = &cmd->state.gfx; uint32_t params[] = {first, first_instance}; - if (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) && + if (agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip) && gfx->g17p_draw_params_host_valid && gfx->draw_params && memcmp(gfx->g17p_draw_params_value, params, sizeof(params)) == 0) { hk_upload_stat(cmd, draw_param_reuses, 1); @@ -172,7 +173,7 @@ void hk_cmd_upload_draw_id(struct hk_cmd_buffer *cmd, uint32_t draw_id) { struct hk_graphics_state *gfx = &cmd->state.gfx; - if (agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) && + if (agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip) && gfx->g17p_draw_id_host_valid && gfx->draw_id_ptr && gfx->g17p_draw_id_value == draw_id) { hk_upload_stat(cmd, draw_id_reuses, 1); diff --git a/src/asahi/vulkan/hk_descriptor_set.c b/src/asahi/vulkan/hk_descriptor_set.c index 8f901582ec68..c86eff0dcfad 100644 --- a/src/asahi/vulkan/hk_descriptor_set.c +++ b/src/asahi/vulkan/hk_descriptor_set.c @@ -1097,7 +1097,7 @@ hk_CreateDescriptorPool(VkDevice _device, * the recording core. */ pool->cpu_cached = hk_g17p_cached_cmd_memory(&dev->dev); const enum agx_bo_flags pool_flags = - agx_native_graphics(&dev->dev) + agx_chip_native_agx3(dev->dev.chip) ? AGX_BO_ZERO_ON_REUSE | (pool->cpu_cached ? AGX_BO_WRITEBACK : 0) : 0; @@ -1202,7 +1202,7 @@ hk_descriptor_set_create(struct hk_device *dev, struct hk_descriptor_pool *pool, * null texture / heap index 0, which is bound and safe. */ set->cpu_cached = pool->cpu_cached; - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { memset(set->mapped_ptr, 0, set->size); hk_descriptor_set_publish(set, set->mapped_ptr, set->size); } diff --git a/src/asahi/vulkan/hk_device.c b/src/asahi/vulkan/hk_device.c index 2d23a3ccda81..5539bec10ec2 100644 --- a/src/asahi/vulkan/hk_device.c +++ b/src/asahi/vulkan/hk_device.c @@ -120,7 +120,7 @@ hk_upload_rodata(struct hk_device *dev) VkResult result = VK_ERROR_OUT_OF_DEVICE_MEMORY; /* Background reloads use the same two native texel-fetch selectors as * ordinary shaders: staged multisample reads name entry one. */ - const unsigned sampler_count = agx_native_graphics(&dev->dev) ? 2 : 1; + const unsigned sampler_count = agx_chip_native_agx3(dev->dev.chip) ? 2 : 1; const size_t rodata_size = align(sampler_count * sampler_size, sizeof(uint64_t)); dev->rodata.bo = agx_bo_create(&dev->dev, rodata_size, 0, 0, "Read only data"); @@ -275,7 +275,7 @@ hk_init_sampler_heap(struct hk_device *dev, struct hk_sampler_heap *h) VkResult result = hk_descriptor_table_init(dev, &h->table, sampler_size, 1024, - agx_native_graphics(&dev->dev) ? 4096 + agx_chip_native_agx3(dev->dev.chip) ? 4096 : agx_chip_hal300_path(dev->dev.chip) ? 2048 : 1024); @@ -1112,7 +1112,7 @@ hk_CreateDevice(VkPhysicalDevice physicalDevice, * sampler exists, and most samples then pay one branch, so D3D content keeps * its correct borders there. */ if (instance->drirc.misc.disable_border_emulation && - !agx_native_graphics(&pdev->dev)) { + !agx_chip_native_agx3(pdev->dev.chip)) { dev->perftest |= HK_PERF_NOBORDER; } diff --git a/src/asahi/vulkan/hk_image.c b/src/asahi/vulkan/hk_image.c index cd39d142915b..24663b94dc20 100644 --- a/src/asahi/vulkan/hk_image.c +++ b/src/asahi/vulkan/hk_image.c @@ -71,7 +71,8 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, * of code inspection alone. COSITED_EVEN is kept because it is what this * driver actually implements and passes. */ - if (agx_native_graphics(&pdev->dev) && hk_packed_ycbcr_bits(vk_format)) { + if (agx_chip_native_agx3(pdev->dev.chip) && + hk_packed_ycbcr_bits(vk_format)) { if (tiling != VK_IMAGE_TILING_OPTIMAL && tiling != VK_IMAGE_TILING_LINEAR) return 0; return VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT | @@ -153,7 +154,7 @@ hk_get_image_plane_format_features(struct hk_physical_device *pdev, /* Keep compressed-family reporting atomic with the corresponding Vulkan * feature. The complete BC, ETC2/EAC and ASTC LDR format matrices are * hardware-qualified through the native G17P sampled/upload path. */ - if (agx_native_graphics(&pdev->dev) && + if (agx_chip_native_agx3(pdev->dev.chip) && util_format_is_compressed(p_format) && !hk_g17p_bc_format_supported(vk_format)) { const enum util_format_layout layout = @@ -319,7 +320,7 @@ hk_get_image_format_features(struct hk_physical_device *pdev, } /* G17P used to add CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE here, and only - * G17P: agx_native_graphics() is G16G/G17P, so M1/M2 reach these formats + * G17P: agx_chip_native_agx3() is G16G/G17P, so M1/M2 reach these formats * without it and every explicit_* conformance case is NotSupported there. * * That bit is the sole route into VK-GL-CTS's explicit reconstruction diff --git a/src/asahi/vulkan/hk_image_view.c b/src/asahi/vulkan/hk_image_view.c index fae2c36315fa..c3e712bca084 100644 --- a/src/asahi/vulkan/hk_image_view.c +++ b/src/asahi/vulkan/hk_image_view.c @@ -236,7 +236,7 @@ pack_texture(struct hk_device *dev, struct hk_image_view *view, unsigned layer = view->vk.base_array_layer; enum pipe_format p_format = format_for_plane(view, view_plane); - const unsigned packed_ycbcr = agx_native_graphics(&dev->dev) + const unsigned packed_ycbcr = agx_chip_native_agx3(dev->dev.chip) ? hk_packed_ycbcr_bits(view->vk.format) : 0; if (packed_ycbcr) p_format = packed_ycbcr == 8 ? PIPE_FORMAT_R8G8B8A8_UNORM : @@ -246,7 +246,7 @@ pack_texture(struct hk_device *dev, struct hk_image_view *view, hk_padded_image_format(p_format) != p_format; if (padded_rgb) p_format = hk_padded_image_format(p_format); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { enum pipe_format integer = hk_scaled_texture_format(p_format); enum pipe_format normalized = hk_uscaled_normalized_format(p_format); if (usage == HK_DESC_USAGE_SAMPLED_FILTERABLE && @@ -341,7 +341,7 @@ pack_texture(struct hk_device *dev, struct hk_image_view *view, * false) and native meta copies view one layer * (copied_layers_src_view). */ - if (unlikely(layers > 1) && agx_native_graphics(&dev->dev)) + if (unlikely(layers > 1) && agx_chip_native_agx3(dev->dev.chip)) mesa_loge_once("hk: uncompressed view of %u layers of a " "block-compressed image addresses only the first", layers); @@ -350,7 +350,7 @@ pack_texture(struct hk_device *dev, struct hk_image_view *view, cfg.width = DIV_ROUND_UP(u_minify(layout->width_px, level), denom.x); cfg.height = DIV_ROUND_UP(u_minify(layout->height_px, level), denom.y); cfg.first_level = 0; - cfg.last_level = agx_native_graphics(&dev->dev) ? 0 : 1; + cfg.last_level = agx_chip_native_agx3(dev->dev.chip) ? 0 : 1; } else { cfg.address = base_addr + ail_get_layer_offset_B(layout, layer); cfg.width = layout->width_px; diff --git a/src/asahi/vulkan/hk_physical_device.c b/src/asahi/vulkan/hk_physical_device.c index 02f9cce28e1c..2e1fe71b7502 100644 --- a/src/asahi/vulkan/hk_physical_device.c +++ b/src/asahi/vulkan/hk_physical_device.c @@ -104,7 +104,7 @@ hk_get_device_extensions(const struct agx_device *dev, * implementations have been qualified there. Native AGX3 and M5 keep * their existing exposure. */ - const bool native_agx3 = (agx_native_graphics(dev) && + const bool native_agx3 = (agx_chip_native_agx3(dev->chip) && dev->params.gpu_generation > 15) || agx_chip_g17_m5(dev->chip); @@ -255,7 +255,7 @@ hk_get_device_extensions(const struct agx_device *dev, .EXT_extended_dynamic_state3 = true, .EXT_external_memory_dma_buf = true, .EXT_external_memory_host = agx_has_userptr(dev), - .EXT_fragment_shader_interlock = agx_native_graphics(dev), + .EXT_fragment_shader_interlock = agx_chip_native_agx3(dev->chip), .EXT_global_priority = true, .EXT_global_priority_query = true, .EXT_graphics_pipeline_library = true, @@ -2275,7 +2275,7 @@ hk_create_drm_physical_device(struct vk_instance *_instance, supported_extensions.EXT_sampler_filter_minmax = agx_chip_sampler_generation(pdev->dev.chip) == AGX_SAMPLER_GENERATION_GEN5; - if (agx_native_graphics(&pdev->dev)) { + if (agx_chip_native_agx3(pdev->dev.chip)) { supported_extensions.KHR_shader_quad_control = pdev->dev.chip == AGX_CHIP_G17P; } @@ -2404,7 +2404,7 @@ hk_create_drm_physical_device(struct vk_instance *_instance, VkQueueFlags queue_flags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT | VK_QUEUE_SPARSE_BINDING_BIT; - if (agx_native_graphics(&pdev->dev)) { + if (agx_chip_native_agx3(pdev->dev.chip)) { /* Graphics, compute and transfers use the native HAL200 queue path. * Sparse binding rides the shared per-page VM_BIND path; advertise it * only when the same opt-in that turns on the sparse features above is diff --git a/src/asahi/vulkan/hk_query_pool.c b/src/asahi/vulkan/hk_query_pool.c index dc493e8a91d0..4c019dfaade3 100644 --- a/src/asahi/vulkan/hk_query_pool.c +++ b/src/asahi/vulkan/hk_query_pool.c @@ -303,7 +303,7 @@ hk_dispatch_imm_writes(struct hk_cmd_buffer *cmd, struct hk_cs *cs) * buffer, when it is no longer current: a post-graphics dispatch would * open a new stream after every later command, a query copy or reset * included. Write into the stream itself, as native AGX3 does. */ - const bool pin = agx_native_graphics(&dev->dev) || + const bool pin = agx_chip_native_agx3(dev->dev.chip) || (cs != cmd->current_cs.post_gfx && cs != cmd->current_cs.cs); if (pin) { /* End-of-stream writes belong to this exact post-graphics stream. @@ -363,7 +363,7 @@ hk_queue_write(struct hk_cmd_buffer *cmd, uint64_t address, uint32_t value, hk_cdm_cache_flush(dev, cs); perf_debug(cmd, "Queued write"); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { hk_g17p_meta_fill_addr(cmd, &cmd->current_cs.cs, address, sizeof(value), value); return; @@ -577,7 +577,7 @@ emit_zero_queries(struct hk_cmd_buffer *cmd, struct hk_query_pool *pool, struct hk_device *dev = hk_cmd_buffer_device(cmd); perf_debug(cmd, "Query pool zero"); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { emit_zero_queries_g17p(cmd, pool, first_index, num_queries, set_available); return; @@ -754,7 +754,7 @@ hk_CreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo, /* See hk_oq_submission_done(): only the native AGX3 path needs the * submission point. */ - if (occlusion_queries && agx_native_graphics(&dev->dev)) { + if (occlusion_queries && agx_chip_native_agx3(dev->dev.chip)) { pool->oq_submit = vk_zalloc2(&dev->vk.alloc, pAllocator, sizeof(*pool->oq_submit) * occlusion_queries, 8, @@ -1879,7 +1879,8 @@ hk_cmd_copy_query_pool_results(struct hk_cmd_buffer *cmd, * Finish the producing streams before creating a waiting consumer so it * cannot spin ahead of its own availability write. Do this before * hk_query_command_cs attaches dependencies to the consumer stream. */ - if (agx_native_graphics(&dev->dev) && (flags & VK_QUERY_RESULT_WAIT_BIT)) { + if (agx_chip_native_agx3(dev->dev.chip) && + (flags & VK_QUERY_RESULT_WAIT_BIT)) { hk_cmd_buffer_end_graphics(cmd); hk_cmd_buffer_end_compute(cmd); } @@ -1892,7 +1893,7 @@ hk_cmd_copy_query_pool_results(struct hk_cmd_buffer *cmd, perf_debug(cmd, "Query pool copy"); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { if ((pool->vk.query_type != VK_QUERY_TYPE_TIMESTAMP && pool->vk.query_type != VK_QUERY_TYPE_OCCLUSION && pool->vk.query_type != VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT && diff --git a/src/asahi/vulkan/hk_sampler.c b/src/asahi/vulkan/hk_sampler.c index 5807fe3d9a46..bbdbbd11ee32 100644 --- a/src/asahi/vulkan/hk_sampler.c +++ b/src/asahi/vulkan/hk_sampler.c @@ -307,7 +307,8 @@ hk_CreateSampler(VkDevice device, * we no longer guarantee it, which is what "reconstruction is * implementation-defined" means. */ - if (agx_native_graphics(&dev->dev) && hk_packed_ycbcr_bits(sampler->ycbcr.format)) + if (agx_chip_native_agx3(dev->dev.chip) && + hk_packed_ycbcr_bits(sampler->ycbcr.format)) sampler->ycbcr.force_explicit_reconstruction = true; /* Explicit nearest chroma maps luma (i,j) to (i/2,j/2), independent * of chroma location. Linear reconstruction retains the offset. */ @@ -317,8 +318,8 @@ hk_CreateSampler(VkDevice device, } bool workaround_rgba4 = dev->vk.enabled_features.customBorderColors || - agx_native_graphics(&dev->dev); - bool int_border_custom = agx_native_graphics(&dev->dev); + agx_chip_native_agx3(dev->dev.chip); + bool int_border_custom = agx_chip_native_agx3(dev->dev.chip); bool custom_border = uses_border(info) && is_border_color_custom(info->borderColor, workaround_rgba4, @@ -389,7 +390,8 @@ hk_CreateSampler(VkDevice device, /* Packed conversion fetches raw words; chroma filtering runs in the * shader and does not consume a second sampler/descriptor plane. */ if (sampler->vk.ycbcr_conversion && - !(agx_native_graphics(&dev->dev) && hk_packed_ycbcr_bits(sampler->ycbcr.format))) { + !(agx_chip_native_agx3(dev->dev.chip) && + hk_packed_ycbcr_bits(sampler->ycbcr.format))) { assert(!uses_border(info) && "consequence of VUID-VkSamplerCreateInfo-addressModeU-01646"); diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index 0d75a9ea3546..491b4dfaf106 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -531,7 +531,7 @@ hk_preprocess_nir_internal(struct vk_physical_device *vk_pdev, nir_shader *nir) } /* Optimize but allow copies because we haven't lowered them yet */ - if (agx_native_graphics(&((struct hk_physical_device *)vk_pdev)->dev) && + if (agx_chip_native_agx3(((struct hk_physical_device *)vk_pdev)->dev.chip) && nir->info.stage != MESA_SHADER_MESH) agx_preprocess_nir_native( nir, ((struct hk_physical_device *)vk_pdev)->dev.chip); @@ -983,7 +983,7 @@ hk_hash_graphics_state(struct vk_physical_device *device, /* G17P removes user varyings from fragmentless pipelines, so the same * pre-rasterization shader compiles differently for a library. */ - if (agx_native_graphics(&((struct hk_physical_device *)device)->dev) && + if (agx_chip_native_agx3(((struct hk_physical_device *)device)->dev.chip) && !(stages & VK_SHADER_STAGE_FRAGMENT_BIT)) { const bool no_fragment_shader = hk_pipeline_has_no_fragment_shader(state); _mesa_blake3_update(&blake3_ctx, &no_fragment_shader, @@ -3075,7 +3075,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, NULL); NIR_PASS(_, nir, nir_lower_wpos_center); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { NIR_PASS(_, nir, agx_nir_lower_g17p_helper_samples); } } @@ -3108,7 +3108,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, &ycbcr_state); NIR_PASS(_, nir, nir_shader_tex_pass, lower_ycbcr_chroma_blend, nir_metadata_none, (void *)&ycbcr_state); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { NIR_PASS(_, nir, nir_shader_tex_pass, lower_ycbcr_plane_range, nir_metadata_control_flow, (void *)&ycbcr_state); } @@ -3198,7 +3198,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, else NIR_PASS(_, nir, agx_nir_lower_texture_early, support_lod_bias); - if (agx_native_graphics(&dev->dev) && + if (agx_chip_native_agx3(dev->dev.chip) && agx_chip_sampler_has_lod_bias(dev->dev.chip)) NIR_PASS(_, nir, nir_shader_tex_pass, hk_lower_g17p_sampler_bias, nir_metadata_control_flow, NULL); @@ -3211,7 +3211,8 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, NIR_PASS(_, nir, hk_nir_lower_image_view_min_lod); } - if (((features & HK_FEAT_CUSTOM_BORDER) || agx_native_graphics(&dev->dev)) && + if (((features & HK_FEAT_CUSTOM_BORDER) || + agx_chip_native_agx3(dev->dev.chip)) && !HK_PERF(dev, NOBORDER)) { NIR_PASS(_, nir, agx_nir_lower_custom_border); } @@ -3509,7 +3510,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir, if (nir->info.stage != MESA_SHADER_MESH && !(nir->info.stage == MESA_SHADER_TASK && agx_chip_g17p_or_m5(dev->dev.chip))) { - if (agx_native_graphics(&dev->dev)) + if (agx_chip_native_agx3(dev->dev.chip)) agx_preprocess_nir_native(nir, dev->dev.chip); else if (dev->dev.chip == AGX_CHIP_G18G) agx_preprocess_nir_g18g(nir); @@ -4815,7 +4816,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * in a register (agx_optimizer_inline_imm), so only G17P admits one to * the sampler lowerings below. */ const bool g17p = dev->dev.chip == AGX_CHIP_G17P; - if (agx_native_graphics(&dev->dev) && + if (agx_chip_native_agx3(dev->dev.chip) && nir->info.stage == MESA_SHADER_VERTEX) { /* Software vertex variants feed geometry/tessellation through CDM. * They use the same indexed texture heap and shifted vertex uniforms @@ -4839,7 +4840,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, AGX_ABI_G17P_TEXTURE_POINTER_HALFS, shader->info.agx3_gen1_fragment_rq); } - } else if (agx_native_graphics(&dev->dev) && + } else if (agx_chip_native_agx3(dev->dev.chip) && (nir->info.stage == MESA_SHADER_GEOMETRY || nir->info.stage == MESA_SHADER_TESS_CTRL || nir->info.stage == MESA_SHADER_TESS_EVAL || @@ -4921,7 +4922,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, } } shader->info.g18_unlowered_image = hk_g18g_has_unlowered_image(nir); - } else if (agx_native_graphics(&dev->dev) && + } else if (agx_chip_native_agx3(dev->dev.chip) && nir->info.stage == MESA_SHADER_COMPUTE) { /* Descriptor buffers keep only the heap-indexed paths, which never * decode set contents while recording. */ @@ -5057,7 +5058,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, NIR_PASS(_, nir, nir_lower_alpha_to_coverage, false, enable); } - if (agx_native_graphics(&dev->dev)) + if (agx_chip_native_agx3(dev->dev.chip)) shader->info.fs.g17p_colour_unit_range = agx_nir_fs_colour_outputs_unit_range(nir); @@ -5110,7 +5111,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, a2c_in_main ? &a2c_in_main : NULL); } shader->info.fs.a2c_in_main = a2c_in_main; - } else if (agx_native_graphics(&dev->dev)) + } else if (agx_chip_native_agx3(dev->dev.chip)) NIR_PASS(_, nir, agx_nir_lower_sample_mask_deferred); else NIR_PASS(_, nir, agx_nir_lower_sample_mask); @@ -5242,7 +5243,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * layer on this generation. */ NIR_PASS(_, nir, agx_nir_lower_interpolation, agx_chip_native_or_m5(dev->dev.chip)); - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { NIR_PASS(_, nir, nir_shader_intrinsics_pass, hk_g17p_lower_is_first_fan, nir_metadata_control_flow, NULL); @@ -5297,7 +5298,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, uint64_t outputs = nir->info.outputs_written; if (sw_stage == MESA_SHADER_VERTEX || sw_stage == MESA_SHADER_TESS_EVAL) { if (hw) { - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { NIR_PASS(_, nir, nir_shader_intrinsics_pass, hk_g17p_saturate_layer_viewport, nir_metadata_control_flow, NULL); @@ -5308,7 +5309,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, hk_lower_hw_vs(dev, nir, shader, kill_psiz, agx_chip_native_or_m5(dev->dev.chip), default_layer, hk_clip_m1_1(dev, features), - agx_native_graphics(&dev->dev) + agx_chip_native_agx3(dev->dev.chip) ? hk_root_descriptor_offset(draw.no_attachments) : -1); outputs = nir->info.outputs_written; @@ -5450,7 +5451,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, rs->uniform_buffers != VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT), .g17p_sparse_vertex_outputs = - agx_native_graphics(&dev->dev) && hw && + agx_chip_native_agx3(dev->dev.chip) && hw && hk_g17p_sparse_vertex_outputs(&nir->info, sw_stage, xfb_info && xfb_info->output_count), /* The placeholder indices of a relocatable UVS layout, which the @@ -5472,7 +5473,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, .no_preamble = dev->dev.chip == AGX_CHIP_G18G || (agx_chip_g17_m5(dev->dev.chip) && !m5_compute_cprog && !m5_fs_cprog) || - (agx_native_graphics(&dev->dev) && + (agx_chip_native_agx3(dev->dev.chip) && (!agx_chip_native_preamble(dev->dev.chip) || !fs_reads_descriptors)), }; @@ -5481,7 +5482,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, * vertex constant programs); carried in the key, never in the global * debug word. */ backend_key.g17p_native_uniforms = - (agx_native_graphics(&dev->dev) || m5_fs_cprog) && + (agx_chip_native_agx3(dev->dev.chip) || m5_fs_cprog) && !backend_key.no_preamble; /* Uniform DMA: the root table, every descriptor set pointer, the dynamic @@ -5504,7 +5505,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, const bool fs_dma = backend_key.no_preamble && sw_stage == MESA_SHADER_FRAGMENT && nir->info.stage == MESA_SHADER_FRAGMENT; - if ((agx_native_graphics(&dev->dev) && (fs_dma || vs_dma || cs_dma)) || + if ((agx_chip_native_agx3(dev->dev.chip) && (fs_dma || vs_dma || cs_dma)) || (agx_chip_g17_m5(dev->dev.chip) && (fs_dma || vs_dma || (cs_dma && m5_compute_cprog)))) { backend_key.g17p_uniform_dma = true; @@ -5551,7 +5552,7 @@ hk_compile_nir(struct hk_device *dev, const VkAllocationCallbacks *pAllocator, sw_stage == MESA_SHADER_FRAGMENT && hk_m5_uniform_colour(nir)) || (sw_stage == MESA_SHADER_FRAGMENT && shader->info.fs.m5_inline_sample_shading) || - (agx_native_graphics(&dev->dev) && + (agx_chip_native_agx3(dev->dev.chip) && (agx_get_fs_structure_flags() & AGX_FS_STRUCTURE_INLINE_BLEND) && sw_stage == MESA_SHADER_FRAGMENT && nir->info.stage == MESA_SHADER_FRAGMENT && !nir->info.internal && @@ -7652,7 +7653,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf * non-AGX2 command-stream generations, so those keep replay until they * have a graphics-stage CDM launcher. */ const bool supports_gs_main_cdm = - agx_native_graphics(&dev->dev) || + agx_chip_native_agx3(dev->dev.chip) || agx_chip_command_stream_generation(dev->dev.chip) == AGX_CS_GENERATION_AGX2; const enum poly_gs_side_effects side_effects = @@ -7687,7 +7688,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf NIR_PASS(_, rast, nir_lower_default_point_size); struct hk_shader *shader = &obj->variants[HK_GS_VARIANT_RAST]; - if (agx_native_graphics(&dev->dev)) { + if (agx_chip_native_agx3(dev->dev.chip)) { NIR_PASS(_, rast, nir_shader_intrinsics_pass, hk_g17p_saturate_layer_viewport, nir_metadata_control_flow, NULL); @@ -7695,7 +7696,7 @@ hk_compile_shader_impl(struct hk_device *dev, struct vk_shader_compile_info *inf hk_lower_hw_vs(dev, rast, shader, false, agx_chip_native_or_m5(dev->dev.chip), true, hk_clip_m1_1(dev, features), - agx_native_graphics(&dev->dev) + agx_chip_native_agx3(dev->dev.chip) ? hk_root_descriptor_offset(draw.no_attachments) : -1); shader->info.gs = count_variant->info.gs; @@ -8361,7 +8362,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, * * Do not apply this to pipeline libraries: their pre-raster shader can be * linked with a fragment library later. */ - if (agx_native_graphics(&dev->dev) && shader_count > 0 && + if (agx_chip_native_agx3(dev->dev.chip) && shader_count > 0 && hk_pipeline_has_no_fragment_shader(state)) { nir_shader *last = shaders[shader_count - 1]; if (last->info.stage <= MESA_SHADER_GEOMETRY) @@ -8421,7 +8422,7 @@ hk_compile_shaders(struct vk_device *vk_dev, uint32_t shader_count, /* Only a complete pipeline known to have no fragment shader can fix an * empty interpolation contract. A pre-raster library or shader object * must retain draw-time UVS indices for its eventual fragment consumer. */ - if (agx_native_graphics(&dev->dev) && shader_count > 0 && + if (agx_chip_native_agx3(dev->dev.chip) && shader_count > 0 && hk_pipeline_has_no_fragment_shader(state)) { nir_shader *last = shaders[shader_count - 1]; if (last->info.stage <= MESA_SHADER_GEOMETRY) { @@ -8740,19 +8741,19 @@ hk_deserialize_api_shader_impl(struct vk_device *vk_dev, if (blob->overrun || stage >= MESA_SHADER_MESH_STAGES || (clip_z ? !dev->vk.physical->supported_features.depthClipControl : dev->vk.enabled_features.depthClipControl) || - (has_mesh_source && (stage != MESA_SHADER_FRAGMENT || - dev->dev.chip != AGX_CHIP_G17P)) || + (has_mesh_source && + (stage != MESA_SHADER_FRAGMENT || dev->dev.chip != AGX_CHIP_G17P)) || (variant_flags2 & ~1u) || (has_fbl_source && stage != MESA_SHADER_FRAGMENT) || (has_source && !sample_variants) || (m5_sample_variants && (!sample_variants || !agx_chip_g17_m5(dev->dev.chip))) || - (sample_variants && - (stage != MESA_SHADER_FRAGMENT || - (agx_chip_g17_m5(dev->dev.chip) ? !m5_sample_variants - : !agx_native_graphics(&dev->dev)))) || + (sample_variants && (stage != MESA_SHADER_FRAGMENT || + (agx_chip_g17_m5(dev->dev.chip) + ? !m5_sample_variants + : !agx_chip_native_agx3(dev->dev.chip)))) || (has_mono && (stage != MESA_SHADER_FRAGMENT || - !agx_chip_native_or_m5(dev->dev.chip)))) + !agx_chip_native_or_m5(dev->dev.chip)))) return vk_error(dev, VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT); /* Compiled with a custom-border emulation that this GPU, with no sampler diff --git a/src/asahi/vulkan/hk_sync.c b/src/asahi/vulkan/hk_sync.c index ea9d18a4fdeb..35163473cb9a 100644 --- a/src/asahi/vulkan/hk_sync.c +++ b/src/asahi/vulkan/hk_sync.c @@ -1032,7 +1032,7 @@ static void stamp_carrier_launch(struct hk_cmd_buffer *cmd) { struct hk_cs *cs = cmd->current_cs.cs; - if (!agx_native_graphics(&hk_cmd_buffer_device(cmd)->dev) || !cs || + if (!agx_chip_native_agx3(hk_cmd_buffer_device(cmd)->dev.chip) || !cs || (!cs->timestamp.start.handle && !cs->timestamp.end.handle) || cs->stats.cmds || cs->stats.flushes || cs->imm_writes.size) return; @@ -1229,7 +1229,8 @@ stamp_wait(struct hk_cmd_buffer *cmd, struct hk_cs *cs, { if (cs->type == HK_CS_CDM) { const struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (agx_native_graphics(&dev->dev) && dev->dev.chip == AGX_CHIP_G17P && + if (agx_chip_native_agx3(dev->dev.chip) && + dev->dev.chip == AGX_CHIP_G17P && (dev->dev.params.features & DRM_ASAHI_FEATURE_EXACT_PRIOR_BARRIERS)) { /* The logical compute queue already orders these GPU commands by * their mandatory kick parents. Adding the timestamp's same-CDM @@ -1270,7 +1271,7 @@ static bool start_stamps_ordered(const struct hk_cmd_buffer *cmd) { const struct hk_device *dev = hk_cmd_buffer_device(cmd); - return !((agx_native_graphics(&dev->dev) && + return !((agx_chip_native_agx3(dev->dev.chip) && dev->dev.chip == AGX_CHIP_G17P) || agx_chip_g17_m5(dev->dev.chip)); } From b40713cbaf57272caafb810bcbb41a670bbc320f Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:37:02 -0300 Subject: [PATCH 11/13] asahi: spell the native path test agx_chip_native_agx3() The Gallium half of the previous commit: 66 calls of agx_native_graphics(dev) become agx_chip_native_agx3(dev->chip), rewritten by script. The lines that grew past 80 columns are re-wrapped. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216, and the Gallium driver builds. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/gallium/drivers/asahi/agx_batch.c | 4 +- src/gallium/drivers/asahi/agx_blit.c | 6 +- src/gallium/drivers/asahi/agx_pipe.c | 8 +- src/gallium/drivers/asahi/agx_state.c | 114 +++++++++--------- src/gallium/drivers/asahi/agx_uniforms.c | 2 +- .../drivers/asahi/tests/test-agx-vs-query.c | 2 +- 6 files changed, 69 insertions(+), 67 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_batch.c b/src/gallium/drivers/asahi/agx_batch.c index 4ccf557dca79..317fd552aa9a 100644 --- a/src/gallium/drivers/asahi/agx_batch.c +++ b/src/gallium/drivers/asahi/agx_batch.c @@ -136,7 +136,7 @@ agx_batch_get_g17p_vdm_alias(struct agx_batch *batch, struct agx_bo *bo, uint64_t address) { struct agx_device *dev = agx_device(batch->ctx->base.screen); - if (!agx_native_graphics(dev)) + if (!agx_chip_native_agx3(dev->chip)) return address; if (!bo || address < bo->va->addr || address - bo->va->addr >= bo->size) @@ -166,7 +166,7 @@ agx_batch_get_g17p_vdm_alias(struct agx_batch *batch, struct agx_bo *bo, static void agx_encoder_bind_vdm_alias(struct agx_device *dev, struct agx_encoder *encoder) { - if (!agx_native_graphics(dev)) + if (!agx_chip_native_agx3(dev->chip)) return; encoder->g17p_vdm_alias = agx_bo_get_g17p_vdm_alias(dev, encoder->bo); diff --git a/src/gallium/drivers/asahi/agx_blit.c b/src/gallium/drivers/asahi/agx_blit.c index 99d2fa36e934..ca279169aa58 100644 --- a/src/gallium/drivers/asahi/agx_blit.c +++ b/src/gallium/drivers/asahi/agx_blit.c @@ -832,13 +832,13 @@ agx_blit(struct pipe_context *pipe, const struct pipe_blit_info *info) * written and the next pass reloaded stale memory (dEQP-GLES3 * multisample.fbo_4_samples.stencil: samples a stencil test rejected * came back zero; gpu/msstencil.c in m5air). */ - if (agx_native_graphics(agx_device(ctx->base.screen)) && + if (agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) && agx_g17p_direct_resolve_blit_shape(info, true) && agx_g17p_attach_direct_resolve(ctx, info->src.resource, info->dst.resource, true)) return; - if (agx_native_graphics(agx_device(ctx->base.screen)) && + if (agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) && agx_g17p_staged_resolve_blit_shape(info) && agx_g17p_staged_resolve_blit(ctx, info)) return; @@ -893,7 +893,7 @@ agx_blit(struct pipe_context *pipe, const struct pipe_blit_info *info) * from the WSI image. Keep that copy in the same tile batch, and publish * the tile directly back to the WSI image when the swap resolve arrives. */ - if (agx_native_graphics(agx_device(ctx->base.screen)) && + if (agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) && agx_g17p_direct_resolve_blit_shape(info, false)) { if (agx_g17p_attach_direct_resolve(ctx, info->dst.resource, info->src.resource, false)) { diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index 74a4b4ea6b55..db0aabca0cbd 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -1416,7 +1416,7 @@ agx_clear(struct pipe_context *pctx, unsigned buffers, unsigned fastclear = buffers & ~(batch->draw | batch->load); struct agx_device *dev = agx_device(pctx->screen); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { agx_batch_init_state(batch); const struct agx_tilebuffer_layout *tib = &batch->tilebuffer_layout; /* A spilling multisample tilebuffer clears every target with the @@ -1827,7 +1827,7 @@ agx_cmdbuf(struct agx_device *dev, struct drm_asahi_cmd_render *c, /* A direct resolve also writes a different image: loaded samples in * tiles without geometry must reach that destination. */ if ((batch->clear & batch->resolve) || - (agx_native_graphics(dev) && batch->key.resolve && + (agx_chip_native_agx3(dev->chip) && batch->key.resolve && (batch->load & PIPE_CLEAR_COLOR0))) c->flags |= DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES; @@ -1952,7 +1952,7 @@ agx_flush_compute(struct agx_context *ctx, struct agx_batch *batch, { /* Finalize the encoder */ struct agx_device *dev = agx_device(ctx->base.screen); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { uint8_t terminate[AGX3_CDM_STREAM_TERMINATE_SIZE]; if (!agx3_cdm_stream_terminate_pack(dev->chip, terminate)) UNREACHABLE("G17P CDM terminate must be grounded"); @@ -2486,7 +2486,7 @@ agx_init_shader_caps(struct pipe_screen *pscreen) * texel-fetch entry, so native graphics and compute can expose * Gallium's complete API table without the legacy heap. Geometry * shaders use the same table through their lowered compute programs. */ - if (agx_native_graphics(agx_device(pscreen)) && + if (agx_chip_native_agx3(agx_device(pscreen)->chip) && (i == MESA_SHADER_VERTEX || i == MESA_SHADER_FRAGMENT || i == MESA_SHADER_GEOMETRY || i == MESA_SHADER_COMPUTE)) caps->max_texture_samplers = PIPE_MAX_SAMPLERS; diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index ba1b782adae2..1e0160dc9269 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -171,7 +171,7 @@ agx_gallium_ppp_fini(struct agx_batch *batch, uint8_t **out, return false; return agx_ppp_fini(dev->chip, out, &compact); } - if (!agx_native_graphics(dev)) + if (!agx_chip_native_agx3(dev->chip)) return agx_ppp_fini(dev->chip, out, ppp); struct agx_ppp_update compact_ppp = *ppp; @@ -1061,7 +1061,7 @@ agx_pack_texture(enum agx_descriptor_generation descriptor_generation, /* Native Gen9 cube descriptors require one complete six-face range. * The shared extended-range address is filled for all applicable * dimensions below, after the selected layer count is known. */ - if (agx_native_graphics(agx_device(rsrc->base.screen)) && + if (agx_chip_native_agx3(agx_device(rsrc->base.screen)->chip) && state->target == PIPE_TEXTURE_CUBE) { const unsigned faces = state->u.tex.last_layer - state->u.tex.first_layer + 1; @@ -1115,7 +1115,7 @@ agx_pack_texture(enum agx_descriptor_generation descriptor_generation, * the layers themselves are tightly or page aligned. Compression keeps * using the same word for metadata instead. */ const bool gen9_range = - agx_native_graphics(agx_device(rsrc->base.screen)) && + agx_chip_native_agx3(agx_device(rsrc->base.screen)->chip) && !rsrc->layout.compressed && rsrc->layout.tiling != AIL_TILING_LINEAR && (state->target == PIPE_TEXTURE_2D_ARRAY || @@ -1657,7 +1657,7 @@ agx_gallium_tilebuffer_layout(const struct agx_device *dev, return agx_build_tilebuffer_layout_with_limits( formats, nr_cbufs, nr_samples, layered, imageblock ? AGX_G17P_MAX_BYTES_PER_SAMPLE : 0, - imageblock ? 32768 : 0, agx_native_graphics(dev) ? 2048 : 0); + imageblock ? 32768 : 0, agx_chip_native_agx3(dev->chip) ? 2048 : 0); } /* Native G18 retains three RGBA32 targets at 2x/4x: 96 KiB and 2048 @@ -1950,7 +1950,8 @@ agx_g17p_direct_resolve_surface(struct agx_batch *batch, /* msaa163: G18G resolves its witnessed four-sample tile the same way. */ const bool g18_msaa4 = agx_g18_msaa4_tile_layout(dev, &batch->tilebuffer_layout); - if ((!agx_native_graphics(dev) && !g18_msaa4 && !agx_chip_g17_m5(dev->chip)) || + if ((!agx_chip_native_agx3(dev->chip) && !g18_msaa4 && + !agx_chip_g17_m5(dev->chip)) || fb->nr_cbufs != 1 || !source->texture || !target || (util_res_sample_count(source->texture) != 2 && util_res_sample_count(source->texture) != 4) || @@ -2780,7 +2781,7 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir, NIR_PASS(_, nir, agx_nir_layout_uniforms, compiled, &key.reserved_preamble, uniform_base, agx_chip_agx3_path(dev->chip)); - if (agx_native_graphics(dev)) + if (agx_chip_native_agx3(dev->chip)) NIR_PASS(_, nir, agx_nir_lower_g17p_storage_records, texture_descriptor_size); } @@ -3079,7 +3080,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, false, -1); } else { NIR_PASS(_, nir, agx_nir_lower_uvs, &uvs, - agx_native_graphics(dev), false, -1); + agx_chip_native_agx3(dev->chip), false, -1); } } else { if (agx_chip_g17_m5(dev->chip) && !nir->info.vs.tes_poly) @@ -3128,7 +3129,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, } const bool native_msaa_fbfetch = - agx_native_graphics(dev) && key->nr_samples > 1 && + agx_chip_native_agx3(dev->chip) && key->nr_samples > 1 && nir->info.fs.uses_fbfetch_output; if (native_msaa_fbfetch) nir->info.fs.uses_sample_shading = true; @@ -3143,7 +3144,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, * key already carries the raster sample count, so fold it into the * shader as hk_shader.c does. gl_SampleMaskIn, gl_SampleID and * interpolateAtSample() all read it. */ - if (agx_native_graphics(dev) && agx_nir_needs_sample_count(nir)) + if (agx_chip_native_agx3(dev->chip) && agx_nir_needs_sample_count(nir)) NIR_PASS(_, nir, agx_nir_specialize_sample_count, MAX2(key->nr_samples, 1)); @@ -3156,7 +3157,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, * G18G has no sample loop for the linker to splice either; there a * multisample stencil resolve still rasterizes into a single-sample * destination, and its tile stores use the whole-pixel protocol. */ - if ((((agx_native_graphics(dev) && key->nr_samples <= 1) || + if ((((agx_chip_native_agx3(dev->chip) && key->nr_samples <= 1) || (dev->chip == AGX_CHIP_G18G && keyed_samples == 1)) && nir->info.fs.uses_sample_shading) || (agx_chip_g17_m5(dev->chip) && key->nr_samples == 1)) { @@ -3192,7 +3193,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, const uint64_t zs_outputs = BITFIELD64_BIT(FRAG_RESULT_DEPTH) | BITFIELD64_BIT(FRAG_RESULT_STENCIL); const bool unrolled_samples = - ((agx_native_graphics(dev) && key->nr_samples > 1) || + ((agx_chip_native_agx3(dev->chip) && key->nr_samples > 1) || (dev->chip == AGX_CHIP_G18G && (key->nr_samples == 2 || key->nr_samples == 4))) && nir->info.fs.uses_sample_shading && @@ -3340,7 +3341,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, nir->info.fs.uses_sample_shading = false; g17g_samples_unrolled = true; } else if (nir->info.fs.uses_sample_shading && - agx_native_graphics(dev)) { + agx_chip_native_agx3(dev->chip)) { /* Use the same export layout and static sample copies as Vulkan. * The epilog consumes each sample's exports in the matching order. */ @@ -3539,7 +3540,7 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, false, -1); } else { NIR_PASS(_, gs_copy, agx_nir_lower_uvs, &uvs, - agx_native_graphics(dev), false, -1); + agx_chip_native_agx3(dev->chip), false, -1); } compiled->gs_copy = @@ -3890,7 +3891,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, NIR_PASS(_, nir, nir_lower_robust_access, should_lower_robustness, &robust); /* Similarly, we need to do early texture lowering before bindings. */ - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { NIR_PASS(_, nir, agx_nir_lower_g17p_texture_early, support_lod_bias, agx_chip_sampler_has_lod_bias(dev->chip)); } else { @@ -3922,7 +3923,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, /* We need to lower binding tables before calling agx_preprocess_nir, since * that does texture lowering that needs to know the binding model. */ - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { nir_foreach_function_impl(impl, nir) { nir_foreach_block(block, impl) { nir_foreach_instr(instr, block) { @@ -3959,8 +3960,8 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, .g17p_native_sampler_handles = agx_chip_agx3_path(dev->chip), .g18 = dev->chip == AGX_CHIP_G18G, - .g17p_bindless_storage = agx_native_graphics(dev), - .image_records = agx_native_graphics(dev) ? 3 : 2, + .g17p_bindless_storage = agx_chip_native_agx3(dev->chip), + .image_records = agx_chip_native_agx3(dev->chip) ? 3 : 2, .bindful_sampler_count = agx_chip_agx3_path(dev->chip) ? AGX_GALLIUM_G17P_IMMEDIATE_API_SAMPLERS @@ -4063,7 +4064,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, const enum agx_descriptor_generation descriptor_generation = agx_chip_descriptor_generation(dev->chip); - if (agx_native_graphics(dev)) + if (agx_chip_native_agx3(dev->chip)) { /* Texel fetches get G17P's explicit out-of-view predicate only in * robust contexts: elsewhere an out-of-range texelFetch is undefined @@ -4103,7 +4104,7 @@ agx_shader_initialize(struct agx_device *dev, struct agx_uncompiled_shader *so, /* The native stack protocol only encodes whole words; Honeykrisp gets * this from agx_preprocess_nir_g17p(). */ - if (agx_native_graphics(dev)) + if (agx_chip_native_agx3(dev->chip)) agx3_nir_lower_scratch_words(nir); if (nir->info.stage == MESA_SHADER_FRAGMENT && @@ -4637,7 +4638,7 @@ asahi_fast_link(struct agx_context *ctx, struct agx_uncompiled_shader *so, const enum agx_chip chip = agx_device(ctx->base.screen)->chip; epilog = agx_build_meta_shader_internal( ctx, - agx_native_graphics(agx_device(ctx->base.screen)) || + agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) || (agx_chip_g17_m5(chip) && key->epilog.fs.nr_samples > 1) ? build_g17p_fs_epilog : agx_device(ctx->base.screen)->chip == AGX_CHIP_G18G && @@ -4997,7 +4998,7 @@ agx_update_fs(struct agx_batch *batch) * A G17G fragment shader that runs per sample is unrolled over the sample * count, so the count belongs in its variant key too. */ - if (agx_native_graphics(dev) || + if (agx_chip_native_agx3(dev->chip) || ctx->stage[MESA_SHADER_FRAGMENT].shader->info.needs_sample_count || ctx->stage[MESA_SHADER_FRAGMENT].shader->info.uses_fbfetch || ctx->stage[MESA_SHADER_FRAGMENT].shader->info.uses_sample_shading || @@ -5037,7 +5038,7 @@ agx_update_fs(struct agx_batch *batch) ctx->fs->b.info.early_fragment_tests && (ctx->fs->b.info.writes_sample_mask || (ctx->fs->so && ctx->fs->so->info.writes_memory)); - const bool defer_api_sample_mask = agx_native_graphics(dev) && msaa && + const bool defer_api_sample_mask = agx_chip_native_agx3(dev->chip) && msaa && sample_mask != BITFIELD_MASK(nr_samples) && !nontrivial_force_early; struct agx_fast_link_key link_key = { @@ -5079,7 +5080,7 @@ agx_update_fs(struct agx_batch *batch) agx_chip_g17_m5(dev->chip) && batch->key.nr_cbufs > 1, .main = ctx->fs, - .nr_samples_shaded = !agx_native_graphics(dev) && + .nr_samples_shaded = !agx_chip_native_agx3(dev->chip) && ctx->fs->epilog_key.sample_shading && !ctx->fs->g17g_samples_unrolled ? nr_samples @@ -5189,7 +5190,7 @@ agx_update_fs(struct agx_batch *batch) return true; } - link_key.epilog.fs.native_spills = agx_native_graphics(dev) && + link_key.epilog.fs.native_spills = agx_chip_native_agx3(dev->chip) && agx_tilebuffer_spills(&batch->tilebuffer_layout); if (link_key.epilog.fs.native_spills) { uint16_t base; @@ -5513,7 +5514,7 @@ agx_build_meta_shader_internal(struct agx_context *ctx, dev, b.shader, NULL, dev->chip == AGX_CHIP_G18G ? MESA_SHADER_COMPUTE : b.shader->info.stage, internal_kernel, - !prolog && !(!agx_native_graphics(dev) && + !prolog && !(!agx_chip_native_agx3(dev->chip) && b.shader->info.stage == MESA_SHADER_FRAGMENT && b.shader->info.fs.uses_sample_shading), prolog || epilog, cf_base, compile_samples, @@ -5547,7 +5548,7 @@ sampler_count(struct agx_context *ctx, mesa_shader_stage stage) unsigned count = ctx->stage[stage].sampler_count + 1; /* Native staged MS reads name sampler one. Even an image-only shader * therefore needs that entry inside the declared sampler table. */ - return agx_native_graphics(agx_device(ctx->base.screen)) + return agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) ? MAX2(count, 2u) : count; } @@ -6115,7 +6116,7 @@ agx_upload_textures(struct agx_batch *batch, struct agx_compiled_shader *cs, agx_upload_spilled_rt_descriptors(out, batch, descriptor_generation, agx_nr_tex_descriptors_without_spilled_rts(cs), agx_g18_native_ms_spills(batch)); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { batch->g17p_emrt_heap = agx_upload_g17p_spilled_rt_table( batch, out, agx_nr_tex_descriptors_without_spilled_rts(cs)); if (!batch->g17p_emrt_heap) @@ -6272,7 +6273,7 @@ agx_upload_samplers(struct agx_batch *batch, struct agx_compiled_shader *cs, bool custom_borders = ctx->stage[stage].custom_borders; struct agx_device *dev = agx_device(ctx->base.screen); - const bool native = agx_native_graphics(dev); + const bool native = agx_chip_native_agx3(dev->chip); /* G18G uses the same native table, packed by agx_pack_g17_api_sampler(). */ const bool g18 = dev->chip == AGX_CHIP_G18G; size_t sampler_length = native || g18 || agx_chip_g17_m5(dev->chip) @@ -7633,7 +7634,7 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, return agx_build_agx3_graphics_program(batch, cs, linked, full_va, why); if (agx_chip_g17_m5(dev->chip) && phys_stage != MESA_SHADER_COMPUTE) return agx_build_native_g17g_graphics_program(batch, cs, linked, full_va); - if (agx_native_graphics(dev) && phys_stage != MESA_SHADER_COMPUTE) + if (agx_chip_native_agx3(dev->chip) && phys_stage != MESA_SHADER_COMPUTE) return agx_build_g17p_graphics_program(batch, cs, linked, full_va); unsigned constant_push_ranges = DIV_ROUND_UP(cs->b.info.rodata.size_16, 64); @@ -7686,7 +7687,7 @@ agx_build_pipeline(struct agx_batch *batch, struct agx_compiled_shader *cs, * to the legacy 40-bit USC Uniform packer either trips its bounds check * or relies on accidental truncation in release builds. */ const uint64_t rodata_base = - agx_native_graphics(dev) ? agx_usc_addr(dev, cs->bo->va->addr) + agx_chip_native_agx3(dev->chip) ? agx_usc_addr(dev, cs->bo->va->addr) : cs->bo->va->addr; agx_usc_immediates(&b, &cs->b.info.rodata, rodata_base); } @@ -8073,7 +8074,7 @@ agx_g17p_append_compute(struct agx_batch *batch, !info ? 0 : linked ? MAX2(linked->scratch_size, linked->agx3_spectpr_scratch_size) : MAX2(info->scratch_size, info->agx3_spectpr_scratch_size); - if (!agx_native_graphics(dev) || !info || !binary || + if (!agx_chip_native_agx3(dev->chip) || !info || !binary || (grid.mode != AGX_CDM_MODE_DIRECT && !indirect_local) || (indirect_local && (!grid.ptr || grid.ptr >= (UINT64_C(1) << 48) || (grid.ptr & 3))) || @@ -9101,7 +9102,7 @@ agx_launch_precomp(struct agx_batch *batch, struct agx_grid grid, return; } - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { if (!cs || !cs->bo || !cs->info.main_size || !cs->info.nr_gprs || cs->info.nr_preamble_gprs || (cs->info.rodata.size_16 && !cs->rodata_offset) || @@ -10181,7 +10182,7 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) * previous multisample contents. Only the loader's explicit seed uses * that image as a background source. */ .single_sample_reload = - (agx_native_graphics(dev) ? batch->g17p_resolve_reload + (agx_chip_native_agx3(dev->chip) ? batch->g17p_resolve_reload : agx_chip_g17_m5(dev->chip)) && !store && !partial_render && batch->tilebuffer_layout.nr_samples > 1 && batch->key.resolve, @@ -10192,9 +10193,9 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) agx_g18_msaa4_tile_layout(dev, &batch->tilebuffer_layout)) && store && batch->tilebuffer_layout.nr_samples > 1 && (partial_render || !batch->key.resolve || - (agx_native_graphics(dev) && batch->g17p_resolve_preserve)), + (agx_chip_native_agx3(dev->chip) && batch->g17p_resolve_preserve)), .store_and_resolve = - agx_native_graphics(dev) && store && !partial_render && + agx_chip_native_agx3(dev->chip) && store && !partial_render && batch->tilebuffer_layout.nr_samples > 1 && batch->key.resolve && batch->g17p_resolve_preserve, }; @@ -10209,7 +10210,8 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) if (surf->texture == NULL) continue; - if (agx_native_graphics(dev) && batch->tilebuffer_layout.spilled[rt]) { + if (agx_chip_native_agx3(dev->chip) && + batch->tilebuffer_layout.spilled[rt]) { key.op[rt] = AGX_BG_EOT_NONE; } else if (store) { /* TODO: Suppress stores to discarded render targets */ @@ -10244,7 +10246,7 @@ agx_build_bg_eot(struct agx_batch *batch, bool store, bool partial_render) if (agx_chip_g17_m5(dev->chip)) return agx_build_native_g17g_bg_eot(batch, &key, store, partial_render); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { if (agx_tilebuffer_spills(&key.tib)) { bool active = false; for (unsigned rt = 0; rt < PIPE_MAX_COLOR_BUFS; ++rt) { @@ -10931,7 +10933,7 @@ agx_batch_init_state(struct agx_batch *batch) memcpy(out, records[i].bytes, records[i].length); out += records[i].length; } - } else if (agx_native_graphics(dev)) { + } else if (agx_chip_native_agx3(dev->chip)) { const struct agx_ppp_w_clamp_cull2_fields fields = { .w_clamp_raw = 0, .cull2_raw = UINT32_C(0x80), @@ -11740,7 +11742,7 @@ agx_g17p_emit_bind_state(struct agx_batch *batch, uint8_t *out, struct agx_context *ctx = batch->ctx; struct agx_device *dev = agx_device(ctx->base.screen); struct agx_rasterizer *rast = ctx->rast; - if (!agx_native_graphics(dev) || !draw_state_offset) + if (!agx_chip_native_agx3(dev->chip) || !draw_state_offset) return NULL; /* Gallium does not track the highest initialized viewport. When a shader @@ -13074,7 +13076,7 @@ agx_encode_state(struct agx_batch *batch, uint8_t *out, struct agx_ptr t = agx_pool_alloc_aligned(&batch->pipeline_pool, linkage_size, - agx_native_graphics(dev) ? 64 : 16); + agx_chip_native_agx3(dev->chip) ? 64 : 16); agx_link_varyings_vs_fs(t.cpu, &batch->linked_varyings, vs->uvs.user_size, &ctx->linked.fs->cf, @@ -13085,7 +13087,7 @@ agx_encode_state(struct agx_batch *batch, uint8_t *out, &batch->generate_primitive_id); batch->varyings = - agx_native_graphics(dev) ? t.gpu : agx_usc_addr(dev, t.gpu); + agx_chip_native_agx3(dev->chip) ? t.gpu : agx_usc_addr(dev, t.gpu); } else { batch->varyings = 0; batch->generate_primitive_id = false; @@ -13114,7 +13116,7 @@ agx_encode_state(struct agx_batch *batch, uint8_t *out, ctx->gs ? ctx->linked.gs_copy : ctx->linked.vs, MESA_SHADER_VERTEX, 0, 0, &pipeline, NULL); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { if (agx_drop_for_null_g17p_program(ctx, vs, pipeline, "vertex", NULL)) return NULL; @@ -13172,7 +13174,7 @@ agx_encode_state(struct agx_batch *batch, uint8_t *out, ctx->perf.vs_emits++; } - if (agx_native_graphics(dev)) + if (agx_chip_native_agx3(dev->chip)) return agx_g17p_emit_bind_state(batch, out, vs, draw_state_offset); struct agx_pool *pool = &batch->pool; @@ -13539,7 +13541,7 @@ agx_index_buffer_direct_ptr(struct agx_batch *batch, * odd index (or a u8 draw at index % 4 != 0) reads from the preceding * aligned address. Copy such ranges to an aligned pool upload. */ - if (agx_native_graphics(agx_device(batch->ctx->base.screen)) && + if (agx_chip_native_agx3(agx_device(batch->ctx->base.screen)->chip) && ((base + offset) & 3)) { struct agx_resource *rsrc = agx_resource(info->index.resource); const uint8_t *cpu = (const uint8_t *)agx_bo_map(rsrc->bo) + @@ -13606,7 +13608,7 @@ agx_ensure_cmdbuf_has_space(struct agx_batch *batch, struct agx_encoder *enc, /* Jump from the old command buffer to the new command buffer */ struct agx_device *dev = agx_device(batch->ctx->base.screen); - if (vdm && agx_native_graphics(dev)) { + if (vdm && agx_chip_native_agx3(dev->chip)) { const uint64_t alias = agx_batch_get_g17p_vdm_alias(batch, target_bo, T.gpu); uint32_t compact = 0; @@ -15282,7 +15284,7 @@ agx_draw_patches_split(struct agx_context *ctx, * Anything that varies per sub-draw (draw ID or base parameters in uniforms, * statistics, geometry or tessellation stages, transform feedback, misaligned * indices) keeps the full path. The record written is the HAL200 draw body - * of agx_g17p_emit_draw_body(), which is what every agx_native_graphics() + * of agx_g17p_emit_draw_body(), which is what every agx_chip_native_agx3() * chip encodes; other chips keep util_draw_multi(). */ @@ -15399,7 +15401,7 @@ agx_draw_multi(struct pipe_context *pctx, const struct pipe_draw_info *info, struct agx_context *ctx = agx_context(pctx); struct agx_device *dev = agx_device(pctx->screen); - if (indirect || !agx_native_graphics(dev)) { + if (indirect || !agx_chip_native_agx3(dev->chip)) { util_draw_multi(pctx, info, drawid_offset, indirect, draws, num_draws); return; } @@ -15524,7 +15526,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, const uint64_t index_offset = indirect ? 0 : (uint64_t)draws->start * info->index_size; if (!indirect && info->index_size && !info->has_user_indices && - agx_native_graphics(agx_device(pctx->screen)) && + agx_chip_native_agx3(agx_device(pctx->screen)->chip) && (index_offset & 3)) { const uint64_t bytes = (uint64_t)draws->count * info->index_size; struct pipe_resource *source = info->index.resource; @@ -16071,7 +16073,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, * an empty rasterized output, or too few vertices for one primitive. The * pre-rasterization work is already launched above; a native HAL200 * direct draw cannot encode a zero count, and would draw nothing. */ - if (agx_native_graphics(agx_device(ctx->base.screen)) && !indirect && + if (agx_chip_native_agx3(agx_device(ctx->base.screen)->chip) && !indirect && (!draws->count || !info->instance_count)) return; @@ -16116,7 +16118,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, MAX2(AGX_VDM_INDEX_LIST_DIRECT_INDEXED_MAX_LENGTH, AGX_VDM_INDEX_LIST_INDIRECT_INDEXED_MAX_LENGTH) + AGX_VDM_BARRIER_CORE_LENGTH - : agx_native_graphics(dev) + : agx_chip_native_agx3(dev->chip) ? AGX_VDM_STATE_UPDATE_LENGTH + AGX_VDM_HAL200_BIND_TAIL_LENGTH + AGX_VDM_HAL200_DRAW_STATE_POINTER_LENGTH + AGX_VDM_HAL200_INDEXED_DRAW_BODY_LENGTH + AGX_VDM_BARRIER_LENGTH @@ -16138,7 +16140,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, * dirtying PRIM would also relink varyings and rebuild the VS program. */ const uint64_t skipped_before = ctx->skipped_no_program; uint8_t *out = - agx_native_graphics(dev) && indirect && !ctx->dirty + agx_chip_native_agx3(dev->chip) && indirect && !ctx->dirty ? agx_g17p_emit_bind_state(batch, batch->vdm.current, ctx->gs ? ctx->gs->gs_copy : ctx->vs, &draw_state_offset) @@ -16152,7 +16154,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, return; } - if (!agx_native_graphics(dev) && info->index_size && + if (!agx_chip_native_agx3(dev->chip) && info->index_size && info->primitive_restart) { agx_push(out, VDM_STATE, cfg) cfg.restart_index_present = true; @@ -16181,7 +16183,7 @@ agx_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info, } const enum agx_primitive primitive = agx_primitive_for_pipe(info->mode); - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { out = indirect ? agx_g17p_emit_indirect_draw( dev->chip, out, &draw, primitive, info->restart_index, draw_state_offset) @@ -16475,7 +16477,7 @@ agx_launch(struct agx_batch *batch, struct agx_grid grid, } } - if (agx_native_graphics(dev)) { + if (agx_chip_native_agx3(dev->chip)) { struct agx3_ioto_uniform_range ranges[AGX_MAX_PUSH_RANGES + 2]; size_t range_count = 0; const bool resource_pair = batch->texture_count[stage] != 0; @@ -16752,7 +16754,7 @@ agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) union asahi_shader_key key = { .cs.custom_borders = - agx_native_graphics(agx_device(pipe->screen)) && + agx_chip_native_agx3(agx_device(pipe->screen)->chip) && ctx->stage[MESA_SHADER_COMPUTE].custom_borders, }; /* The variant compiled at link time, or by an earlier dispatch, is in @@ -16766,7 +16768,7 @@ agx_launch_grid(struct pipe_context *pipe, const struct pipe_grid_info *info) uncompiled, &key); struct agx_grid grid; - if (indirect && agx_native_graphics(agx_device(pipe->screen))) { + if (indirect && agx_chip_native_agx3(agx_device(pipe->screen)->chip)) { /* G17P launches an indirect dispatch from a six-word grid -- three * global thread counts then the three local sizes -- so the API's three * workgroup counts are not the record the hardware reads. Expand them diff --git a/src/gallium/drivers/asahi/agx_uniforms.c b/src/gallium/drivers/asahi/agx_uniforms.c index 63aed95aa67c..50c052bf4d77 100644 --- a/src/gallium/drivers/asahi/agx_uniforms.c +++ b/src/gallium/drivers/asahi/agx_uniforms.c @@ -79,7 +79,7 @@ agx_upload_uniforms(struct agx_batch *batch, ? ctx->rast->base.sprite_coord_enable : 0; - if (hw_vs && agx_native_graphics(agx_device(ctx->base.screen))) { + if (hw_vs && agx_chip_native_agx3(agx_device(ctx->base.screen)->chip)) { /* Keep the old immutable upload for unchanged vertex inputs, including * fragment-only root updates. The unconditional native VS update used * to cover root inputs not represented by VS dirty bits. Compare the diff --git a/src/gallium/drivers/asahi/tests/test-agx-vs-query.c b/src/gallium/drivers/asahi/tests/test-agx-vs-query.c index 2c247c8d7dc0..6f8186fe62c7 100644 --- a/src/gallium/drivers/asahi/tests/test-agx-vs-query.c +++ b/src/gallium/drivers/asahi/tests/test-agx-vs-query.c @@ -169,7 +169,7 @@ check_vs(struct pipe_context *pctx) pctx->set_stencil_ref(pctx, ref); draw(pctx); CHECK(ctx->perf.vs_emits == 1 && ctx->batch->vdm.current > before); - if (agx_native_graphics(agx_device(pctx->screen))) { + if (agx_chip_native_agx3(agx_device(pctx->screen)->chip)) { struct agx_vdm_state_update_info update; CHECK(!agx_vdm_state_update_unpack(AGX_CHIP_G17P, before, AGX_VDM_STATE_UPDATE_LENGTH, &update)); From 75b186e77e81584bc9f73de979c16d5f3e12981a Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:37:02 -0300 Subject: [PATCH 12/13] agx: remove agx_native_graphics() Its last callers now call agx_chip_native_agx3(), which it wrapped. A comment in agx_compile.h that named it names the predicate. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216, and the Vulkan and Gallium drivers build. No hardware has run this commit and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/compiler/agx_compile.h | 2 +- src/asahi/lib/agx_device.h | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index ef903c55e4d6..f47b6bd813e4 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -719,7 +719,7 @@ uint64_t agx_gather_texcoords(nir_shader *nir); void agx_preprocess_nir(nir_shader *nir); void agx_preprocess_nir_g17p(nir_shader *nir); -/* For any native AGX3 chip (agx_native_graphics); passes validated on G17P +/* For any native AGX3 chip (agx_chip_native_agx3); passes validated on G17P * alone check chip. */ void agx_preprocess_nir_native(nir_shader *nir, enum agx_chip chip); void agx_preprocess_nir_g18g(nir_shader *nir); diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 6974fddfa0d3..50cbbc74b0b3 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -597,13 +597,6 @@ unsigned agx_get_num_cores(const struct agx_device *dev); struct agx_device_key agx_gather_device_key(struct agx_device *dev); -/* Native AGX3 recording: Ioto programs and HAL200-format records. */ -static inline bool -agx_native_graphics(const struct agx_device *dev) -{ - return agx_chip_native_agx3(dev->chip); -} - /* This interface carries native sampler state in GPU records, not in the * firmware command's optional sampler-heap fields. */ static inline bool From 2a31495fae671c154b78d6cd3107b43b043ec381 Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Fri, 20 Nov 2026 20:55:00 -0300 Subject: [PATCH 13/13] agx: read the Ioto and PPP payload generations from the chip table After the allowlists, one chip list was still typed seven times in lib: G15G, G15S, G15C, G15D, G16G, G16S, G16C and G17P select the GPU0 Ioto encoding in agx_ioto_core.c, agx_ioto_load_core.c, agx_ioto_preshader_core.c, agx_ioto_state_core.c and agx_ioto_program_core.c, and the PPPEncoderGen6 header in the viewport and W-clamp/cull2 payload codecs. The M5 parts select GPU1 five times. The Ioto encoding follows the instruction set generation, as the comment in the preshader codec says, so it becomes a column of the chip table: agx_chip_ioto_generation() is GPU0, GPU1 or none, and each codec maps it to its own enum. G16P, G17A and G18G stay refused. The two PPP payloads get a record bit each, like the other record codecs, and pick the Gen7 header on the HAL300 path and Gen6 otherwise. That is the split they had: G17G, G17S, G17C and G18G are Gen7. tests/test-chip.c gets a row for the Ioto generation and one for the generation each PPP payload codec packs. The two payload rows were printed by the old switches before they were removed. The rows for the encoding the preshader, state and program codecs select pass unedited. No behaviour change is intended for any chip. Tested on J616s (M4 Pro, T6040): the asahi suite passes, 216 of 216, which includes the Ioto load, preshader and program codec tests, and the precompiled libagx kernels are byte-identical to those built from b8762aab9. This is the last commit of the chip table series, and the series was checked as a whole at this commit, against b8762aab9: - Under the no-op DRM shim, for all 17 ASAHI_SHIM_CHIP profiles: vulkaninfo is the same apart from the build UUIDs. 258 dEQP-VK cases per profile (glsl, compute, tessellation, geometry, draw, ubo, ssbo, texture, SPIR-V and others) submit the same kernel command buffers and the same bytes in every mapped BO, 8,047 submits in all. One case differs between two runs of the same build and was compared on its stable lines. An offscreen GLES 3.1 program submits the same bytes on every profile (the compile-only G17G one submits nothing). The registered tests that submit through the shim, base and head built in the same tree, submit the same bytes (17), or the same on every line that is stable between runs (4); hk-g17p-cross-queue times out under the shim on both and is not comparable. - On hardware, J616s only (G17P): 37,339 dEQP-VK compute, SSBO and GLSL cases give the results stored for aurora-wip fa9a6766c, with no GPU recovery, and the offscreen GLES program renders the same pixels as on b8762aab9. Before the rebase, 24,262 passing pipeline, shader object, transform feedback, tessellation, clipping and geometry cases also gave the results stored for aurora-wip 45963937b. This version of the series has run on J616s only: G13, G14, G15, G16G, the M5 parts and G18G are covered by the shim comparison and the unit tests, and no other machine has built it. Signed-off-by: Jonathan Goyvaerts --- src/asahi/lib/agx_chip.h | 81 ++++++++++++------- src/asahi/lib/agx_ioto_core.c | 15 +--- src/asahi/lib/agx_ioto_load_core.c | 15 +--- src/asahi/lib/agx_ioto_preshader_core.c | 17 +--- src/asahi/lib/agx_ioto_program_core.c | 14 +--- src/asahi/lib/agx_ioto_state_core.c | 15 +--- src/asahi/lib/agx_ppp_viewport_payload_core.c | 30 ++----- src/asahi/lib/agx_ppp_w_clamp_cull2_core.c | 26 ++---- src/asahi/lib/tests/test-chip.c | 38 +++++++++ 9 files changed, 116 insertions(+), 135 deletions(-) diff --git a/src/asahi/lib/agx_chip.h b/src/asahi/lib/agx_chip.h index 3aedd7d9122a..62a16ec396d7 100644 --- a/src/asahi/lib/agx_chip.h +++ b/src/asahi/lib/agx_chip.h @@ -116,6 +116,15 @@ enum agx_sampler_generation { AGX_SAMPLER_GENERATION_UNKNOWN, }; +/* The encoding of Ioto programs and their load, state, preshader and profile + * records. It follows the instruction set: GPU0 for the AGX3b parts whose + * programs are witnessed, GPU1 for the M5 parts. NONE refuses them. */ +enum agx_ioto_generation { + AGX_IOTO_GENERATION_NONE, + AGX_IOTO_GENERATION_GPU0, + AGX_IOTO_GENERATION_GPU1, +}; + /* M4 Pro/Max and A18 Pro carry both queueing paths; M5 and M6 are * SKSM-only. */ enum agx_submission_model { @@ -165,6 +174,8 @@ enum agx_chip_record { AGX_RECORD_IOTO_PROFILE_CONTROL = 1 << 19, /* agx_chip_hal300_records */ AGX_RECORD_HAL300_NATIVE_CAPTURE = 1 << 20, + AGX_RECORD_PPP_VIEWPORT = 1 << 21, + AGX_RECORD_PPP_W_CLAMP_CULL2 = 1 << 22, }; /* The records of every byte-witnessed G15, G16 and G17 identity. */ @@ -172,6 +183,7 @@ enum agx_chip_record { (AGX_RECORD_VDM_STATE | AGX_RECORD_VDM_PPP_STATE | AGX_RECORD_VDM_BARRIER | \ AGX_RECORD_VDM_STREAM_LINK | AGX_RECORD_VDM_STREAM_TERMINATE | \ AGX_RECORD_VDM_TESSELLATE | AGX_RECORD_VDM_INDEX_LIST | \ + AGX_RECORD_PPP_VIEWPORT | AGX_RECORD_PPP_W_CLAMP_CULL2 | \ AGX_RECORD_CDM_LAUNCH | AGX_RECORD_CDM_INDIRECT_LAUNCH | \ AGX_RECORD_CDM_INDIRECT_LAUNCH_36 | AGX_RECORD_CDM_STREAM_LINK | \ AGX_RECORD_CDM_LINK_PADDING | AGX_RECORD_CDM_BARRIER | \ @@ -189,7 +201,8 @@ enum agx_chip_record { * before this table (see each codec). */ #define AGX_RECORDS_G18G \ (AGX_RECORD_VDM_STATE | AGX_RECORD_VDM_PPP_STATE | AGX_RECORD_VDM_BARRIER | \ - AGX_RECORD_VDM_STREAM_TERMINATE | AGX_RECORD_PPP_HAL300_DEPTH_STENCIL | \ + AGX_RECORD_VDM_STREAM_TERMINATE | AGX_RECORD_PPP_VIEWPORT | \ + AGX_RECORD_PPP_W_CLAMP_CULL2 | AGX_RECORD_PPP_HAL300_DEPTH_STENCIL | \ AGX_RECORD_PPP_HAL300_DEPTH_BIAS_SCISSOR | AGX_RECORD_CDM_LAUNCH | \ AGX_RECORD_CDM_INDIRECT_LAUNCH | AGX_RECORD_CDM_INDIRECT_LAUNCH_36 | \ AGX_RECORD_CDM_BARRIER | AGX_RECORD_HAL300_NATIVE_CAPTURE) @@ -234,8 +247,8 @@ enum agx_chip_quirk { * cannot disagree, and every predicate below reads a field of the row. * * Columns: chip, instruction set, binary encoding, command-stream generation, - * descriptor generation, sampler generation, submission model, path, - * witnessed records, quirks. + * descriptor generation, sampler generation, Ioto generation, submission + * model, path, witnessed records, quirks. * * AGX2: `G` is a single-cluster part, `X` is multi-cluster. * @@ -277,47 +290,47 @@ enum agx_chip_quirk { * submission model is unknown. */ #define AGX_CHIPS(X, ...) \ - X(G13G, AGX2, AGX2, AGX2, 7, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ - X(G13X, AGX2, AGX2, AGX2, 7, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ - X(G14G, AGX2, AGX2, AGX2, 8, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ - X(G14X, AGX2, AGX2, AGX2, 8, GEN4, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ - X(G15P, AGX2, AGX2, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, NONE, 0, 0, \ + X(G13G, AGX2, AGX2, AGX2, 7, GEN4, NONE, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G13X, AGX2, AGX2, AGX2, 7, GEN4, NONE, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G14G, AGX2, AGX2, AGX2, 8, GEN4, NONE, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G14X, AGX2, AGX2, AGX2, 8, GEN4, NONE, CLASSIC, AGX2, 0, 0, __VA_ARGS__) \ + X(G15P, AGX2, AGX2, UNKNOWN, UNKNOWN, UNKNOWN, NONE, UNKNOWN, NONE, 0, 0, \ __VA_ARGS__) \ - X(G15G, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + X(G15G, AGX3, AGX3B, G15, 9, GEN4, GPU0, CLASSIC, NATIVE_AGX3, \ AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ AGX_QUIRKS_NATIVE_PRE_G17 | AGX_QUIRK_SCHEDULING_STALLS, __VA_ARGS__) \ - X(G15S, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + X(G15S, AGX3, AGX3B, G15, 9, GEN4, GPU0, CLASSIC, NATIVE_AGX3, \ AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ AGX_QUIRKS_NATIVE_PRE_G17, __VA_ARGS__) \ - X(G15C, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NATIVE_AGX3, \ + X(G15C, AGX3, AGX3B, G15, 9, GEN4, GPU0, CLASSIC, NATIVE_AGX3, \ AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ AGX_QUIRKS_NATIVE_PRE_G17 | AGX_QUIRK_USC_BASE_PAGE_FILL_RETURNS, \ __VA_ARGS__) \ - X(G15D, AGX3, AGX3B, G15, 9, GEN4, CLASSIC, NONE, AGX_RECORDS_G15_G17, 0, \ - __VA_ARGS__) \ - X(G16P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, UNKNOWN, NONE, 0, 0, \ + X(G15D, AGX3, AGX3B, G15, 9, GEN4, GPU0, CLASSIC, NONE, \ + AGX_RECORDS_G15_G17, 0, __VA_ARGS__) \ + X(G16P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, NONE, UNKNOWN, NONE, 0, 0, \ __VA_ARGS__) \ - X(G16G, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, CLASSIC, NATIVE_AGX3, \ + X(G16G, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, GPU0, CLASSIC, NATIVE_AGX3, \ AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_WIDE_VISIBILITY, \ AGX_QUIRKS_NATIVE_PRE_G17, __VA_ARGS__) \ - X(G16S, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NONE, \ + X(G16S, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, GPU0, DUAL, NONE, \ AGX_RECORDS_G15_G17, 0, __VA_ARGS__) \ - X(G16C, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NONE, \ + X(G16C, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, GPU0, DUAL, NONE, \ AGX_RECORDS_G15_G17, 0, __VA_ARGS__) \ - X(G17P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, DUAL, NATIVE_AGX3, \ + X(G17P, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, GPU0, DUAL, NATIVE_AGX3, \ AGX_RECORDS_G15_G17 | AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY, \ AGX_QUIRKS_G17P, __VA_ARGS__) \ - X(G17A, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, UNKNOWN, NONE, 0, 0, \ + X(G17A, AGX3, AGX3B, HAL200, 9, GEN4_HAL200, NONE, UNKNOWN, NONE, 0, 0, \ __VA_ARGS__) \ - X(G17G, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, \ + X(G17G, AGX3, AGX3C, HAL300, 10, GEN5, GPU1, SKSM, HAL300, \ AGX_RECORDS_M5 | AGX_RECORD_HAL300_NATIVE_CAPTURE, AGX_QUIRK_M5_PATHS, \ __VA_ARGS__) \ - X(G17S, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_M5, 0, \ - __VA_ARGS__) \ - X(G17C, AGX3, AGX3C, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_M5, 0, \ - __VA_ARGS__) \ - X(G18G, AGX3, AGX3D, HAL300, 10, GEN5, SKSM, HAL300, AGX_RECORDS_G18G, \ - AGX_QUIRK_M5_PATHS, __VA_ARGS__) + X(G17S, AGX3, AGX3C, HAL300, 10, GEN5, GPU1, SKSM, HAL300, AGX_RECORDS_M5, \ + 0, __VA_ARGS__) \ + X(G17C, AGX3, AGX3C, HAL300, 10, GEN5, GPU1, SKSM, HAL300, AGX_RECORDS_M5, \ + 0, __VA_ARGS__) \ + X(G18G, AGX3, AGX3D, HAL300, 10, GEN5, NONE, SKSM, HAL300, \ + AGX_RECORDS_G18G, AGX_QUIRK_M5_PATHS, __VA_ARGS__) enum agx_chip { #define AGX_CHIP_ENUM(chip, ...) AGX_CHIP_##chip, @@ -334,6 +347,7 @@ struct agx_chip_info { enum agx_command_stream_generation cs_generation; enum agx_descriptor_generation descriptor_generation; enum agx_sampler_generation sampler_generation; + enum agx_ioto_generation ioto_generation; enum agx_submission_model submission_model; enum agx_chip_path path; /* Mask of enum agx_chip_record. */ @@ -347,7 +361,7 @@ struct agx_chip_info { /* Initialised by position: the C++ translation units that include this * header reject array and field designators. */ static const struct agx_chip_info agx_chip_infos[AGX_CHIP_UNKNOWN + 1] = { -#define AGX_CHIP_INFO(chip, isa, encoding, cs, descriptor, sampler, \ +#define AGX_CHIP_INFO(chip, isa, encoding, cs, descriptor, sampler, ioto, \ submission, path, records, quirks, ...) \ {#chip, \ AGX_ISA_##isa, \ @@ -355,6 +369,7 @@ static const struct agx_chip_info agx_chip_infos[AGX_CHIP_UNKNOWN + 1] = { AGX_CS_GENERATION_##cs, \ AGX_DESCRIPTOR_GENERATION_##descriptor, \ AGX_SAMPLER_GENERATION_##sampler, \ + AGX_IOTO_GENERATION_##ioto, \ AGX_SUBMISSION_MODEL_##submission, \ AGX_CHIP_PATH_##path, \ records, \ @@ -363,8 +378,8 @@ static const struct agx_chip_info agx_chip_infos[AGX_CHIP_UNKNOWN + 1] = { #undef AGX_CHIP_INFO {"unknown", AGX_ISA_UNKNOWN, AGX_ISA_ENCODING_UNKNOWN, AGX_CS_GENERATION_UNKNOWN, AGX_DESCRIPTOR_GENERATION_UNKNOWN, - AGX_SAMPLER_GENERATION_UNKNOWN, AGX_SUBMISSION_MODEL_UNKNOWN, - AGX_CHIP_PATH_NONE, 0, 0}, + AGX_SAMPLER_GENERATION_UNKNOWN, AGX_IOTO_GENERATION_NONE, + AGX_SUBMISSION_MODEL_UNKNOWN, AGX_CHIP_PATH_NONE, 0, 0}, }; /* The row of a chip. AGX_CHIP_UNKNOWN and any value outside the enum get the @@ -391,7 +406,7 @@ agx_chip_info(enum agx_chip chip) * AGX_CHIPS(AGX_CHIP_ROW_TEST, chip, TEST, arg) is that expansion for the * rows that pass TEST(path, records, arg). */ -#define AGX_CHIP_ROW_TEST(row, isa, encoding, cs, descriptor, sampler, \ +#define AGX_CHIP_ROW_TEST(row, isa, encoding, cs, descriptor, sampler, ioto, \ submission, path, records, quirks, chip, TEST, arg) \ | (((chip) == AGX_CHIP_##row) & TEST(AGX_CHIP_PATH_##path, records, arg)) #define AGX_CHIP_ROW_HAS_RECORD(path, records, record) \ @@ -717,6 +732,12 @@ agx_chip_sampler_heap_element_size(enum agx_chip chip) } } +static inline enum agx_ioto_generation +agx_chip_ioto_generation(enum agx_chip chip) +{ + return agx_chip_info(chip)->ioto_generation; +} + static inline enum agx_submission_model agx_chip_submission_model(enum agx_chip chip) { diff --git a/src/asahi/lib/agx_ioto_core.c b/src/asahi/lib/agx_ioto_core.c index f070151412ef..01b7034e6915 100644 --- a/src/asahi/lib/agx_ioto_core.c +++ b/src/asahi/lib/agx_ioto_core.c @@ -197,19 +197,10 @@ static const struct agx_ioto_form agx_ioto_gpu1_forms[] = { static enum agx_ioto_encoding agx_ioto_target_encoding(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: + switch (agx_chip_ioto_generation(chip)) { + case AGX_IOTO_GENERATION_GPU0: return AGX_IOTO_ENCODING_GPU0; - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: + case AGX_IOTO_GENERATION_GPU1: return AGX_IOTO_ENCODING_GPU1; default: return AGX_IOTO_ENCODING_UNSUPPORTED; diff --git a/src/asahi/lib/agx_ioto_load_core.c b/src/asahi/lib/agx_ioto_load_core.c index 23d51244cdb5..d4a1135a6ecb 100644 --- a/src/asahi/lib/agx_ioto_load_core.c +++ b/src/asahi/lib/agx_ioto_load_core.c @@ -59,19 +59,10 @@ store_u16(uint8_t *bytes, uint16_t value) enum agx_ioto_load_encoding agx_ioto_load_target_encoding(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: + switch (agx_chip_ioto_generation(chip)) { + case AGX_IOTO_GENERATION_GPU0: return AGX_IOTO_LOAD_ENCODING_GPU0; - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: + case AGX_IOTO_GENERATION_GPU1: return AGX_IOTO_LOAD_ENCODING_GPU1; default: return AGX_IOTO_LOAD_ENCODING_UNSUPPORTED; diff --git a/src/asahi/lib/agx_ioto_preshader_core.c b/src/asahi/lib/agx_ioto_preshader_core.c index ba4a83b39fe8..f2b9b532d415 100644 --- a/src/asahi/lib/agx_ioto_preshader_core.c +++ b/src/asahi/lib/agx_ioto_preshader_core.c @@ -22,22 +22,11 @@ agx_ioto_preshader_target_encoding(enum agx_chip chip) * not rediscover it through two decoder table walks for every graphics * launcher branch. The exhaustive preshader tests still validate every * listed chip's result through the independent record decoder. */ - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: + switch (agx_chip_ioto_generation(chip)) { + case AGX_IOTO_GENERATION_GPU0: return AGX_IOTO_PRESHADER_ENCODING_GPU0; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: + case AGX_IOTO_GENERATION_GPU1: return AGX_IOTO_PRESHADER_ENCODING_GPU1; - default: return AGX_IOTO_PRESHADER_ENCODING_UNSUPPORTED; } diff --git a/src/asahi/lib/agx_ioto_program_core.c b/src/asahi/lib/agx_ioto_program_core.c index 9634ea2dbd1a..ff405cabb673 100644 --- a/src/asahi/lib/agx_ioto_program_core.c +++ b/src/asahi/lib/agx_ioto_program_core.c @@ -200,19 +200,7 @@ static const uint8_t g17s_minimal_compute_copies[] = { static bool agx_ioto_program_target_gpu0(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - return true; - default: - return false; - } + return agx_chip_ioto_generation(chip) == AGX_IOTO_GENERATION_GPU0; } /* GPU0 EslBuilder appends the AGX3b LDDEV instruction directly rather than diff --git a/src/asahi/lib/agx_ioto_state_core.c b/src/asahi/lib/agx_ioto_state_core.c index 279b15032438..af52c2808975 100644 --- a/src/asahi/lib/agx_ioto_state_core.c +++ b/src/asahi/lib/agx_ioto_state_core.c @@ -24,19 +24,10 @@ static const uint8_t agx_ioto_e4[4] = {2, 0, 1, 3}; static enum agx_ioto_state_encoding agx_ioto_state_target_encoding(enum agx_chip chip) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: + switch (agx_chip_ioto_generation(chip)) { + case AGX_IOTO_GENERATION_GPU0: return AGX_IOTO_STATE_ENCODING_GPU0; - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: + case AGX_IOTO_GENERATION_GPU1: return AGX_IOTO_STATE_ENCODING_GPU1; default: return AGX_IOTO_STATE_ENCODING_UNSUPPORTED; diff --git a/src/asahi/lib/agx_ppp_viewport_payload_core.c b/src/asahi/lib/agx_ppp_viewport_payload_core.c index 697875d5ad54..e8c5710ca216 100644 --- a/src/asahi/lib/agx_ppp_viewport_payload_core.c +++ b/src/asahi/lib/agx_ppp_viewport_payload_core.c @@ -12,32 +12,18 @@ static bool agx_ppp_viewport_header_layout(enum agx_chip chip, uint32_t *base_header, unsigned *count_shift) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - *base_header = AGX_PPP_VIEWPORT_PAYLOAD_GEN6_BASE_HEADER; - *count_shift = 12; - return true; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - *base_header = AGX_PPP_VIEWPORT_PAYLOAD_GEN7_BASE_HEADER; - *count_shift = 14; - return true; - - default: + if (!agx_chip_has_record(chip, AGX_RECORD_PPP_VIEWPORT)) { *base_header = 0; *count_shift = 0; return false; } + + /* PPPEncoderGen7 on the HAL300 path, PPPEncoderGen6 before it. */ + const bool gen7 = agx_chip_hal300_path(chip); + *base_header = gen7 ? AGX_PPP_VIEWPORT_PAYLOAD_GEN7_BASE_HEADER + : AGX_PPP_VIEWPORT_PAYLOAD_GEN6_BASE_HEADER; + *count_shift = gen7 ? 14 : 12; + return true; } /* diff --git a/src/asahi/lib/agx_ppp_w_clamp_cull2_core.c b/src/asahi/lib/agx_ppp_w_clamp_cull2_core.c index 385ae735021a..cd102804af97 100644 --- a/src/asahi/lib/agx_ppp_w_clamp_cull2_core.c +++ b/src/asahi/lib/agx_ppp_w_clamp_cull2_core.c @@ -11,29 +11,15 @@ static bool agx_ppp_w_clamp_cull2_header(enum agx_chip chip, uint32_t *header) { - switch (chip) { - case AGX_CHIP_G15G: - case AGX_CHIP_G15S: - case AGX_CHIP_G15C: - case AGX_CHIP_G15D: - case AGX_CHIP_G16G: - case AGX_CHIP_G16S: - case AGX_CHIP_G16C: - case AGX_CHIP_G17P: - *header = AGX_PPP_W_CLAMP_CULL2_GEN6_HEADER; - return true; - - case AGX_CHIP_G17G: - case AGX_CHIP_G17S: - case AGX_CHIP_G17C: - case AGX_CHIP_G18G: - *header = AGX_PPP_W_CLAMP_CULL2_GEN7_HEADER; - return true; - - default: + if (!agx_chip_has_record(chip, AGX_RECORD_PPP_W_CLAMP_CULL2)) { *header = 0; return false; } + + /* PPPEncoderGen7 on the HAL300 path, PPPEncoderGen6 before it. */ + *header = agx_chip_hal300_path(chip) ? AGX_PPP_W_CLAMP_CULL2_GEN7_HEADER + : AGX_PPP_W_CLAMP_CULL2_GEN6_HEADER; + return true; } bool diff --git a/src/asahi/lib/tests/test-chip.c b/src/asahi/lib/tests/test-chip.c index ef8b4dab8f22..66da8677d438 100644 --- a/src/asahi/lib/tests/test-chip.c +++ b/src/asahi/lib/tests/test-chip.c @@ -24,6 +24,7 @@ #include "agx_ppp_hal300_depth_bias_scissor_core.h" #include "agx_ppp_hal300_depth_stencil_core.h" #include "agx_ppp_viewport_payload_core.h" +#include "agx_ppp_w_clamp_cull2_core.h" #include "agx_vdm_barrier_core.h" #include "agx_vdm_index_list_core.h" #include "agx_vdm_ppp_state_core.h" @@ -189,6 +190,8 @@ static unsigned checks; "0000 00000 0000 00111 1 0") \ ROW(agx_ppp_viewport_payload_core_supported(c), \ "0000 01111 0111 10111 1 0") \ + ROW(viewport_payload_generation(c), "0000 06666 0666 60777 7 0") \ + ROW(w_clamp_cull2_generation(c), "0000 06666 0666 60777 7 0") \ /* Per-record allowlists: CDM. */ \ ROW(agx3_cdm_launch_target_grounded(c), "0000 01111 0111 10111 1 0") \ ROW(agx3_cdm_direct_launch_target_grounded(c), "0000 01111 0111 10111 1 0") \ @@ -216,6 +219,7 @@ static unsigned checks; ROW(agx3_native_indirect_compute_dispatch_size(c) / 4, \ "iiii ijjji iiii iiiii i i") \ /* Per-record allowlists: Ioto. */ \ + ROW(agx_chip_ioto_generation(c), "0000 01111 0111 10222 0 0") \ ROW(agx_ioto_target_supported(c), "0000 01111 0111 10111 0 0") \ ROW(agx_ioto_load_target_encoding(c), "0000 01111 0111 10222 0 0") \ ROW(agx_ioto_profile_control_supported(c), "0000 01111 0111 10111 0 0") \ @@ -284,6 +288,40 @@ shader_binary_version_class(enum agx_chip chip) } } +/* The PPP encoder generation a payload codec packs for a chip: 6 or 7, or 0 + * when it refuses the chip. */ +static unsigned +viewport_payload_generation(enum agx_chip chip) +{ + const struct agx_ppp_viewport_payload_fields fields = {.viewport_count = 1}; + struct agx_ppp_viewport_payload_core out; + uint32_t header; + + if (!agx_ppp_viewport_payload_core_pack(chip, &fields, &out)) + return 0; + + memcpy(&header, out.bytes, sizeof(header)); + return header == AGX_PPP_VIEWPORT_PAYLOAD_GEN6_BASE_HEADER ? 6 + : header == AGX_PPP_VIEWPORT_PAYLOAD_GEN7_BASE_HEADER ? 7 + : 9; +} + +static unsigned +w_clamp_cull2_generation(enum agx_chip chip) +{ + const struct agx_ppp_w_clamp_cull2_fields fields = {0}; + struct agx_ppp_w_clamp_cull2_core out; + uint32_t header; + + if (!agx_ppp_w_clamp_cull2_core_pack(chip, &fields, &out)) + return 0; + + memcpy(&header, out.bytes, sizeof(header)); + return header == AGX_PPP_W_CLAMP_CULL2_GEN6_HEADER ? 6 + : header == AGX_PPP_W_CLAMP_CULL2_GEN7_HEADER ? 7 + : 9; +} + static const char *const chip_names[AGX_CHIP_UNKNOWN + 1] = { "G13G", "G13X", "G14G", "G14X", "G15P", "G15G", "G15S", "G15C", "G15D", "G16P", "G16G", "G16S", "G16C", "G17P",