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
32 changes: 14 additions & 18 deletions src/asahi/compiler/agx3_pack_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ agx3_emit_texture_fetch(struct util_dynarray *emission,
* staging slot 2, then issues the texture result on slot 1. Keep those two
* independent scoreboard domains; reusing slot 1 for both is not a native
* dependency shape. */
const uint8_t staging_slot = m5 ? slot : ms_array || combined_array_lod
const uint8_t staging_slot = m5 ? slot : combined_array_lod
? 1 : register_lod ? 2 : slot;
/* A sparse read writes one extra register after its masked channels, so
* agx_emit_texture reserves an eight-channel destination for it (see
Expand Down Expand Up @@ -2396,19 +2396,24 @@ agx3_emit_texture_fetch(struct util_dynarray *emission,
* sharing the halves is retired first. */
const bool plain_bank = !ms_2d && !ms_array && !array && !register_lod;
const bool array_bank = array && !register_lod;
const bool m5_ms_banks = m5 && (ms_2d || ms_array);
const bool banked_read = plain_bank || array_bank || m5_ms_banks;
const bool agx3_ms_banks =
(m5 || enc == AGX_ISA_ENCODING_AGX3B) && (ms_2d || ms_array);
const bool banked_read = plain_bank || array_bank || agx3_ms_banks;
/* Fetch coordinates can name any aligned bank through half 60 (f19).
* Use independent eight-half banks for all scoreboard slots (6 on AGX3B,
* 8 on AGX3C) before recycling one. */
const unsigned plain_banks =
MIN2(m5 ? AGX3_M5_FETCH_BANKS : 6u, 1 + (60 - staging_base) / 8);
/* Keep independent non-array MS publications in separate operand banks. */
/* Keep independent multisample publications in separate eight-half banks
* (up to 6 on AGX3B 2D_MS, 4 on 2D_MS_ARRAY within bank 24). */
const unsigned ms_banks =
m5_ms_banks && !ms_array ? AGX3_M5_MS_FETCH_BANKS : 4;
m5 && !ms_array ? AGX3_M5_MS_FETCH_BANKS :
(enc == AGX_ISA_ENCODING_AGX3B && !ms_array)
? (staging_base <= 56 ? MIN2(6u, 1u + (56 - staging_base) / 8) : 1u)
: (staging_base <= 24 ? MIN2(4u, 1u + (24 - staging_base) / 8) : 1u);
const uint16_t bank_span =
(m5_ms_banks || array_bank) ? 8 : plain_bank ? 2 * coord_count
: staging_base + 8;
(agx3_ms_banks || array_bank) ? 8 : plain_bank ? 2 * coord_count
: staging_base + 8;
uint16_t staging_coord = staging_base;
uint16_t bank_retire = 0;
const bool reuse = group && group->reuse;
Expand All @@ -2430,7 +2435,7 @@ agx3_emit_texture_fetch(struct util_dynarray *emission,
/* Non-banked reads with PACK_SMPIR operands occupy halves 0..bank_span. */
const uint16_t first = banked_read ? staging_base : 0;
const unsigned max_banks =
m5_ms_banks ? ms_banks :
agx3_ms_banks ? ms_banks :
(plain_bank || array_bank) ? plain_banks : 1u;
bool placed = false;
for (unsigned c = 0; c < max_banks && !placed; ++c) {
Expand Down Expand Up @@ -14073,14 +14078,6 @@ agx3_pack_binary(agx_context *ctx, struct util_dynarray *emission)
* the generic round-robin starting point. */
if (enc == AGX_ISA_ENCODING_AGX3B && I->op == AGX_OPCODE_LD_TILE)
e->preferred_slot = 6;
/* Native multisample reloads keep the texture result on slot 1 and
* publish the packed sample/layer coordinate independently on slot
* 2. This prevents the fetch from waiting on its own generation. */
if (enc == AGX_ISA_ENCODING_AGX3B &&
I->op == AGX_OPCODE_TEXTURE_LOAD &&
(I->dim == AGX_DIM_2D_MS ||
I->dim == AGX_DIM_2D_MS_ARRAY))
e->preferred_slot = 1;
if (g17p_vertex_load_policy && I->op == AGX_OPCODE_DEVICE_LOAD &&
vertex_loads_scheduled++ == 0)
e->preferred_slot = 6;
Expand Down Expand Up @@ -15932,8 +15929,7 @@ agx3_pack_binary(agx_context *ctx, struct util_dynarray *emission)
}
const uint16_t fetch_wait =
g18_fixed_fetch_record ? 0 :
wait | (((enc == AGX_ISA_ENCODING_AGX3B ||
ctx->key->dev.emit_agx3d) &&
wait | ((ctx->key->dev.emit_agx3d &&
(I->dim == AGX_DIM_2D_MS ||
I->dim == AGX_DIM_2D_MS_ARRAY))
? (outstanding_here & 1u)
Expand Down
51 changes: 29 additions & 22 deletions src/asahi/compiler/agx3_tex_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ fetch_ok(enum agx_isa_encoding enc, const struct agx3_tex_fetch_desc *d)
(enc == AGX_ISA_ENCODING_AGX3C
? (!d->staged_sample || (d->coord & 7) ||
d->coord > (d->array ? 24 : 120))
: d->coord != (d->array && !d->staged_sample ? 16 : 0)))))
: d->staged_sample
? ((d->coord & 7) || d->coord > (d->array ? 24 : 56))
: d->coord != (d->array ? 16 : 0)))))
return false;

/* Own-MSL texture3d::read witnesses use f76=3 with a third integer
Expand Down Expand Up @@ -259,7 +261,7 @@ agx3_tex_encode_fetch(enum agx_isa_encoding enc,
return false;
}

if (d->multisample && !d->array) {
if (d->multisample && !d->array && !d->staged_sample) {
/* Own-MSL reads of samples 0..3 isolate this two-bit immediate: byte 5
* is 00/02/04/06 while the remaining sample-0 instruction is fixed. */
if (out[5] & 0x06) {
Expand Down Expand Up @@ -3076,26 +3078,29 @@ agx3_tex_stage_ms_array_sample_at(
uint16_t packed_layer, uint8_t slot, bool cache, bool discard,
uint8_t out[AGX3_TEX_MAX_LENGTH], uint8_t *len)
{
if (enc == AGX_ISA_ENCODING_AGX3B && bank == 0)
return agx3_tex_stage_ms_array_sample(enc, sample, packed_layer,
cache, discard, out, len);
if (!out || !len)
return false;
memset(out, 0, AGX3_TEX_MAX_LENGTH);
*len = 0;
if (enc != AGX_ISA_ENCODING_AGX3C || (bank & 7) || bank > 24 ||
sample >= 128 || (sample & 1) || packed_layer > 254 ||
(packed_layer & 1) || slot < 1 || slot > 8 || (cache && discard))
const bool m5 = enc == AGX_ISA_ENCODING_AGX3C;
const unsigned slots = m5 ? 8 : 6;
if ((!m5 && enc != AGX_ISA_ENCODING_AGX3B) || (bank & 7) || bank > 24 ||
sample >= 128 || (sample & 1) ||
packed_layer > (m5 ? 254 : 190) || (packed_layer & 1) ||
slot < 1 || slot > slots || (cache && discard))
return false;
const struct agx3_field_kv fields[] = {
KV(5, bank + 4), KV(9, 5), KV(10, 2), KV(12, slot),
KV(16, sample), KV(23, 2), KV(24, 1), KV(25, cache), KV(27, discard),
KV(37, 1), KV(38, 1), KV(44, packed_layer), KV(51, 2),
KV(52, 2), KV(55, 1), KV(56, 1), KV(57, 119),
KV(52, 2), KV(55, 1),
KV(74, 9), KV(75, 12), KV(76, 1), KV(77, 16),
KV(56, 1), KV(57, 119),
};
return agx3_bind_compose(enc, AGX3_MN_pack_smpir, 0, fields,
sizeof(fields) / sizeof(fields[0]), NULL, 0, out, len);
const unsigned nfields =
sizeof(fields) / sizeof(fields[0]) - (m5 ? 0 : 2);
return agx3_bind_compose(enc, AGX3_MN_pack_smpir, 0, fields, nfields,
NULL, 0, out, len);
}

/* Native texture2d_ms reads publish the sample at fixed staging half4.
Expand Down Expand Up @@ -3173,33 +3178,35 @@ agx3_tex_stage_ms_sample_at(enum agx_isa_encoding enc, uint16_t bank,
bool src_cache, bool src_discard,
uint8_t out[AGX3_TEX_MAX_LENGTH], uint8_t *len)
{
if (enc == AGX_ISA_ENCODING_AGX3B && bank == 0)
return agx3_tex_stage_ms_sample(enc, src, wait_mask, src_cache,
src_discard, out, len);
if (!out || !len)
return false;
memset(out, 0, AGX3_TEX_MAX_LENGTH);
*len = 0;
if (enc != AGX_ISA_ENCODING_AGX3C || (bank & 7) || bank > 120 ||
src >= 256 || (src & 1) || slot < 1 || slot > 8 ||
(wait_mask & ~0xffu) || (src_cache && src_discard))
const bool m5 = enc == AGX_ISA_ENCODING_AGX3C;
const unsigned slots = m5 ? 8 : 6;
if ((!m5 && enc != AGX_ISA_ENCODING_AGX3B) || (bank & 7) ||
bank > (m5 ? 120 : 56) || src >= 256 || (src & 1) ||
slot < 1 || slot > slots ||
(wait_mask & ~((1u << slots) - 1)) || (src_cache && src_discard))
return false;

const struct agx3_field_kv fields[] = {
KV(5, bank + 4), KV(9, 5), KV(10, 2), KV(12, slot),
KV(16, src), KV(23, 2), KV(24, 1),
KV(25, src_cache), KV(27, src_discard),
KV(37, 1), KV(38, 1), KV(51, 1), KV(52, 2),
KV(56, 1), KV(57, 119), KV(74, 9), KV(75, 12), KV(76, 1), KV(77, 16),
KV(74, 9), KV(75, 12), KV(76, 1), KV(77, 16),
KV(56, 1), KV(57, 119),
};
const unsigned nfields =
sizeof(fields) / sizeof(fields[0]) - (m5 ? 0 : 2);
struct agx3_field_kv waits[8];
unsigned n = 0;
for (unsigned i = 0; i < 8; ++i)
for (unsigned i = 0; i < slots; ++i)
if (wait_mask & (1u << i))
waits[n++] = (struct agx3_field_kv)KV(58 + i, 1);
return agx3_bind_compose(enc, AGX3_MN_pack_smpir, 0, fields,
sizeof(fields) / sizeof(fields[0]), waits, n,
out, len);
return agx3_bind_compose(enc, AGX3_MN_pack_smpir, 0, fields, nfields,
waits, n, out, len);
}

/* Fresh native G17P LOD fragment witnesses use this 12-byte PACK_SMPIR for a
Expand Down
31 changes: 30 additions & 1 deletion src/asahi/compiler/agx_pressure_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ ilp_agx3b_sample_relocatable(const agx_instr *I)
case AGX_OPCODE_IMAGE_LOAD:
if (I->nr_srcs < 2 ||
(I->dim != AGX_DIM_2D && I->dim != AGX_DIM_2D_ARRAY &&
I->dim != AGX_DIM_2D_MS && I->dim != AGX_DIM_2D_MS_ARRAY &&
I->dim != AGX_DIM_3D))
return false;

Expand Down Expand Up @@ -934,18 +935,46 @@ ilp_tile_store_bank_overflows(agx_context *ctx, struct sched_node **nodes,
ctx->stage != MESA_SHADER_FRAGMENT || ctx->is_preamble)
return false;

/* A split channel takes its vector's register, and RA places the whole
* vector of a stored channel in the bank (see low_gpr in agx_ra()): a
* per-sample reload of an R32 target stores channel 0 of each eight-half
* 2D_MS texel fetch. Count the vector while it is live, not only the
* stored channel. */
uint8_t *tile_width = NULL;
agx_index *split_parent = NULL;
agx_foreach_instr_global(ctx, I) {
if (I->op == AGX_OPCODE_SPLIT && I->src[0].type == AGX_INDEX_NORMAL &&
I->src[0].value < ctx->alloc) {
if (!split_parent) {
split_parent =
rzalloc_array(memctx, agx_index, MAX2(ctx->alloc, 1));
if (!split_parent)
return true;
}
agx_foreach_ssa_dest(I, d) {
if (I->dest[d].value < ctx->alloc)
split_parent[I->dest[d].value] = I->src[0];
}
}
if (I->op != AGX_OPCODE_ST_TILE || I->src[0].type != AGX_INDEX_NORMAL ||
I->src[0].value >= ctx->alloc)
continue;
if (!tile_width) {
tile_width = rzalloc_array(memctx, uint8_t, MAX2(ctx->alloc, 1));
if (!tile_width)
if (!tile_width) {
ralloc_free(split_parent);
return true;
}
}
tile_width[I->src[0].value] = agx_index_size_16(I->src[0]);
if (split_parent && split_parent[I->src[0].value].type ==
AGX_INDEX_NORMAL) {
const agx_index vec = split_parent[I->src[0].value];
tile_width[vec.value] =
MAX2(tile_width[vec.value], agx_index_size_16(vec));
}
}
ralloc_free(split_parent);
if (!tile_width)
return false;

Expand Down
85 changes: 82 additions & 3 deletions src/asahi/compiler/test/test-agx3-pack-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6092,13 +6092,13 @@ TEST_F(AGX3PackBinary, TextureFetchRepeatedWaitKeepsCoordinateUntilFinalCopy)

uint8_t bytes[AGX3_TEX_MAX_LENGTH], len = 0;
std::vector<uint8_t> copies;
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 0, 12, 1, 1, false, false,
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 0, 12, 3, 1, false, false,
bytes, &len));
append(copies, bytes, len);
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 0, 12, 1, 2, false, true,
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 0, 12, 3, 2, false, true,
bytes, &len));
append(copies, bytes, len);
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 2, 14, 1, 0, false, true,
ASSERT_TRUE(agx3_tex_stage_copy_hints(enc, 2, 14, 3, 0, false, true,
bytes, &len));
append(copies, bytes, len);

Expand Down Expand Up @@ -6677,6 +6677,85 @@ TEST_F(AGX3PackBinary, TextureFetch2DMSIndexedTextureAndSample)
EXPECT_EQ(b->shader->agx3_staging_halfs, 8u);
}

/* Back-to-back AGX3B 2D_MS and 2D_MS_ARRAY texel fetches allocate disjoint
* 8-half staging banks (0, 8, 16, 24) across scoreboard slots 1..4 with zero
* serializing wait carriers. */
TEST_F(AGX3PackBinary, TextureFetch2DMSRelocatesBanksAcrossSlots)
{
for (enum agx_dim dim : {AGX_DIM_2D_MS, AGX_DIM_2D_MS_ARRAY}) {
SCOPED_TRACE(dim);
agx_builder *b = builder(AGX_ISA_ENCODING_AGX3B);
agx_shader_info info = {};
b->shader->out = &info;
b->shader->stage = MESA_SHADER_FRAGMENT;
b->shader->max_reg = 127;

for (unsigned i = 0; i < 4; ++i) {
agx_index dest = agx_register(32 + 8 * i, AGX_SIZE_32);
agx_index coord = agx_register(4, AGX_SIZE_32);
dest.channels_m1 = 3;
coord.channels_m1 = 2;
coord.discard = (i == 3);
agx_instr *I = agx_texture_sample_to(
b, dest, coord, agx_immediate(0), agx_immediate(0),
agx_immediate(i), agx_immediate(0), agx_null(), dim,
AGX_LOD_MODE_AUTO_LOD, 0, false, false, false, AGX_GATHER_NONE,
false);
I->op = AGX_OPCODE_TEXTURE_LOAD;
I->mask = 15;
}
/* Consume each fetch's destination so the slot planner keeps all four
* fetches in flight on distinct scoreboard slots. */
agx_fadd_to(b, agx_register(0, AGX_SIZE_32),
agx_register(32, AGX_SIZE_32),
agx_register(40, AGX_SIZE_32));
agx_fadd_to(b, agx_register(2, AGX_SIZE_32),
agx_register(48, AGX_SIZE_32),
agx_register(56, AGX_SIZE_32));
agx_fadd_to(b, agx_register(0, AGX_SIZE_32),
agx_register(0, AGX_SIZE_32),
agx_register(2, AGX_SIZE_32));
agx_stop(b);

const auto code = pack(b);
ASSERT_FALSE(code.empty()) << agx3_last_pack_refusal();
EXPECT_EQ(b->shader->agx3_staging_halfs, 32u);
EXPECT_EQ(b->shader->out->stats.carriers, 0u);

uint8_t used_slots = 0;
for (unsigned i = 0; i < 4; ++i) {
bool found = false;
for (uint8_t slot = 1; slot <= 6 && !found; ++slot) {
struct agx3_tex_fetch_desc want = {};
want.dest = 32 + 8 * i;
want.coord = 8 * i;
want.width = AGX3_TEX_W32;
want.mask = 15;
want.texture = i;
want.slot = slot;
want.wait_mask = (uint16_t)(1u << (slot - 1));
want.coord_kill = true;
want.final = (i == 3);
want.array = (dim == AGX_DIM_2D_MS_ARRAY);
want.multisample = true;
want.staged_sample = true;
want.sampler_value = 1;
uint8_t bytes[AGX3_TEX_MAX_LENGTH], len = 0;
ASSERT_TRUE(agx3_tex_encode_fetch(AGX_ISA_ENCODING_AGX3B, &want,
bytes, &len));
if (std::search(code.begin(), code.end(), bytes, bytes + len) !=
code.end()) {
found = true;
used_slots |= (uint8_t)(1u << (slot - 1));
}
}
EXPECT_TRUE(found)
<< "missing relocated MS fetch at bank " << (8 * i);
}
EXPECT_EQ(__builtin_popcount(used_slots), 4);
}
}

TEST_F(AGX3PackBinary, TextureFetch2DMSArrayBindless)
{
agx_builder *b = builder(AGX_ISA_ENCODING_AGX3B);
Expand Down
Loading