Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 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
2 changes: 1 addition & 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
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 @@ -2757,7 +2757,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
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 @@ -384,6 +384,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 @@ -555,6 +575,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
15 changes: 13 additions & 2 deletions src/asahi/genxml/agx3_cmdstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,17 @@ agx3_cdm_barrier_flush_memory_grounded(enum agx_chip chip)
return agx_chip_has_record(chip, AGX_RECORD_CDM_BARRIER_FLUSH_MEMORY);
}

/* Whether a barrier's flags take memory scope on this chip: the strong flush
* (flags 5) wherever memory scope is grounded, and the ordering record
* (flags 0) where AGX_RECORD_CDM_ORDERING_FLUSH_MEMORY is. */
static inline bool
agx3_cdm_barrier_flush_memory_flags(enum agx_chip chip, uint8_t flags)
{
return flags == 5 ||
(flags == 0 &&
agx_chip_has_record(chip, AGX_RECORD_CDM_ORDERING_FLUSH_MEMORY));
}

static inline uint32_t
agx3_cdm_barrier_word(uint8_t flags)
{
Expand All @@ -595,7 +606,7 @@ agx3_cdm_barrier_pack(const struct agx3_cdm_barrier_info *info,

if (info->flush_memory &&
(!agx3_cdm_barrier_flush_memory_grounded(info->chip) ||
info->flags != 5))
!agx3_cdm_barrier_flush_memory_flags(info->chip, info->flags)))
return false;
agx3_cmdstream_store_le32(
packed, agx3_cdm_barrier_word(info->flags) |
Expand Down Expand Up @@ -645,7 +656,7 @@ agx3_cdm_barrier_unpack(enum agx_chip chip, const void *packed,
if (!agx3_cdm_barrier_flags_grounded(chip, flags))
return false;

if (flush_memory && flags != 5)
if (flush_memory && !agx3_cdm_barrier_flush_memory_flags(chip, flags))
return false;
info->chip = chip;
info->flags = flags;
Expand Down
Loading