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
378 changes: 370 additions & 8 deletions src/asahi/compiler/agx3_pack_binary.c

Large diffs are not rendered by default.

156 changes: 155 additions & 1 deletion src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -12285,7 +12285,7 @@ agx3_order_g18_msaa_tile_ops(agx_context *ctx)
}

static bool
agx3_order_g17p_mrt_tile_ops(agx_context *ctx)
agx3_order_g17p_mrt_tile_ops_strict(agx_context *ctx)
{
/* G18G: this optional pass cannot affect a non-fragment program or a
* preamble. Returning false means no transformation, not a refused shader.
Expand Down Expand Up @@ -12701,6 +12701,160 @@ agx3_order_g17p_mrt_tile_ops(agx_context *ctx)
return true;
}

/* Monolithic fragment shaders with on-chip tile-memory input-attachment reads
* (local_read / subpassLoad) can read partitions they never write and contain
* arbitrary control flow (e.g. lighting loops, per-sample unrolled loops)
* between their tile loads and final tile stores. Admit those shapes on
* chips with agx_chip_local_read_tilebuffer() (HAL200/AGX3B and HAL300/AGX3C)
* under a single uniform pixel-class transaction covering every touched
* partition. */
static bool
agx3_order_g17p_local_read_tile_ops(agx_context *ctx)
{
if (!ctx->key->agx3_local_read || ctx->key->m5_uniform_blend)
return false;

if (!agx_chip_local_read_tilebuffer(ctx->key->dev.chip) ||
(ctx->key->dev.encoding != AGX_ISA_ENCODING_AGX3B &&
!(ctx->key->dev.encoding == AGX_ISA_ENCODING_AGX3C &&
!ctx->key->dev.emit_agx3d && ctx->key->fs.nr_samples <= 8)) ||
ctx->stage != MESA_SHADER_FRAGMENT || ctx->is_preamble ||
ctx->key->secondary || ctx->key->fs.ignore_tib_dependencies ||
ctx->key->no_stop || ctx->key->g17p_emrt ||
list_is_empty(&ctx->blocks))
return false;

const bool multisample = ctx->key->fs.nr_samples > 1;
const BITSET_WORD *partitions = ctx->key->g17p_tile_partitions;
const bool keyed = !__bitset_is_empty(
partitions, BITSET_WORDS(AGX_G17P_MAX_BYTES_PER_SAMPLE));
agx_block *first_block = list_first_entry(&ctx->blocks, agx_block, link);
agx_block *exit_block = list_last_entry(&ctx->blocks, agx_block, link);

unsigned load_count = 0;
bool saw_stop = false;
bool saw_block0_cf = false;
bool tile_started = false;
bool saw_store = false;
bool all_loads_before_cf_and_stores = true;

agx_foreach_block(ctx, block) {
if (block == exit_block) {
if (block->successors[0] || block->successors[1])
return false;
} else {
if (!block->successors[0] && !block->successors[1])
return false;
}

agx_foreach_instr_in_block(block, I) {
if (saw_stop)
return false;

switch (I->op) {
case AGX_OPCODE_ZS_EMIT_AGX3:
case AGX_OPCODE_SIGNAL_PIX:
return false;
case AGX_OPCODE_SAMPLE_MASK_AGX3:
if (tile_started || block != first_block || saw_block0_cf)
return false;
break;
case AGX_OPCODE_LD_TILE:
if (I->nr_dests != 1 || I->nr_srcs != 2 || I->explicit_coords ||
I->pixel_offset >= AGX_G17P_MAX_BYTES_PER_SAMPLE ||
I->pixel_offset > UINT8_MAX ||
(keyed && !BITSET_TEST(partitions, I->pixel_offset)) ||
!(multisample
? (I->src[0].type == AGX_INDEX_NORMAL &&
I->src[0].size == AGX_SIZE_16)
: (I->src[0].type == AGX_INDEX_IMMEDIATE &&
I->src[0].value == 0xff)) ||
!agx_is_null(I->src[1]))
return false;
if (block != first_block || saw_block0_cf || saw_store)
all_loads_before_cf_and_stores = false;
tile_started = true;
load_count++;
break;
case AGX_OPCODE_ST_TILE:
if (I->nr_dests != 0 || I->nr_srcs != 3 || I->explicit_coords ||
I->pixel_offset >= AGX_G17P_MAX_BYTES_PER_SAMPLE ||
I->pixel_offset > UINT8_MAX ||
(keyed && !BITSET_TEST(partitions, I->pixel_offset)) ||
I->src[0].type != AGX_INDEX_NORMAL || I->src[0].memory ||
!(multisample
? (I->src[1].type == AGX_INDEX_NORMAL &&
I->src[1].size == AGX_SIZE_16)
: (I->src[1].type == AGX_INDEX_IMMEDIATE &&
I->src[1].value == 0xff)) ||
!agx_is_null(I->src[2]))
return false;
tile_started = true;
saw_store = true;
break;
case AGX_OPCODE_STOP:
if (block != exit_block)
return false;
saw_stop = true;
break;
case AGX_OPCODE_IF_ICMP:
case AGX_OPCODE_WHILE_ICMP:
case AGX_OPCODE_ELSE_ICMP:
case AGX_OPCODE_IF_FCMP:
case AGX_OPCODE_WHILE_FCMP:
case AGX_OPCODE_ELSE_FCMP:
case AGX_OPCODE_JMP_EXEC_ANY:
case AGX_OPCODE_JMP_EXEC_NONE:
case AGX_OPCODE_JMP_EXEC_NONE_AFTER:
case AGX_OPCODE_POP_EXEC:
case AGX_OPCODE_BREAK_IF_ICMP:
case AGX_OPCODE_BREAK_IF_FCMP:
case AGX_OPCODE_BEGIN_CF:
if (block == first_block)
saw_block0_cf = true;
break;
default:
break;
}
}
}

if (!saw_stop || !load_count)
return false;

/* Single-sample tile loads take only the immediate 0xff sample mask and
* have no register inputs. When every load sits in the entry block ahead
* of control flow and stores, group them back-to-back after the first load
* so all tilebuffer fetches overlap on independent scoreboard slots and
* load-only colour classes can release before lighting ALU begins. */
if (!multisample && all_loads_before_cf_and_stores && load_count > 1) {
agx_instr *anchor = NULL;
agx_foreach_instr_in_block_safe(first_block, I) {
if (I->op != AGX_OPCODE_LD_TILE)
continue;
if (!anchor) {
anchor = I;
continue;
}
list_del(&I->link);
list_add(&I->link, &anchor->link);
anchor = I;
}
}

ctx->agx3_mrt_tile_ops_ordered = true;
ctx->agx3_local_read_tile_ops = true;
return true;
}

static bool
agx3_order_g17p_mrt_tile_ops(agx_context *ctx)
{
if (ctx->key->agx3_local_read && !ctx->key->m5_uniform_blend)
return agx3_order_g17p_local_read_tile_ops(ctx);
return agx3_order_g17p_mrt_tile_ops_strict(ctx);
}

/* The tile load whose value a store writes back unchanged, or NULL. The value
* is the load's result or the collect of its split channels in order. */
static const agx_instr *
Expand Down
4 changes: 4 additions & 0 deletions src/asahi/compiler/agx_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ struct agx_shader_key {
* still proves its one read/write pixel transaction before admitting it. */
bool m5_uniform_blend;

/* Monolithic AGX3 fragment program reading color input attachments from
* on-chip tile memory (local_read / subpassLoad) across arbitrary CFG. */
bool agx3_local_read;

/* AGX3B: build the preamble as a native constant program (CProg inputs
* imported through its TPS frame, arithmetic results selected straight
* into uniform destinations, half exports legalized) for this shader.
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/agx_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ typedef struct {
bool agx3_staging_known;
bool agx3_fltnorm_start;
bool agx3_mrt_tile_ops_ordered;
bool agx3_local_read_tile_ops;
/* The packer emitted this fragment's tile accesses through the native1130
* mixed-format protocol, inside its 0x200 entry and final release (run
* 1139); its reads then take the long LLDCol form. */
Expand Down
5 changes: 3 additions & 2 deletions src/asahi/compiler/agx_register_allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -3006,8 +3006,9 @@ agx3_tile_store_bank(agx_context *ctx)
* So size the bank by what the stores actually need, prefix included, and
* widen to the same halves 0..63 the plain MRT bank below already uses past
* four targets rather than inventing a third bank. */
if (ctx->key->g17p_emrt && ctx->agx3_mrt_tile_ops_ordered &&
list_length(&ctx->blocks) > 1) {
if ((ctx->key->g17p_emrt && ctx->agx3_mrt_tile_ops_ordered &&
list_length(&ctx->blocks) > 1) ||
ctx->agx3_local_read_tile_ops) {
const unsigned prefix = ALIGN_POT(reserved_size(ctx), payload_align);
return prefix + payload_halves > 32 ? 64 : 32;
}
Expand Down
Loading