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
5 changes: 4 additions & 1 deletion src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2295,8 +2295,11 @@ agx_emit_tex(agx_builder *b, nir_tex_instr *instr)
case nir_tex_src_lod:
case nir_tex_src_bias:
lod = index;
/* G11 fragment shaders take automatic LOD from derivatives */
lod_is_zero = nir_src_is_const(instr->src[i].src) &&
nir_src_as_uint(instr->src[i].src) == 0;
nir_src_as_uint(instr->src[i].src) == 0 &&
!(AGX_G11 && b->shader->stage == MESA_SHADER_FRAGMENT &&
instr->op == nir_texop_txl);
break;

case nir_tex_src_lod_bias_min_agx:
Expand Down
2 changes: 2 additions & 0 deletions src/asahi/compiler/agx_nir.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ bool agx_nir_lower_fminmax(struct nir_shader *s);

bool agx_nir_lower_texture_early(struct nir_shader *s, bool support_lod_bias);
bool agx_nir_lower_texture(struct nir_shader *s);
bool agx_nir_g11_coherent_image_atomics(struct nir_shader *s);
bool agx_g11_samplers_from_0(const struct nir_shader *s);
bool agx_nir_lower_multisampled_image_store(struct nir_shader *s);
bool agx_nir_lower_g11_layered_image_store(struct nir_shader *s);
bool agx_nir_needs_texture_crawl(struct nir_instr *instr);
48 changes: 48 additions & 0 deletions src/asahi/compiler/agx_nir_lower_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <stdint.h>
#include "compiler/nir/nir_builder.h"
#include "asahi/genxml/agx_g11.h"
#include "agx_nir.h"
#include "nir.h"
#include "nir_intrinsics.h"
Expand Down Expand Up @@ -150,11 +151,58 @@ pass(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
return true;
}

/*
* G11 plain loads and stores stay in the core's cache: barriers do not make
* them visible to other cores, and the big barriers G13 uses end the thread.
* Atomics are coherent, so coherent 32 and 64-bit accesses become atomics.
*/
static bool
g11_coherent_atomics(struct nir_builder *b, nir_intrinsic_instr *intr,
void *data)
{
bool store = intr->intrinsic == nir_intrinsic_store_global;
if ((!store && intr->intrinsic != nir_intrinsic_load_global) ||
!(nir_intrinsic_access(intr) & ACCESS_COHERENT))
return false;

nir_def *value = store ? intr->src[0].ssa : &intr->def;
unsigned bits = value->bit_size;
if (bits < 32)
return false;

b->cursor = nir_before_instr(&intr->instr);
nir_def *addr = intr->src[store ? 1 : 0].ssa;
nir_def *out[NIR_MAX_VEC_COMPONENTS];

for (unsigned c = 0; c < value->num_components; ++c) {
if (store && !(nir_intrinsic_write_mask(intr) & BITFIELD_BIT(c)))
continue;

nir_def *a = nir_iadd_imm(b, addr, c * (bits / 8));
out[c] = nir_global_atomic(
b, bits, a,
store ? nir_channel(b, value, c) : nir_imm_intN_t(b, 0, bits),
.atomic_op = store ? nir_atomic_op_xchg : nir_atomic_op_iadd);
}

if (store)
nir_instr_remove(&intr->instr);
else
nir_def_replace(&intr->def, nir_vec(b, out, value->num_components));

return true;
}

bool
agx_nir_lower_address(nir_shader *nir)
{
bool progress = false;

/* Precompiled kernels are built without a device key, which atomics need */
if (AGX_G11 && !nir->info.internal)
NIR_PASS(progress, nir, nir_shader_intrinsics_pass, g11_coherent_atomics,
nir_metadata_control_flow, NULL);

/* First, clean up as much as possible. This will make fusing more effective.
*/
do {
Expand Down
Loading
Loading