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
33 changes: 7 additions & 26 deletions src/asahi/clc/asahi_clc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ target_chip(const char *target)
return AGX_CHIP_G15G;
else if (!strcmp(target, "g16g"))
return AGX_CHIP_G16G;
/* G18G compiles as G17G (agx3c) and re-encodes its code as agx3d, exactly
* as the driver's own compiles do (agx_device_key::emit_agx3d). */
else if (!strcmp(target, "g18g"))
return AGX_CHIP_G17G;
return AGX_CHIP_G18G;
else if (!strcmp(target, "g13x"))
return AGX_CHIP_G13X;
else
Expand All @@ -94,26 +92,21 @@ target_is_native_hal200(const char *target)
return agx_chip_native_hal200(target_chip(target));
}

/* Whether a target executes AGX3 code: the native AGX3B path or the M5 AGX3C
* one. */
/* Whether a target executes AGX3 code. */
static bool
target_is_agx3(const char *target)
{
const enum agx_chip chip = target_chip(target);
return agx_chip_native_agx3(chip) || agx_chip_g17_m5(chip);
return agx_encoding_is_agx3(agx_chip_isa_encoding(target_chip(target)));
}

/* Whether a target decompresses spilled compressed colour attachments in place
* (libagx_agx3_decompress, and libagx_reset_compression_metadata for the
* attachments a pass discards): native HAL200, and the chips with private
* Gen10 compression (AGX_CAP_GEN10_2D_COMPRESSION). g18g compiles as G17G
* (target_chip()) but is asked about as itself, which has no Gen10
* compression. */
* Gen10 compression (AGX_CAP_GEN10_2D_COMPRESSION). */
static bool
target_has_spill_decompress(const char *target)
{
const enum agx_chip chip =
!strcmp(target, "g18g") ? AGX_CHIP_G18G : target_chip(target);
const enum agx_chip chip = target_chip(target);
return agx_chip_native_hal200(chip) ||
agx_chip_has_cap(chip, AGX_CAP_GEN10_2D_COMPRESSION);
}
Expand Down Expand Up @@ -377,7 +370,7 @@ target_supports_program(const char *target, const nir_function *func)
*
* G18G launches these through the G17G-family compute profile; it takes
* the qualified list below, without fast clear and with the hardware
* tessellator. target_is_agx3() covers it: its target chip is G17G.
* tessellator.
*
* Tessellation runs as libagx_tess_isoline/tri/quad (libagx_tessellate is
* only the tessellator.h macro choosing one), qualified below for every
Expand Down Expand Up @@ -735,19 +728,7 @@ main(int argc, char **argv)
.has_scratch = target_is_agx3(*target),
};

key.dev.encoding = !strcmp(*target, "g17g")
? AGX_ISA_ENCODING_AGX3C
: target_is_native_agx3(*target)
? AGX_ISA_ENCODING_AGX3B
: AGX_ISA_ENCODING_AGX2;
key.dev.chip = target_chip(*target);

if (!strcmp(*target, "g18g")) {
/* The device key agx_gather_device_key() builds for G18G. */
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G17G;
key.dev.emit_agx3d = true;
}
agx_device_key_set_target(&key.dev, target_chip(*target));

if (has_atomic) {
key.dev.needs_g13x_coherency =
Expand Down
23 changes: 12 additions & 11 deletions src/asahi/compiler/agx_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,17 +511,7 @@ struct agx_device_key {
* the instruction encoding, notably formatted PBE store inputs. */
enum agx_chip chip;

/*
* Binary encoding of the instruction set to emit.
*
* Every part this compiler supports is AGX2, so the packer accepts only
* that and asserts on anything else. Carrying it explicitly is what makes
* a future AGX3 table a dispatch rather than a rewrite, and it means a
* caller that reaches the compiler with an unsupported part is caught in
* the compiler instead of producing an instruction stream for the wrong
* hardware. See agx_chip.h for why the encoding, rather than the chip, is
* the thing that decides.
*/
/* Encoding used by the instruction packer, before any transcoding. */
enum agx_isa_encoding encoding;

/* Does the target GPU need explicit cluster coherency for atomics?
Expand All @@ -547,6 +537,17 @@ struct agx_device_key {
bool emit_agx3d;
};

/* AGX3D uses the AGX3C packer and transcodes its output. Resolve the
* physical target once for both runtime and precompiled shaders. */
static inline void
agx_device_key_set_target(struct agx_device_key *dev, enum agx_chip chip)
{
const enum agx_isa_encoding encoding = agx_chip_isa_encoding(chip);
dev->emit_agx3d = encoding == AGX_ISA_ENCODING_AGX3D;
dev->chip = dev->emit_agx3d ? AGX_CHIP_G17G : chip;
dev->encoding = dev->emit_agx3d ? AGX_ISA_ENCODING_AGX3C : encoding;
}

/*
* Is this a compile for the M6 GPU (G18G)? G18G compiles with the G17G key
* (AGX_ISA_ENCODING_AGX3C, the G17G-family encoding shared by G17G, G17S and
Expand Down
47 changes: 10 additions & 37 deletions src/asahi/compiler/agx_nir_opt_preamble.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,47 +47,20 @@ def_size(nir_def *def, unsigned *size, unsigned *align,
}

static void
def_size_g17p(nir_def *def, unsigned *size, unsigned *align,
def_size_agx3(nir_def *def, unsigned *size, unsigned *align,
nir_preamble_class *class)
{
def_size(def, size, align, class);
nir_intrinsic_instr *intr = nir_def_as_intrinsic_or_null(def);
if (!intr || intr->intrinsic != nir_intrinsic_bindless_image_agx ||
intr->src[0].ssa->bit_size != 64)
return;

/* G17P cannot export texture state, so its native image descriptor is
* carried in general uniforms. The opaque token is 32 bits; reserve the
* 64-bit payload that lower_store_preamble actually exports instead.
* Image-class slot units and the other encodings stay unchanged.
*/
*class = nir_preamble_class_general;
*size = *align = 4;
}

/* The AGX3C constant-program export is a 32-bit uniform COPY: a lone half
* is published as one pair-aligned copy whose upper half is padding (Apple
* widens scalar half preamble results the same way), and no half-width
* copy-to-uniform form is witnessed. Give a scalar 16-bit value its own
* aligned pair so the export never lands on an odd half. */
/* A half result takes a whole word, see widen_half_exports(). */
static void
def_size_agx3b(nir_def *def, unsigned *size, unsigned *align,
nir_preamble_class *class)
{
def_size_g17p(def, size, align, class);
if (*class == nir_preamble_class_general && def->num_components == 1 &&
def->bit_size <= 16) {
*size = 2;
*align = 2;
if (intr && intr->intrinsic == nir_intrinsic_bindless_image_agx &&
intr->src[0].ssa->bit_size == 64) {
/* Reserve the 64-bit descriptor payload exported in general uniforms.
* The opaque image token itself is only 32 bits. */
*class = nir_preamble_class_general;
*size = *align = 4;
}
}

static void
def_size_agx3c(nir_def *def, unsigned *size, unsigned *align,
nir_preamble_class *class)
{
def_size_g17p(def, size, align, class);
/* Widen scalar half exports to a pair-aligned uniform COPY. */
if (*class == nir_preamble_class_general && def->num_components == 1 &&
def->bit_size <= 16) {
*size = 2;
Expand Down Expand Up @@ -1034,7 +1007,7 @@ guard_speculative_load(nir_builder *b, nir_intrinsic_instr *load, void *data)
* register pair. A half exported from the top of a pair, or into the top of a
* word, cannot be packed, and that refusal costs the shader its whole constant
* program. So export every half result as a word with zeroes on top, in the
* slot def_size_agx3b() reserved; the main program still reads the low half.
* slot def_size_agx3() reserved; the main program still reads the low half.
*/
static bool
widen_half_exports(nir_shader *nir)
Expand Down Expand Up @@ -1080,9 +1053,9 @@ agx_nir_opt_preamble(nir_shader *nir, unsigned *sizes, bool g17p,
* invariant ALU and buffer loads remain eligible for the CProg. */
options.no_textures = agx3c;
if (g17p) {
options.def_size = def_size_agx3;
/* The G17P uniform fabs cost is not an M5 witness; keep the
* generic instruction cost there. */
options.def_size = agx3c ? def_size_agx3c : def_size_agx3b;
options.instr_cost_cb = agx3c ? instr_cost_agx3c : instr_cost_g17p;
options.rewrite_cost_cb = agx3c ? rewrite_cost_agx3c : rewrite_cost_g17p;
}
Expand Down
13 changes: 4 additions & 9 deletions src/asahi/lib/agx_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,16 +2075,11 @@ agx_gather_device_key(struct agx_device *dev)
dev->params.num_clusters_total > 1) ||
dev->params.num_dies > 1;

/* G18G compiles as G17G and re-encodes as agx3d; see emit_agx3d. */
const bool g18g = dev->chip == AGX_CHIP_G18G;
const enum agx_chip chip = g18g ? AGX_CHIP_G17G : dev->chip;

return (struct agx_device_key){
.chip = chip,
.encoding = agx_chip_isa_encoding(chip),
struct agx_device_key key = {
.needs_g13x_coherency = u_tristate_make(g13x_coh),
.soft_fault = agx_has_soft_fault(dev),
.emit_agx3d = g18g,
.shader_quad_control = agx_chip_agx3_shader_quad_control(chip),
};
agx_device_key_set_target(&key, dev->chip);
key.shader_quad_control = agx_chip_agx3_shader_quad_control(key.chip);
return key;
}
12 changes: 6 additions & 6 deletions src/gallium/drivers/asahi/agx_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "asahi/lib/agx_abi.h"
#include "asahi/lib/agx3_code_container_core.h"
#include "asahi/lib/agx3_g17p_grid_helper_core.h"
#include "asahi/lib/agx_chip_caps.h"
#include "asahi/lib/agx_g17p_draw_state_upload.h"
#include "asahi/lib/agx_helpers.h"
#include "asahi/lib/agx_m5_va.h"
Expand Down Expand Up @@ -2970,7 +2971,8 @@ agx_compile_nir_tile(struct agx_device *dev, nir_shader *nir,
* and geometry stages run on the GPU too (hk refuses their
* preambles on M5 as well). */
.no_preamble = agx_chip_agx3_path(dev->chip),
.g18_native_mixed = g18_native_mixed && dev->chip == AGX_CHIP_G18G,
.g18_native_mixed = g18_native_mixed &&
agx_chip_has_cap(dev->chip, AGX_CAP_NATIVE_MIXED_EPILOG),
};

if (nir->info.stage == MESA_SHADER_FRAGMENT) {
Expand Down Expand Up @@ -4899,8 +4901,7 @@ agx_fill_precompile_keys(const struct agx_device *dev,
key.fs.zero_lod_bias = so->info.lod_bias_samplers;
/* Match agx_update_fs()'s single-sample key so the precompiled
* variant hits on the first 1x draw instead of recompiling. */
if (agx_chip_native_agx3(dev->chip) || agx_chip_g17_m5(dev->chip) ||
dev->chip == AGX_CHIP_G18G || so->info.needs_sample_count ||
if (agx_chip_agx3_path(dev->chip) || so->info.needs_sample_count ||
so->info.uses_sample_shading)
key.fs.nr_samples = 1;
}
Expand Down Expand Up @@ -5987,8 +5988,7 @@ agx_update_gs(struct agx_context *ctx, const struct pipe_draw_info *info,
struct agx_device *dev = agx_device(ctx->base.screen);
struct agx_uncompiled_shader *fs = ctx->stage[MESA_SHADER_FRAGMENT].shader;
struct asahi_gs_shader_key key = {0};
if (dev->chip == AGX_CHIP_G18G || agx_chip_native_hal200(dev->chip) ||
agx_chip_g17_m5(dev->chip)) {
if (agx_chip_native_hal200(dev->chip) || agx_chip_hal300_path(dev->chip)) {
key.link_uvs = true;
if (fs) {
key.flat_varyings = fs->info.inputs_flat_shaded;
Expand Down Expand Up @@ -6279,7 +6279,7 @@ agx_update_fs(struct agx_batch *batch)
/* Run 1139: the epilog builds the same index-order layout and stores
* exactly what Apple's mixed-format fragments store. */
link_key.epilog.fs.g18_native_mixed =
dev->chip == AGX_CHIP_G18G &&
agx_chip_has_cap(dev->chip, AGX_CAP_NATIVE_MIXED_EPILOG) &&
agx_g18g_native_mixed_mask(&batch->tilebuffer_layout) != 0;

memcpy(&link_key.epilog.fs.blend, &ctx->blend->key,
Expand Down