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
26 changes: 9 additions & 17 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -13828,20 +13828,12 @@ agx_compile_function_nir_attempt(nir_shader *nir, nir_function_impl *impl,
!ctx->is_preamble;
if ((agx3_cse || m5_bounded_cse) &&
!(agx_compiler_debug & AGX_DBG_NOOPT)) {
/* AGX3B main programs use the pressure-aware CSE, which merges only
* while the earlier result is still live. Uniform source lowering
* copies a uniform into a GPR for each operation that cannot read it in
* place, so a value used by a run of selects is copied once per select,
* and each copy is read right after it is made. On G17P and in M5
* main programs, also merge such copies where that keeps the register
* pressure within the shader's existing peak. */
if (key->dev.encoding == AGX_ISA_ENCODING_AGX3B && !ctx->is_preamble &&
ctx->stage != MESA_SHADER_VERTEX) {
if (key->dev.chip == AGX_CHIP_G17P)
AGX_PASS(ctx, agx_opt_cse_bounded);
else
AGX_PASS(ctx, agx_opt_cse_pressure);
} else if (m5_bounded_cse) {
/* AGX3B and AGX3C main programs use bounded pressure-aware CSE so
* uniform-source copies can merge without exceeding the shader's
* existing peak register pressure. */
if ((key->dev.encoding == AGX_ISA_ENCODING_AGX3B && !ctx->is_preamble &&
ctx->stage != MESA_SHADER_VERTEX) ||
m5_bounded_cse) {
AGX_PASS(ctx, agx_opt_cse_bounded);
} else {
AGX_PASS(ctx, agx_opt_cse);
Expand Down Expand Up @@ -17208,10 +17200,10 @@ agx_compile_shader_nir_internal(nir_shader *nir, struct agx_shader_key *key,
NIR_PASS(_, nir, nir_opt_dce);
}

if (key->dev.encoding == AGX_ISA_ENCODING_AGX3C) {
NIR_PASS(_, nir, agx_nir_opt_canonical_minmax);
bool canonical_minmax_progress = false;
NIR_PASS(canonical_minmax_progress, nir, agx_nir_opt_canonical_minmax);
if (canonical_minmax_progress)
NIR_PASS(_, nir, nir_opt_dce);
}


if (key->dev.encoding == AGX_ISA_ENCODING_AGX3C) {
Expand Down
2 changes: 1 addition & 1 deletion src/asahi/compiler/agx_opt_register_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
static void
agx3_remove_redundant_physical_copies(agx_context *ctx)
{
if (ctx->key->dev.encoding != AGX_ISA_ENCODING_AGX3C ||
if (!agx_isa_is_agx3(ctx->key->dev.encoding) ||
ctx->stage != MESA_SHADER_FRAGMENT || ctx->is_preamble)
return;

Expand Down
3 changes: 1 addition & 2 deletions src/asahi/compiler/agx_spill.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,7 @@ compute_w_entry_loop_header(struct spill_ctx *ctx)

BITSET_WORD *used = NULL;
unsigned room = 0;
if (agx_chip_g17p_or_m5(ctx->shader->key->dev.chip) &&
!ctx->remat_only) {
if (!ctx->remat_only) {
used = BITSET_CALLOC(ctx->n);
room = loop_room_for_live_through(ctx, used);
}
Expand Down
44 changes: 16 additions & 28 deletions src/asahi/vulkan/hk_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ lower_load_global_bounded(nir_builder *b, nir_intrinsic_instr *intr)

struct global_load_lowering {
bool soft_fault;
/* G17P and M5: storage-buffer loads use the soft-fault form as well:
/* With soft faults, storage-buffer loads use the soft-fault form as well:
* load, then zero the value when the access is out of bounds. */
bool storage_result_select;
};
Expand Down Expand Up @@ -3333,24 +3333,14 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir,
bool lowered_global_io = false;
NIR_PASS(lowered_global_io, nir, nir_lower_explicit_io, nir_var_mem_global,
nir_address_format_64bit_global);
/* While UBO (and G17P/M5 SSBO) offsets are still 32-bit deref offsets,
* merge adjacent scalar and component loads: once lowered to 64-bit
* base + u2u64(offset32), potential 32-bit wrap hides adjacency from later
* nir_opt_load_store_vectorize. Gate pre-lowering SSBO vectorization on
* G17P and M5 (matching storage_result_select below) so AGX2 and other
* generations keep their exact existing lowering sequence. A uniform buffer
* does not change during a draw or dispatch, so its loads may also be
* marked reorderable before CSE and vectorization. */
const bool agx3_ssbo_vec = agx_chip_g17p_or_m5(dev->dev.chip);
bool lowered_buf_io = false;
if (!agx3_ssbo_vec) {
NIR_PASS(lowered_buf_io, nir, nir_lower_explicit_io, nir_var_mem_ssbo,
hk_buffer_addr_format(rs->storage_buffers,
rs->null_storage_buffer_descriptor,
agx_chip_g17_m5(dev->dev.chip)));
}
/* While UBO and SSBO offsets are still 32-bit deref offsets, merge adjacent
* scalar and component loads: once lowered to 64-bit base + u2u64(offset32),
* potential 32-bit wrap hides adjacency from later
* nir_opt_load_store_vectorize. A uniform buffer does not change during a
* draw or dispatch, so its loads may also be marked reorderable before CSE
* and vectorization. */
const nir_variable_mode pre_lower_vec_modes =
nir_var_mem_ubo | (agx3_ssbo_vec ? nir_var_mem_ssbo : 0);
nir_var_mem_ubo | nir_var_mem_ssbo;
bool lowered_pre_vec = false;
NIR_PASS(lowered_pre_vec, nir, nir_lower_array_deref_of_vec,
pre_lower_vec_modes, NULL,
Expand All @@ -3368,20 +3358,18 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir,
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT
? 0
: nir_var_mem_ubo) |
(!agx3_ssbo_vec ||
rs->storage_buffers ==
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT
(rs->storage_buffers ==
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT
? 0
: nir_var_mem_ssbo),
.callback = agx_mem_vectorize_cb,
});
}
if (agx3_ssbo_vec) {
NIR_PASS(lowered_buf_io, nir, nir_lower_explicit_io, nir_var_mem_ssbo,
hk_buffer_addr_format(rs->storage_buffers,
rs->null_storage_buffer_descriptor,
agx_chip_g17_m5(dev->dev.chip)));
}
bool lowered_buf_io = false;
NIR_PASS(lowered_buf_io, nir, nir_lower_explicit_io, nir_var_mem_ssbo,
hk_buffer_addr_format(rs->storage_buffers,
rs->null_storage_buffer_descriptor,
agx_chip_g17_m5(dev->dev.chip)));
NIR_PASS(lowered_buf_io, nir, nir_lower_explicit_io, nir_var_mem_ubo,
hk_ubo_addr_format(rs->uniform_buffers));

Expand Down Expand Up @@ -3437,7 +3425,7 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir,
*/
struct global_load_lowering global_loads = {
.soft_fault = agx_has_soft_fault(&dev->dev),
.storage_result_select = agx3_ssbo_vec,
.storage_result_select = agx_has_soft_fault(&dev->dev),
};
const bool need_pre_bounds_opt =
!already_preprocessed || lowered_desc || lowered_global_io ||
Expand Down