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
132 changes: 42 additions & 90 deletions src/asahi/compiler/test/test-agx3-fm-wave2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,25 @@ build_const_bitpack_loop(unsigned trips, bool bottom_tested, bool with_load,

} /* namespace */

/* A test builder for one shader stage; key must outlive the builder. */
static agx_builder *
fm_test_builder(void *mem, agx_shader_key *key, enum agx_isa_encoding enc,
enum agx_chip chip, mesa_shader_stage stage, bool has_scratch)
{
*key = {};
key->dev.encoding = enc;
key->dev.chip = chip;
key->has_scratch = has_scratch;

agx_builder *b = agx_test_builder(mem);
b->shader->key = key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = stage;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = stage;
return b;
}

/* Bottom-tested rotated loop (do { ... ++iv; } while (iv < n)) must lower
* idiv/imod and udiv/umod into a running (q, r) recurrence just like a
* top-tested loop, while refusing step != 1. */
Expand Down Expand Up @@ -538,16 +557,8 @@ TEST(FmWave2IlpSchedule, TwoLevelIndirectLoadInterleave)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17S;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3C,
AGX_CHIP_G17S, MESA_SHADER_COMPUTE, true);

agx_block *blk = agx_start_block(b->shader);
b->cursor = agx_after_block(blk);
Expand Down Expand Up @@ -598,16 +609,8 @@ TEST(FmWave2IlpSchedule, StoreStillSerializesLaterLoads)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17S;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3C,
AGX_CHIP_G17S, MESA_SHADER_COMPUTE, true);

agx_block *blk = agx_start_block(b->shader);
b->cursor = agx_after_block(blk);
Expand Down Expand Up @@ -659,16 +662,8 @@ TEST(FmWave2IlpSchedule, TwoLoadComputeLoopHoists)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17S;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3C,
AGX_CHIP_G17S, MESA_SHADER_COMPUTE, true);

agx_block *entry = agx_start_block(b->shader);
agx_block *body = agx_test_block(b->shader);
Expand Down Expand Up @@ -854,16 +849,10 @@ TEST(FmWave2IlpSchedule, Agx3bComputeLoopInterleavesIcAndScib)
{AGX_ISA_ENCODING_AGX3B, AGX_ISA_ENCODING_AGX3C}) {
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = enc;
key.dev.chip = enc == AGX_ISA_ENCODING_AGX3B ? AGX_CHIP_G16G : AGX_CHIP_G17S;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(
mem, &key, enc,
enc == AGX_ISA_ENCODING_AGX3B ? AGX_CHIP_G16G : AGX_CHIP_G17S,
MESA_SHADER_COMPUTE, true);

agx_block *entry = agx_start_block(b->shader);
agx_block *body = agx_test_block(b->shader);
Expand Down Expand Up @@ -927,16 +916,9 @@ TEST(FmWave2IlpSchedule, Agx3bComputeLoopRespectsOccupancyTierCapAndHighPressure
for (unsigned nkeep : {12u, 20u, 32u, 44u, 46u, 130u}) {
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
key.dev.chip = AGX_CHIP_G16G;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b =
fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3B, AGX_CHIP_G16G,
MESA_SHADER_COMPUTE, true);

agx_block *entry = agx_start_block(b->shader);
agx_block *body = agx_test_block(b->shader);
Expand Down Expand Up @@ -1066,17 +1048,9 @@ TEST(FmWave2IlpSchedule, Agx3bComputeIntLoopPreserves48And96HalfGranules)
int &after_out, unsigned &alloc_out) {
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
key.dev.chip = chip;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3B, chip,
MESA_SHADER_COMPUTE, true);
b->shader->any_cf = any_cf;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;

agx_block *pre = agx_start_block(b->shader);
agx_block *loop_pre = agx_test_block(b->shader);
Expand Down Expand Up @@ -1189,7 +1163,7 @@ TEST(FmWave2IlpSchedule, Agx3bComputeIntLoopPreserves48And96HalfGranules)
* 32-bit vec3 rounding near the 104-half (7 vec3 + 20 scalars), 136-half,
* 160-half (3 vec3 + 108 scalars), and 184-half boundaries across all
* AGX3B chips. */
for (enum agx_chip chip : {AGX_CHIP_G15S, AGX_CHIP_G16G, AGX_CHIP_G17P}) {
for (enum agx_chip chip : {AGX_CHIP_G15S, AGX_CHIP_G17P}) {
struct {
unsigned nr_vec3;
unsigned live16;
Expand Down Expand Up @@ -1259,16 +1233,8 @@ TEST(FmWave2IlpSchedule, Agx3bComputeIntLoopEnforces8HalfGrowthBound)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
key.dev.chip = AGX_CHIP_G16G;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3B,
AGX_CHIP_G16G, MESA_SHADER_COMPUTE, true);

agx_block *pre = agx_start_block(b->shader);
agx_block *loop_pre = agx_test_block(b->shader);
Expand Down Expand Up @@ -1357,15 +1323,8 @@ TEST(FmWave2IlpSchedule, Agx3bPipeSplitAndIcPacingDoNotLeakOutsideComputeIntLoop
for (mesa_shader_stage stage : {MESA_SHADER_VERTEX, MESA_SHADER_FRAGMENT}) {
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
key.dev.chip = AGX_CHIP_G16G;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = stage;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = stage;
agx_builder *b = fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3B,
AGX_CHIP_G16G, stage, false);

agx_block *pre = agx_start_block(b->shader);
agx_block *body = agx_test_block(b->shader);
Expand Down Expand Up @@ -1417,16 +1376,9 @@ TEST(FmWave2IlpSchedule, Agx3bPipeSplitAndIcPacingDoNotLeakOutsideComputeIntLoop
for (mixed_kind kind : {MIXED_FADD, MIXED_RCP, MIXED_FCMPSEL, MIXED_BITTEST_SELECT}) {
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
key.dev.chip = AGX_CHIP_G16G;
key.has_scratch = true;

agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
b->shader->out = rzalloc(mem, agx_shader_info);
b->shader->stage = MESA_SHADER_COMPUTE;
b->shader->nir = rzalloc(mem, nir_shader);
b->shader->nir->info.stage = MESA_SHADER_COMPUTE;
agx_builder *b =
fm_test_builder(mem, &key, AGX_ISA_ENCODING_AGX3B, AGX_CHIP_G16G,
MESA_SHADER_COMPUTE, true);

agx_block *pre = agx_start_block(b->shader);
agx_block *body = agx_test_block(b->shader);
Expand Down
21 changes: 1 addition & 20 deletions src/asahi/compiler/test/test-agx3-pack-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19611,7 +19611,7 @@ TEST_F(AGX3PackBinary, FragmentTexelFetchUsesReservedSamplerZeroOnAgx3c)
/* Trimmed 16-bit vec3 loads (6 bytes) from global and global-constant memory
* (the lowered load_agx and load_constant_agx forms) must shrink before
* emission and encode/pack as a 3-component W16 load on AGX2, AGX3B, AGX3C,
* and G18G (AGX3D). */
* and G18G (AGX3D). The NIR side of the trim is in test-shrink-memory-loads. */
TEST_F(AGX3PackBinary, TrimmedF16Vec3MemoryLoadsPack)
{
const struct {
Expand Down Expand Up @@ -19661,25 +19661,6 @@ TEST_F(AGX3PackBinary, TrimmedF16Vec3MemoryLoadsPack)
EXPECT_GT(part.info.stats.instrs, 0u);
ASSERT_GT(part.info.main_size, 0u);

const nir_intrinsic_op expect_op =
is_ubo ? nir_intrinsic_load_constant_agx : nir_intrinsic_load_agx;
unsigned trimmed_nir_loads = 0;
nir_foreach_function_impl(impl, b.shader) {
nir_foreach_block(block, impl) {
nir_foreach_instr(instr, block) {
if (instr->type != nir_instr_type_intrinsic)
continue;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic == expect_op) {
EXPECT_EQ(intr->def.bit_size, 16u);
EXPECT_EQ(intr->def.num_components, 3u);
trimmed_nir_loads++;
}
}
}
}
EXPECT_EQ(trimmed_nir_loads, 1u);

const uint8_t *code =
static_cast<const uint8_t *>(part.binary) + part.info.main_offset;
unsigned w16_vec3_loads = 0;
Expand Down
74 changes: 19 additions & 55 deletions src/asahi/compiler/test/test-sampled-compute-register-cap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,6 @@ TEST(SampledComputeRegisterCap, RetryAfterFailedAllocationUsesWholeFile)
EXPECT_EQ(scratch_B, 0u);
}

/* Encodings without launch-allocated static TPS (AGX2) stay uncapped even when
* optional_spills is true and >= 4 texture loads are present. */
TEST(SampledComputeRegisterCap, NoCapOnAGX2WithoutStaticTPS)
{
const enum agx_chip chips[] = {AGX_CHIP_G13G, AGX_CHIP_G14G};
for (enum agx_chip chip : chips) {
SCOPED_TRACE(chip);
void *mem = ralloc_context(NULL);
agx_builder *b = NULL;
agx_shader_key key = {};
build_sampled_compute_air(mem, &b, &key, AGX_ISA_ENCODING_AGX2, chip,
false, 0, false, true, 4, 84);
agx_ra(b->shader);
ASSERT_FALSE(b->shader->ra_failed);
EXPECT_FALSE(b->shader->sampled_cap_applied);
EXPECT_GE(b->shader->max_reg, 160u);
EXPECT_EQ(b->shader->scratch_size_B, 0u);
ralloc_free(mem);
}
}

/* A launch that cannot take the cap's spills keeps the whole file. */
TEST(SampledComputeRegisterCap, NoCapWithoutOptionalSpills)
{
Expand All @@ -177,7 +156,6 @@ TEST(SampledComputeRegisterCap, NoCapWithoutOptionalSpills)
bool emit_agx3d;
} targets[] = {
{AGX_ISA_ENCODING_AGX3C, AGX_CHIP_G17C, false},
{AGX_ISA_ENCODING_AGX2, AGX_CHIP_G14G, false},
{AGX_ISA_ENCODING_AGX3C, AGX_CHIP_G18G, true},
};

Expand Down Expand Up @@ -277,6 +255,22 @@ build_agx3c_sampled_compute_nir(unsigned n_tex, unsigned n_live)
return b.shader;
}

/* Compile on G17C with optional spills and a 4 KiB spill bound. */
static void
compile_g17c_sampled(nir_shader *nir, agx_shader_part *part)
{
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17C;
key.has_scratch = true;
key.optional_spills = true;
key.max_scratch_B = 4096;
key.no_preamble = true;
key.reserved_preamble = 16;
ASSERT_TRUE(agx_compile_shader_nir(nir, &key, part))
<< agx_last_compile_refusal();
}

/* When the 160-half cap pushes spill demand past the RA_MEM bound (4 KiB),
* compilation drops the cap and retries from the whole register file instead
* of refusing a program that fits there. */
Expand Down Expand Up @@ -315,18 +309,8 @@ TEST(SampledComputeRegisterCap, RetryOnSpillExhaustionUsesWholeFile)
nir_shader *nir = build_agx3c_sampled_compute_nir(4, 1115);
ASSERT_NE(nir, nullptr);

agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17C;
key.has_scratch = true;
key.optional_spills = true;
key.max_scratch_B = 4096;
key.no_preamble = true;
key.reserved_preamble = 16;

agx_shader_part part = {};
ASSERT_TRUE(agx_compile_shader_nir(nir, &key, &part))
<< agx_last_compile_refusal();
ASSERT_NO_FATAL_FAILURE(compile_g17c_sampled(nir, &part));
EXPECT_GT(part.info.nr_gprs, 160u);
EXPECT_GT(part.info.scratch_size, 0u);

Expand All @@ -344,18 +328,8 @@ TEST(SampledComputeRegisterCap, ExcessiveSpillsRetryUsesWholeFile)
nir_shader *nir = build_agx3c_sampled_compute_nir(4, 100);
ASSERT_NE(nir, nullptr);

agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17C;
key.has_scratch = true;
key.optional_spills = true;
key.max_scratch_B = 4096;
key.no_preamble = true;
key.reserved_preamble = 16;

agx_shader_part part = {};
ASSERT_TRUE(agx_compile_shader_nir(nir, &key, &part))
<< agx_last_compile_refusal();
ASSERT_NO_FATAL_FAILURE(compile_g17c_sampled(nir, &part));
EXPECT_GT(part.info.nr_gprs, 160u);
EXPECT_EQ(part.info.scratch_size, 0u);

Expand All @@ -373,18 +347,8 @@ TEST(SampledComputeRegisterCap, ModerateSpillsKeepSampledCap)
nir_shader *nir = build_agx3c_sampled_compute_nir(16, 86);
ASSERT_NE(nir, nullptr);

agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17C;
key.has_scratch = true;
key.optional_spills = true;
key.max_scratch_B = 4096;
key.no_preamble = true;
key.reserved_preamble = 16;

agx_shader_part part = {};
ASSERT_TRUE(agx_compile_shader_nir(nir, &key, &part))
<< agx_last_compile_refusal();
ASSERT_NO_FATAL_FAILURE(compile_g17c_sampled(nir, &part));
EXPECT_LE(part.info.nr_gprs, 160u);
EXPECT_GT(part.info.scratch_size, 0u);

Expand Down
Loading