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
18 changes: 10 additions & 8 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -15140,13 +15140,15 @@ agx3_order_fragment_device_loads(agx_context *ctx)
static bool
agx3_m5_word_load(const agx_instr *I)
{
/* Immediate indices are left to agx3_order_fragment_device_loads */
return I->op == AGX_OPCODE_DEVICE_LOAD && I->nr_dests == 1 &&
I->nr_srcs == 2 && I->src[1].type == AGX_INDEX_NORMAL &&
I->format == AGX_FORMAT_I32 && I->mask == 1 &&
!I->memory_is_packed && I->dest[0].type == AGX_INDEX_NORMAL &&
!I->dest[0].memory && I->dest[0].size == AGX_SIZE_32 &&
agx_channels(I->dest[0]) == 1;
/* Immediate indices are left to agx3_order_fragment_device_loads.
* Coherent also covers SPIR-V volatile loads, which may not be combined.
*/
return I->op == AGX_OPCODE_DEVICE_LOAD && !I->coherent &&
I->nr_dests == 1 && I->nr_srcs == 2 &&
I->src[1].type == AGX_INDEX_NORMAL && I->format == AGX_FORMAT_I32 &&
I->mask == 1 && !I->memory_is_packed &&
I->dest[0].type == AGX_INDEX_NORMAL && !I->dest[0].memory &&
I->dest[0].size == AGX_SIZE_32 && agx_channels(I->dest[0]) == 1;
}

static bool
Expand Down Expand Up @@ -15264,7 +15266,7 @@ agx3_merge_word_window(agx_context *ctx, agx_instr **window,
return progress;
}

static bool
bool
agx3_merge_m5_word_loads(agx_context *ctx)
{
/* Vertex and compute shaders often run just below an occupancy step,
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 @@ -1404,6 +1404,7 @@ void agx_lower_uniform_sources(agx_context *ctx);
void agx3_lower_m5_live_scalar_lods(agx_context *ctx);
void agx_lower_agx3_fma_sources(agx_context *ctx);
void agx_lower_agx3_immediates(agx_context *ctx);
bool agx3_merge_m5_word_loads(agx_context *ctx);
bool agx_lower_agx3_cf_constants(agx_context *ctx);
void agx_opt_cse(agx_context *ctx);
bool agx_opt_collect_split(agx_context *ctx);
Expand Down
70 changes: 70 additions & 0 deletions src/asahi/compiler/test/test-agx3-vision-opts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,3 +3104,73 @@ TEST(AGX3VisionOpts, Wave8SwarW8ByteSum)
ralloc_free(b.shader);
}
}

TEST(AGX3VisionOpts, MergeWordLoadsSkipsCoherent)
{
auto make_load = [](agx_builder *b, agx_index base, agx_index idx,
int32_t byte_off, bool coherent) {
agx_index dst = agx_temp(b->shader, AGX_SIZE_32);
agx_instr *I = agx_device_load_to(b, dst, base, idx, AGX_FORMAT_I32, 1,
2, coherent);
I->memory_byte_offset = byte_off;
return dst;
};

/* Coherent (including SPIR-V volatile) loads must never be merged. */
{
void *mem = ralloc_context(NULL);
agx_builder *b = agx_test_builder(mem);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
b->shader->key = &key;
b->shader->stage = MESA_SHADER_FRAGMENT;

agx_index base = agx_uniform(0, AGX_SIZE_64);
agx_index idx = agx_mov_imm(b, 32, 3);
agx_index l0 = make_load(b, base, idx, 0, true);
agx_index l1 = make_load(b, base, idx, 4, true);
agx_unit_test(b, agx_iadd(b, l0, l1, 0));

EXPECT_FALSE(agx3_merge_m5_word_loads(b->shader));

unsigned loads = 0;
agx_foreach_instr_global(b->shader, I) {
if (I->op == AGX_OPCODE_DEVICE_LOAD) {
loads++;
EXPECT_EQ(I->mask, 1u);
EXPECT_TRUE(I->coherent);
}
}
EXPECT_EQ(loads, 2u);
ralloc_free(mem);
}

/* Non-coherent consecutive scalar loads on AGX3C fragment still merge. */
{
void *mem = ralloc_context(NULL);
agx_builder *b = agx_test_builder(mem);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
b->shader->key = &key;
b->shader->stage = MESA_SHADER_FRAGMENT;

agx_index base = agx_uniform(0, AGX_SIZE_64);
agx_index idx = agx_mov_imm(b, 32, 3);
agx_index l0 = make_load(b, base, idx, 0, false);
agx_index l1 = make_load(b, base, idx, 4, false);
agx_unit_test(b, agx_iadd(b, l0, l1, 0));

EXPECT_TRUE(agx3_merge_m5_word_loads(b->shader));

unsigned loads = 0;
agx_foreach_instr_global(b->shader, I) {
if (I->op == AGX_OPCODE_DEVICE_LOAD) {
loads++;
EXPECT_EQ(I->mask, 0x3u);
EXPECT_FALSE(I->coherent);
}
}
EXPECT_EQ(loads, 1u);
ralloc_free(mem);
}
}