Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/asahi/compiler/agx3_graphics_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ struct agx3_g17p_graphics_program_desc {
const struct agx3_cprog_inputs *cprog_inputs;

const struct agx_ioto_preshader_desc *preshader;

/* M5: the cluster count the USC window's code-container lead was built
* for, the kernel's num_clusters_total (agx3_build_m5_container_lead()).
* The program's profile loader points at that lead's helper-table group
* (agx3_m5_container_group_offset()); an M5 program is refused without
* it. Other paths ignore it. */
unsigned usc_clusters;
};

struct agx3_g17p_graphics_program {
Expand Down Expand Up @@ -145,6 +152,14 @@ bool agx3_g18g_tile_program_generate(
const struct agx3_g17p_graphics_program_desc *desc, bool store,
struct agx3_g17p_graphics_program *program);

/* G18G general HAL300 tile shaders (any admitted M5 imageblock shape), emitted
* as single-cluster G17G canonical GPU1 so agx3_transcode_agx3d_ioto() doubles
* the SR14 helper base from 0x100 to the witnessed G18G 0x200 base regardless
* of the host device's cluster count. */
bool agx3_g18g_general_tile_program_generate(
const struct agx3_g17p_graphics_program_desc *desc, bool store,
struct agx3_g17p_graphics_program *program);

struct agx3_g17p_graphics_program_template {
struct agx3_g17p_graphics_program program;
struct agx_ioto_load_relocation
Expand Down
15 changes: 14 additions & 1 deletion src/asahi/compiler/agx3_m5_graphics_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ g17g_graphics_program_generate(
if (!agx3_ioto_uniform_program_body_generate(
chip, &load_desc, workspace, &body_size, &copy_offset) ||
!agx_ioto_m5_resource_program_compose_classes(
chip, desc->program_va, body, body_size, &tail,
chip, desc->usc_clusters, desc->program_va, body, body_size, &tail,
stage, MAX2(desc->colour_classes, 1),
staged.bytes, sizeof(staged.bytes), &written) ||
written > bound || written > UINT16_MAX)
Expand Down Expand Up @@ -306,6 +306,19 @@ agx3_g17g_tile_program_generate(
: AGX_IOTO_G17G_PROGRAM_BACKGROUND, program, NULL);
}

bool
agx3_g18g_general_tile_program_generate(
const struct agx3_g17p_graphics_program_desc *desc, bool store,
struct agx3_g17p_graphics_program *program)
{
if (!desc)
return false;
struct agx3_g17p_graphics_program_desc g18_desc = *desc;
g18_desc.usc_clusters = 1;
return agx3_g17g_tile_program_generate(AGX_CHIP_G17G, &g18_desc, store,
program);
}

bool
agx3_g17g_graphics_program_template_generate(
enum agx_chip chip, const struct agx3_g17p_graphics_program_desc *desc,
Expand Down
2 changes: 1 addition & 1 deletion src/asahi/compiler/agx3_pack_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,7 @@ agx3_emit_storage_image_write(struct util_dynarray *emission,
* Gallium does on G17C) need it: their layer count does not shrink with
* the selected mip level, unlike 3D depth.
*/
const bool layer_operand = !m5 || chip == AGX_CHIP_G17C;
const bool layer_operand = !m5 || agx_chip_m5_layer_operand(chip);
const bool array = I->dim == AGX_DIM_2D_ARRAY && layer_operand;
const bool three_d = I->dim == AGX_DIM_3D ||
(!layer_operand && I->dim == AGX_DIM_2D_ARRAY);
Expand Down
30 changes: 20 additions & 10 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -20448,23 +20448,33 @@ agx_compile_shader_nir_preoptimized(nir_shader *nir, struct agx_shader_key *key,
preamble_newly_enabled, 4, NULL);
}

/* The M5 helpers serve G17G, G17S and G17C, which share one row of the
* capability table. */
#define AGX_M5_SIGNED_ZERO_SELECT \
((AGX_CAPS_M5 & AGX_CAP_SIGNED_ZERO_MINMAX_SELECT) != 0)
void
agx_preprocess_nir_m5_chip(nir_shader *nir, enum agx_chip chip)
{
agx_preprocess_nir_internal(
nir, false, true, false, true,
agx_chip_has_cap(chip, AGX_CAP_SIGNED_ZERO_MINMAX_SELECT), true, false,
false, false);
}

void
agx_preprocess_nir_m5_defer_idiv_chip(nir_shader *nir, enum agx_chip chip)
{
agx_preprocess_nir_internal(
nir, false, true, false, true,
agx_chip_has_cap(chip, AGX_CAP_SIGNED_ZERO_MINMAX_SELECT), true, false,
true, false);
}

/* Single-die M5 convenience entry points (for callers without a device). */
void
agx_preprocess_nir_m5(nir_shader *nir)
{
agx_preprocess_nir_internal(nir, false, true, false, true,
AGX_M5_SIGNED_ZERO_SELECT, true, false, false,
false);
agx_preprocess_nir_m5_chip(nir, AGX_CHIP_G17G);
}

void
agx_preprocess_nir_m5_defer_idiv(nir_shader *nir)
{
agx_preprocess_nir_internal(nir, false, true, false, true,
AGX_M5_SIGNED_ZERO_SELECT, true, false, true,
false);
agx_preprocess_nir_m5_defer_idiv_chip(nir, AGX_CHIP_G17G);
}
5 changes: 5 additions & 0 deletions src/asahi/compiler/agx_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,13 @@ void agx_preprocess_nir_post_lower(nir_shader *nir, enum agx_chip chip);
/* Access private (scratch) memory in whole 32-bit words, the only width the
* AGX3 stack protocol encodes. agx_preprocess_nir_g17p() runs it. */
bool agx3_nir_lower_scratch_words(nir_shader *nir);
/* Single-die M5 (G17G) convenience entry points for unit tests without a
* device; runtime callers must use the _chip variants below. */
void agx_preprocess_nir_m5(nir_shader *nir);
void agx_preprocess_nir_m5_defer_idiv(nir_shader *nir);
/* For any M5 chip (agx_chip_g17_m5); per-chip capabilities check chip. */
void agx_preprocess_nir_m5_chip(nir_shader *nir, enum agx_chip chip);
void agx_preprocess_nir_m5_defer_idiv_chip(nir_shader *nir, enum agx_chip chip);
bool agx_nir_lower_discard_zs_emit(nir_shader *s);
bool agx_nir_lower_sample_mask(nir_shader *s);
/* TARGET/LIVE retain their normal semantics. This flag records the proof that
Expand Down
4 changes: 2 additions & 2 deletions src/asahi/compiler/test/test-agx3-graphics-program.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ main(void)
CHECK(!agx3_g17p_fragment_blend_constant_base(AGX_CHIP_G17P, 505,
&blend_base));
CHECK(blend_base == valid_blend_base);
/* The M5 parts (G17G, G17S, G17C) take the same placement; a pre-AGX3
/* The M5 parts (G17G, G17S, G17C, G17D) take the same placement; a pre-AGX3
* chip is refused and leaves the output alone. */
for (enum agx_chip m5 = AGX_CHIP_G17G; m5 <= AGX_CHIP_G17C;
for (enum agx_chip m5 = AGX_CHIP_G17G; m5 <= AGX_CHIP_G17D;
m5 = (enum agx_chip)(m5 + 1)) {
uint16_t m5_base = UINT16_C(0xa5a5);
CHECK(agx3_g17p_fragment_blend_constant_base(m5, 16, &m5_base));
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/test/test-agx3-ioto-load-packer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const enum agx_chip gpu1_targets[] = {
AGX_CHIP_G17G,
AGX_CHIP_G17S,
AGX_CHIP_G17C,
AGX_CHIP_G17D,
};

struct fixture {
Expand Down
6 changes: 4 additions & 2 deletions src/asahi/compiler/test/test-agx3-ioto-uniform-program.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static const enum agx_chip gpu1_targets[] = {
AGX_CHIP_G17G,
AGX_CHIP_G17S,
AGX_CHIP_G17C,
AGX_CHIP_G17D,
};

struct fixture {
Expand All @@ -44,7 +45,8 @@ static bool
is_gpu1(enum agx_chip chip)
{
return chip == AGX_CHIP_G17G || chip == AGX_CHIP_G17S ||
chip == AGX_CHIP_G17C;
chip == AGX_CHIP_G17C ||
chip == AGX_CHIP_G17D;
}

static struct agx3_ioto_uniform_program_workspace
Expand Down Expand Up @@ -111,7 +113,7 @@ test_exact_uniform_program(void)
const enum agx_chip targets[] = {
AGX_CHIP_G15G, AGX_CHIP_G15S, AGX_CHIP_G15C, AGX_CHIP_G15D,
AGX_CHIP_G16G, AGX_CHIP_G16S, AGX_CHIP_G16C, AGX_CHIP_G17P,
AGX_CHIP_G17G, AGX_CHIP_G17S, AGX_CHIP_G17C,
AGX_CHIP_G17G, AGX_CHIP_G17S, AGX_CHIP_G17C, AGX_CHIP_G17D,
};
for (size_t i = 0; i < ARRAY_SIZE(targets); ++i) {
const enum agx_chip chip = targets[i];
Expand Down
71 changes: 64 additions & 7 deletions src/asahi/compiler/test/test-agx3-m5-program.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "asahi/lib/agx_ioto_preshader_core.h"
#include "asahi/lib/agx_ppp_hal300_graphics_core.h"
#include "asahi/lib/agx3_compute_program_core.h"
#include "asahi/lib/agx3_code_container_core.h"
#include "asahi/lib/agx_bytes.h"
#include "asahi/lib/agx_ioto_load_core.h"
#include "util/macros.h"

#include <stdio.h>
Expand All @@ -24,6 +27,35 @@
} \
} while (0)

/* The cluster count each M5 part's kernel reports (its contract in
* agx_params_m5_supported()), which the USC window's lead is built for. */
static unsigned
m5_clusters(enum agx_chip chip)
{
switch (chip) {
case AGX_CHIP_G17S: return 2;
case AGX_CHIP_G17C: return 4;
case AGX_CHIP_G17D: return 8;
default: return 1;
}
}

/* Whether the profile loader at `loader` loads the offset of the lead's
* helper-table group for this cluster count, through the LDIMM's immediate.
* For one and two clusters that is the template's raw byte at +20 as well
* (4, 8 and 16 for 0x100, 0x200 and 0x400). */
static bool
loader_points_at_group(const uint8_t *loader, unsigned clusters, bool vertex)
{
const uint32_t group = agx3_m5_container_group_offset(clusters, vertex);
const uint64_t field = agx_ioto_load_ldimm_long_immediate(UINT32_MAX);

return group &&
(agx_load_le64(loader + 16) & field) ==
agx_ioto_load_ldimm_long_immediate(group) &&
(clusters > 2 || loader[20] == group >> 6);
}

static int
test_g17g_programs(enum agx_chip chip)
{
Expand All @@ -47,6 +79,7 @@ test_g17g_programs(enum agx_chip chip)
.compiler_d = fragment ? 0 : 32,
.fragment = fragment,
.imageblock = { .sample_size_B = 8, .nr_samples = 1, .tile_size_px = 1024 },
.usc_clusters = m5_clusters(chip),
};
struct agx3_g17p_graphics_program output;
size_t empty_bound;
Expand All @@ -57,8 +90,15 @@ test_g17g_programs(enum agx_chip chip)
&output));
CHECK(output.length == (fragment ? 90 : 84));
CHECK(memcmp(output.bytes, expected_tail[fragment], 28) == 0);
CHECK(output.bytes[48] == (fragment ? 4 : 8) *
((chip == AGX_CHIP_G17S || chip == AGX_CHIP_G17C) ? 2 : 1));
CHECK(loader_points_at_group(output.bytes + 28, m5_clusters(chip),
!fragment));
{
/* Without the cluster count the program is refused. */
struct agx3_g17p_graphics_program_desc no_clusters = desc;
no_clusters.usc_clusters = 0;
CHECK(!agx3_g17g_graphics_program_generate(chip, &no_clusters,
&output));
}


{
Expand Down Expand Up @@ -227,8 +267,8 @@ test_g17g_programs(enum agx_chip chip)
CHECK(output.length == 84);
CHECK(!memcmp(output.bytes, expected_tail[0], 8));
CHECK(!memcmp(output.bytes + 8, expected_tail[1] + 8, 20));
CHECK(output.bytes[28 + 20] ==
((chip == AGX_CHIP_G17S || chip == AGX_CHIP_G17C) ? 8 : 4));
CHECK(loader_points_at_group(output.bytes + 28, m5_clusters(chip),
false));
static const uint8_t end[] = {14, 0, 0, 0};
CHECK(!memcmp(output.bytes + 80, end, sizeof(end)));

Expand Down Expand Up @@ -285,21 +325,31 @@ test_g17g_programs(enum agx_chip chip)
static int
test_m5_dispatch(enum agx_chip chip)
{
/* A device of two dies scopes every ordering record
* (agx_cdm_ordering_memory_scope()); the M5 Ultra is the M5 part that has
* two, and the scoped record is grounded on it alone. */
const bool scoped = chip == AGX_CHIP_G17D;
struct agx3_g17p_native_compute_program_desc desc = {
.program_va = UINT64_C(0x10000090000),
.shader_va = UINT64_C(0x100000003c0),
.ordering_memory_scope = true,
};
CHECK(agx3_cdm_direct_template_sources_compute(false, false, false,
&desc.launch_sources));
struct agx3_compute_program program;
/* Refused where the scoped ordering record is not grounded. */
CHECK(agx3_m5_native_compute_program_bind(chip, &desc, &program) ==
scoped);
desc.ordering_memory_scope = scoped;
CHECK(agx3_m5_native_compute_program_bind(chip, &desc, &program));
const uint32_t tail = scoped ? 0x6000017c : 0x60000160;
struct agx3_compute_direct_grid grid = {
.source = AGX3_CDM_DIRECT_GRID_GLOBAL_THREADS,
.size = {1024,1,1}, .local_size = {64,1,1}, .dimensions = 1,
};
const uint32_t expected[] = {
0, 0x01000000, 0x2400, 0x40000001,
1024, 1, 1, 64, 1, 1, 0x60000160,
1024, 1, 1, 64, 1, 1, tail,
};
uint8_t out[sizeof(expected)];
struct agx3_compute_dispatch_sink sink = {.data = out, .capacity = sizeof(out)};
Expand All @@ -323,7 +373,7 @@ test_m5_dispatch(enum agx_chip chip)
CHECK(!memcmp(saved, out, sizeof(out)));
const uint32_t indirect_local[] = {
0x10080000, 0x01000000, 0x2400, 0x40000001,
0x23, 0x45678000, 0x60000160,
0x23, 0x45678000, tail,
};
sink.length = 0;
CHECK(agx3_m5_native_indirect_dispatch_append(
Expand Down Expand Up @@ -546,6 +596,7 @@ test_multiround_uniforms(enum agx_chip chip)
{ .start_halfs = 8, .size_halfs = 180, .address = 0x5000010000 },
};
struct agx3_g17p_graphics_program_desc desc = {
.usc_clusters = m5_clusters(chip),
.program_va = 0x10000100000, .shader_va = 0x10000000480,
.shader_binary_size = 128, .nr_gprs = 16,
.compiler_d_valid = true, .uniform_ranges = ranges,
Expand Down Expand Up @@ -769,19 +820,25 @@ int main(void) {
int r = test_unused_vertex_outputs() || test_flat_shading_vertex() || test_load_completion_wait(AGX_CHIP_G17G) ||
test_load_completion_wait(AGX_CHIP_G17S) ||
test_load_completion_wait(AGX_CHIP_G17C) ||
test_load_completion_wait(AGX_CHIP_G17D) ||
test_multiround_uniforms(AGX_CHIP_G17G) ||
test_multiround_uniforms(AGX_CHIP_G17S) ||
test_multiround_uniforms(AGX_CHIP_G17C) ||
test_multiround_uniforms(AGX_CHIP_G17D) ||
test_cprog_input_bound(AGX_CHIP_G17G) ||
test_cprog_input_bound(AGX_CHIP_G17S) ||
test_cprog_input_bound(AGX_CHIP_G17C) ||
test_cprog_input_bound(AGX_CHIP_G17D) ||
test_color_disabled() || test_visibility() || test_line_width() || test_polygon_and_primitive_msaa() || test_g17g_programs(AGX_CHIP_G17G) || test_g17g_programs(AGX_CHIP_G17S) ||
test_g17g_programs(AGX_CHIP_G17C) ||
test_g17g_programs(AGX_CHIP_G17D) ||
test_m5_dispatch(AGX_CHIP_G17G) || test_m5_dispatch(AGX_CHIP_G17S) ||
test_m5_dispatch(AGX_CHIP_G17C) ||
test_m5_dispatch(AGX_CHIP_G17D) ||
test_m5_single_kick_launch(AGX_CHIP_G17G) ||
test_m5_single_kick_launch(AGX_CHIP_G17S) ||
test_m5_single_kick_launch(AGX_CHIP_G17C);
test_m5_single_kick_launch(AGX_CHIP_G17C) ||
test_m5_single_kick_launch(AGX_CHIP_G17D);
if (!r) puts("M5_PROGRAM_DISPATCH_PASS");
return r;
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ test_supported_contracts(void)
{AGX_CHIP_G17G, AGX_ISA_ENCODING_AGX3C, 14, 8},
{AGX_CHIP_G17S, AGX_ISA_ENCODING_AGX3C, 14, 8},
{AGX_CHIP_G17C, AGX_ISA_ENCODING_AGX3C, 14, 8},
{AGX_CHIP_G17D, AGX_ISA_ENCODING_AGX3C, 14, 8},
};

for (unsigned c = 0; c < sizeof(chips) / sizeof(chips[0]); ++c) {
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/test/test-native-mesh-program.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int main(void)
d.shader_binary_size=c.binary_size;d.scratch_size=c.scratch;
d.nr_gprs=32;d.compiler_d_valid=true;d.compiler_d=c.compiler_d;
d.threadgroup_memory_size_B=c.shared;
d.usc_clusters=2; /* the M5 Pro's lead */
struct agx3_g17p_graphics_program p = {0};
assert(agx3_g17g_mesh_program_generate(AGX_CHIP_G17S,&d,c.object,&p));
assert(p.length>=28);assert(memcmp(p.bytes,c.tail,28)==0);
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/test/test-scs-nir.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static bool compile(unsigned mode, unsigned variant, unsigned width,
if(out){FILE *f=fopen(out,"wb");assert(f);assert(fwrite(part.binary+part.info.main_offset,1,part.info.main_size,f)==part.info.main_size);assert(!fclose(f));printf("bytes=%u gprs=%u\n",part.info.main_size,part.info.nr_gprs);
struct agx3_g17p_graphics_program_desc desc={
.program_va=0x10000000000ull, .shader_va=0x10000003000ull,
.usc_clusters=2, /* the M5 Pro's lead */
.shader_binary_size=part.info.main_size,.nr_gprs=part.info.nr_gprs,
.scratch_size=MAX2(part.info.scratch_size, part.info.agx3_spectpr_scratch_size),
.compiler_d_valid=part.info.agx3_staging_known,
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/test/test-scs-query.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static void compile(unsigned mode,unsigned count,unsigned width,unsigned flags,
write_file(name,part.binary+part.info.main_offset,part.info.main_size);
struct agx3_ioto_uniform_range range={.start_halfs=122,.size_halfs=4,.address=0x10000090000ull};
struct agx3_g17p_graphics_program_desc desc={.program_va=0x10000000000ull,.shader_va=0x10000003000ull,
.usc_clusters=2, /* the M5 Pro's lead */
.uniform_ranges=mode==1?&range:NULL,.uniform_range_count=mode==1,
.shader_binary_size=part.info.main_size,.nr_gprs=part.info.nr_gprs,
.scratch_size=MAX2(part.info.scratch_size,part.info.agx3_spectpr_scratch_size),
Expand Down
22 changes: 22 additions & 0 deletions src/asahi/drm-shim/asahi_noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,26 @@ static const struct drm_asahi_params_global params_g17s = {
.usc_generation = 3, .gpu_hal_generation = DRM_ASAHI_GPU_HAL_300,
};

/* Explicit offline M5 Ultra identity (ASAHI_SHIM_CHIP=g17d) for
* command-generation tests: the M5 Pro profile's features with the M5 Ultra's
* admission contract (agx_params_m5_supported()): T6050, variant D, two dies,
* eight clusters of ten cores. It exercises what only a two-die, eight-cluster
* part selects: the scoped compute ordering record and the eight-cluster
* helper-table offsets. */
static const struct drm_asahi_params_global params_g17d = {
.features = DRM_ASAHI_FEATURE_SOFT_FAULTS | DRM_ASAHI_FEATURE_RENDER_RESOURCES |
DRM_ASAHI_FEATURE_RENDER_RESOURCES_V2,
.gpu_generation = 17, .gpu_variant = 'D', .gpu_revision = 0,
.chip_id = 0x6050, .num_dies = 2, .num_clusters_total = 8,
.num_cores_per_cluster = 10,
.core_masks = {0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff, 0x3ff},
.vm_start = 0x4000, .vm_end = (1ull << 42) - 0x8000ull,
.vm_kernel_min_size = 0x20000000, .max_commands_per_submission = 64,
.max_attachments = 16, .max_frequency_khz = 1500000,
.command_timestamp_frequency_hz = 1000000000,
.usc_generation = 3, .gpu_hal_generation = DRM_ASAHI_GPU_HAL_300,
};

/* The M5 Pro as the G17 kernel runtime presents it: GET_PARAMS of the E2
* kernel on a J716s (features 0x23cfe7c06, two clusters of ten cores): no
* soft faults, the M5 command set's features (program storage lists, shader
Expand Down Expand Up @@ -557,6 +577,8 @@ shim_params(void)
return &params_g16g;
if (chip && !strcmp(chip, "g17s"))
return &params_g17s;
if (chip && !strcmp(chip, "g17d"))
return &params_g17d;
if (chip && !strcmp(chip, "t6041"))
return &params_t6041;

Expand Down
Loading