Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
042f087
asahi: read context priority from the context-creation flags
jgoyvaerts Oct 27, 2026
603953b
asahi: virtio: close BOs through vdrm so queued binds reach the host …
jgoyvaerts Oct 27, 2026
c32752c
hk: report host-rejected virtio commands as device loss
jgoyvaerts Oct 27, 2026
0de6ca9
asahi: virtio: keep idle BO caches small
jgoyvaerts Oct 27, 2026
c8c66e7
agx: constrain a cube sample's register LOD, not the whole file
jgoyvaerts Oct 27, 2026
e40f42a
agx: give each cube sample its own CEM scratch
jgoyvaerts Oct 28, 2026
482c365
hk: do not walk the tiles past the render area
jgoyvaerts Oct 27, 2026
c560bf2
hk: merge loads of one uniform buffer record
jgoyvaerts Oct 27, 2026
54e229e
hk: keep multisample fragment variants in the disk cache
jgoyvaerts Oct 28, 2026
9799279
hk: remember in the disk cache that a program emulates border colours
jgoyvaerts Oct 28, 2026
c818781
agx: validate a cube sample's own CEM scratch as four words
DjDeveloperr Oct 29, 2026
be3e990
hk: enable synchronization2 in vulkan-sample-variant-cache
DjDeveloperr Oct 31, 2026
03e88e4
hk: count compiles, not milliseconds, in the warm-cache variant tests
DjDeveloperr Oct 31, 2026
1545fe6
asahi: Release failed context allocations with ralloc
satchlj Nov 3, 2026
0ed5782
asahi: Admit the G15G firmware interface independently of GPU records
satchlj Nov 3, 2026
39a605a
zink: Initialize spare query-start slots in the query test
satchlj Nov 3, 2026
7cedaf8
asahi: Keep T8122 sampler state in the native GPU stream
satchlj Nov 3, 2026
881933b
Merge commit 'refs/diag13j/pr29' into local/c13j-public-prs-20261103
satchlj Nov 3, 2026
f53c802
Merge commit 'refs/diag13j/pr30' into local/c13j-public-prs-20261103
satchlj Nov 3, 2026
60b2135
Merge commit 'refs/diag13j/pr22' into local/c13j-public-prs-20261103
satchlj Nov 3, 2026
c9358a9
asahi: probe HIGH admission and report the effective EGL context prio…
satchlj Nov 3, 2026
5c91161
Fix shader cache identity, shared queue priority and render test orde…
satchlj Nov 4, 2026
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
45 changes: 45 additions & 0 deletions src/asahi/compiler/agx3_lower_texture_publications.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,51 @@ agx3_split_texture_coordinates(agx_context *ctx)
return progress;
}

/* The packer computed every cube sample's CEM in one shared scratch above
* the allocation, eight halves the file had to leave free. A cube array
* stages CEM's face in a seven-bit PACK_SMPIR field
* (agx3_tex_stage_cube_array_layer), so for cube arrays that scratch had to
* sit below half 128 and capped the whole register file at 112 halves.
*
* Give each cube sample its own scratch instead: an undefined four-word
* vector the sample reads, which RA places clear of every value live at the
* sample, below half 128 for a cube array (texture_gpr). Its definition
* emits no code. Run right before RA, so the scratch lives for this one
* instruction. A bias with minimum also packs a word above the allocation
* and keeps the shared scratch, as do scalar-coordinate cube samples. */
bool
agx3_reserve_cube_scratch(agx_context *ctx)
{
if (ctx->key->dev.encoding != AGX_ISA_ENCODING_AGX3B)
return false;

bool progress = false;
agx_foreach_instr_global_safe(ctx, I) {
if (I->op != AGX_OPCODE_TEXTURE_SAMPLE ||
(I->dim != AGX_DIM_CUBE && I->dim != AGX_DIM_CUBE_ARRAY) ||
I->nr_srcs != 6 || I->nr_dests != 1 ||
I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS_MIN)
continue;

agx_builder b = agx_init_builder(ctx, agx_before_instr(I));
agx_index scratch = agx_vec_temp(ctx, AGX_SIZE_32, 4);
agx_instr *collect = agx_collect_to(&b, scratch, 4);
agx_foreach_src(collect, c)
collect->src[c] = agx_undef(AGX_SIZE_32);

agx_instr *sample = agx_alloc_instr(&b, I->op, 1, 7);
memcpy(&sample->op, &I->op, sizeof(*I) - offsetof(agx_instr, op));
sample->nr_srcs = 7;
sample->dest[0] = I->dest[0];
memcpy(sample->src, I->src, 6 * sizeof(agx_index));
sample->src[6] = scratch;
agx_builder_insert(&b.cursor, sample);
agx_remove_instruction(I);
progress = true;
}
return progress;
}

static bool
ssa_preserves_publications(const agx_instr *I)
{
Expand Down
34 changes: 31 additions & 3 deletions src/asahi/compiler/agx3_pack_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,29 @@ agx3_is_staged_3d_bias_min(const agx_instr *I)
!I->offset_xyz;
}

/* A cube sample with its own CEM scratch (agx3_reserve_cube_scratch)
* uses it in place of the shared scratch above the allocation. */
static bool
agx3_cube_own_scratch(const agx_instr *I)
{
return I->op == AGX_OPCODE_TEXTURE_SAMPLE &&
(I->dim == AGX_DIM_CUBE || I->dim == AGX_DIM_CUBE_ARRAY) &&
!I->agx3_cube_scalar_coords && I->nr_srcs == 7 &&
I->src[6].type == AGX_INDEX_REGISTER;
}

static const uint16_t *
agx3_cube_scratch(const agx_instr *I, const uint16_t shared[3],
uint16_t own[3])
{
if (!agx3_cube_own_scratch(I))
return shared;
own[0] = I->src[6].value;
own[1] = I->src[6].value + 4;
own[2] = I->src[6].value + 6;
return own;
}

/* Filtered 2D samples use scoreboard-signalling native staging producers.
* Plain implicit 2D keeps its coordinate layout. Explicit per-lane LOD and
* 2D-array samples stage coordinates into bank 0; their auxiliary scalar is
Expand All @@ -2258,7 +2281,10 @@ agx3_emit_texture_sample(struct util_dynarray *emission,
const bool published = agx_texture_resource(I) != 0;
const bool scalar_cube = I->agx3_cube_scalar_coords;
const bool split = I->agx3_split_coords;
const unsigned source_count = scalar_cube || split ? 8 : 6;
const unsigned source_count = scalar_cube || split ? 8
: agx3_cube_own_scratch(I) ? 7 : 6;
uint16_t own_cem_scratch[3];
cem_scratch = agx3_cube_scratch(I, cem_scratch, own_cem_scratch);
const bool explicit_lod = I->lod_mode == AGX_LOD_MODE_LOD_MIN;
const bool bias_min = I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS_MIN;
const bool gradient_min = I->lod_mode == AGX_LOD_MODE_LOD_GRAD_MIN;
Expand Down Expand Up @@ -9203,7 +9229,7 @@ agx3_pack_binary(agx_context *ctx, struct util_dynarray *emission)
((scan_I->lod_mode == AGX_LOD_MODE_LOD_MIN ||
scan_I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS) &&
scan_I->src[1].type != AGX_INDEX_IMMEDIATE);
has_cube_sample = true;
has_cube_sample |= !agx3_cube_own_scratch(scan_I);
/* So is a cube face packed beside a bias and minimum. */
if (register_lod &&
(scan_I->dim == AGX_DIM_CUBE_ARRAY || bias_min))
Expand Down Expand Up @@ -9850,7 +9876,9 @@ agx3_pack_binary(agx_context *ctx, struct util_dynarray *emission)
((I->lod_mode == AGX_LOD_MODE_LOD_MIN ||
I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS) &&
I->src[1].type != AGX_INDEX_IMMEDIATE);
const uint16_t *scratch = cem_scratch;
uint16_t own_scratch[3];
const uint16_t *scratch =
agx3_cube_scratch(I, cem_scratch, own_scratch);
assert(nd + 5 <= AGX3_SLOT_MAX_REGS);
e->dst[nd++] = scratch[0];
e->dst[nd++] = scratch[0] + 2;
Expand Down
3 changes: 3 additions & 0 deletions src/asahi/compiler/agx_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -10424,6 +10424,9 @@ agx_compile_function_nir_attempt(nir_shader *nir, nir_function_impl *impl,
return false;
}

if (agx3_reserve_cube_scratch(ctx))
agx_validate(ctx, "cube-array scratch");

/* Record provenance before RA can create stack instructions. */
const bool imports_only_before_ra = agx3_cprog_spill_provenance(ctx);
if (ctx->key->dev.encoding == AGX_ISA_ENCODING_AGX3C &&
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 @@ -1210,6 +1210,7 @@ bool agx3_fuse_fma_texture_publications(agx_context *ctx);
bool agx3_lower_scalar_texture_publications(agx_context *ctx);
bool agx3_lower_scalar_cube_coordinates(agx_context *ctx);
bool agx3_split_texture_coordinates(agx_context *ctx);
bool agx3_reserve_cube_scratch(agx_context *ctx);
void agx_lower_uniform_sources(agx_context *ctx);
void agx_opt_cse(agx_context *ctx);
bool agx_opt_collect_split(agx_context *ctx);
Expand Down
46 changes: 39 additions & 7 deletions src/asahi/compiler/agx_register_allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,7 @@ agx3_cube_register_budget(agx_context *ctx)
{
unsigned budget = AGX3B_NUM_REGS;
unsigned alignment = 8;
bool shared_cem = false, packed_layer = false;
agx_foreach_instr_global(ctx, I) {
agx_foreach_ssa_dest(I, d)
alignment = MAX2(alignment,
Expand All @@ -2807,15 +2808,32 @@ agx3_cube_register_budget(agx_context *ctx)
(I->dim != AGX_DIM_CUBE && I->dim != AGX_DIM_CUBE_ARRAY))
continue;

/* A plain cube sample stages a register level or bias with CEM's face
* in a form that encodes the face's high bit, so only the level needs
* a seven-bit register, and RA keeps it there (texture_gpr). A cube
* array stages its face in a seven-bit field, from its own CEM scratch
* (agx3_reserve_cube_scratch) where it has one. The bias with
* minimum also places a packed word above the allocation. */
const bool bias_min = I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS_MIN;
const bool register_lod = bias_min ||
((I->lod_mode == AGX_LOD_MODE_LOD_MIN ||
I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS) &&
I->src[1].type != AGX_INDEX_IMMEDIATE);
/* With its own scratch, nothing of a cube sample sits above the
* allocation but a cube array's packed layer word. Its budget keeps
* the shader at 576 threads: Counter-Strike 2's register-heavy
* cube-array material passes ran faster at 177 halves than at 185
* (512 threads), though they spill a little more. */
const bool own_scratch = !I->agx3_cube_scalar_coords && I->nr_srcs == 7;
budget = MIN2(budget,
(I->dim == AGX_DIM_CUBE_ARRAY || register_lod) ? 112 :
AGX3B_NUM_REGS - 8);
}
((I->dim == AGX_DIM_CUBE_ARRAY && !own_scratch) || bias_min)
? 112 : own_scratch ? AGX3B_NUM_REGS - 16
: AGX3B_NUM_REGS - 8);
shared_cem |= !own_scratch;
packed_layer |= own_scratch && I->src[1].type != AGX_INDEX_IMMEDIATE &&
(I->lod_mode == AGX_LOD_MODE_LOD_MIN ||
I->lod_mode == AGX_LOD_MODE_AUTO_LOD_BIAS);
}
/* The shared CEM scratch and a cube array's prepacked layer word both sit
* above the allocation, below half 191. */
if (shared_cem && packed_layer)
budget = MIN2(budget, AGX3B_NUM_REGS - 16);
return ROUND_DOWN_TO(budget, alignment);
}

Expand Down Expand Up @@ -3270,6 +3288,20 @@ agx_ra_impl(agx_context *ctx, bool disable_remat)
if (I->op == AGX_OPCODE_TEXTURE_SAMPLE && I->shadow &&
I->src[5].type == AGX_INDEX_NORMAL)
BITSET_SET(texture_gpr, I->src[5].value);

/* A cube sample's register level or bias is a seven-bit operand of
* the staging PACK_SMPIR (agx3_tex_stage_cube_lod). */
if (I->op == AGX_OPCODE_TEXTURE_SAMPLE &&
(I->dim == AGX_DIM_CUBE || I->dim == AGX_DIM_CUBE_ARRAY) &&
I->src[1].type == AGX_INDEX_NORMAL)
BITSET_SET(texture_gpr, I->src[1].value);

/* A cube array's own CEM scratch holds its face, a seven-bit operand
* of the staging PACK_SMPIR (agx3_tex_stage_cube_array_layer). */
if (I->op == AGX_OPCODE_TEXTURE_SAMPLE &&
I->dim == AGX_DIM_CUBE_ARRAY && I->nr_srcs == 7 &&
I->src[6].type == AGX_INDEX_NORMAL)
BITSET_SET(texture_gpr, I->src[6].value);
}

if (ctx->key->dev.encoding == AGX_ISA_ENCODING_AGX3C &&
Expand Down
5 changes: 5 additions & 0 deletions src/asahi/compiler/agx_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ agx_read_registers(const agx_context *ctx, const agx_instr *I, unsigned s)
* its existing compare/offset collect. */
return agx_is_null(I->src[s]) ? 0
: 2 * agx_channels(I->src[s]);
} else if (s == 6 && I->op == AGX_OPCODE_TEXTURE_SAMPLE &&
I->nr_srcs == 7) {
/* A cube sample's own CEM scratch (agx3_reserve_cube_scratch): the
* four words the packer computes CEM in. */
return 8;
} else {
return size;
}
Expand Down
1 change: 1 addition & 0 deletions src/asahi/compiler/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ if with_tests
'test/test-agx3-integer-lowering.cpp',
'test/test-agx3-unary-lowering.cpp',
'test/test-agx3-fsel-uniform.cpp',
'test/test-agx3-cube-scratch.cpp',
'test/test-fminmax-constant-denorm.cpp',
'test/test-shared-byte-offsets.cpp',
'test/test-device-load-batches.cpp',
Expand Down
95 changes: 95 additions & 0 deletions src/asahi/compiler/test/test-agx3-cube-scratch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* SPDX-License-Identifier: MIT */
#include <gtest/gtest.h>
#include "agx_builder.h"
#include "agx_test.h"

/* A cube sample gets its own CEM scratch: an undefined four-word vector it
* reads, defined right before it, so RA places the scratch rather than the
* packer stacking it above the allocation. */
static agx_instr *
cube_sample(agx_builder *b, enum agx_dim dim, enum agx_lod_mode lod)
{
agx_index coords = agx_vec_temp(b->shader, AGX_SIZE_32, 4);
return agx_texture_sample_to(b, agx_temp(b->shader, AGX_SIZE_16), coords,
agx_immediate(0), agx_immediate(0),
agx_immediate(0), agx_immediate(0),
agx_null(), dim, lod, 0xf, false, false, false,
AGX_GATHER_NONE, false);
}

TEST(AGX3CubeScratch, CubeSamplesReadAnUndefinedScratchVector)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
cube_sample(b, AGX_DIM_CUBE_ARRAY, AGX_LOD_MODE_AUTO_LOD);
cube_sample(b, AGX_DIM_CUBE, AGX_LOD_MODE_AUTO_LOD);
/* The bias with minimum keeps the shared scratch and the capped file. */
cube_sample(b, AGX_DIM_CUBE_ARRAY, AGX_LOD_MODE_AUTO_LOD_BIAS_MIN);
cube_sample(b, AGX_DIM_2D, AGX_LOD_MODE_AUTO_LOD);

ASSERT_TRUE(agx3_reserve_cube_scratch(b->shader));

agx_instr *collect = NULL;
unsigned samples = 0, own = 0;
agx_foreach_instr_global(b->shader, I) {
if (I->op == AGX_OPCODE_COLLECT) {
collect = I;
continue;
}
ASSERT_EQ(I->op, AGX_OPCODE_TEXTURE_SAMPLE);
++samples;
const bool expect_own = (I->dim == AGX_DIM_CUBE ||
I->dim == AGX_DIM_CUBE_ARRAY) &&
I->lod_mode != AGX_LOD_MODE_AUTO_LOD_BIAS_MIN;
if (!expect_own) {
EXPECT_EQ(I->nr_srcs, 6u);
continue;
}
++own;
ASSERT_EQ(I->nr_srcs, 7u);
ASSERT_NE(collect, nullptr);
EXPECT_EQ(collect->dest[0].value, I->src[6].value);
EXPECT_EQ(agx_index_size_16(I->src[6]), 8u);
ASSERT_EQ(collect->nr_srcs, 4u);
agx_foreach_src(collect, s)
EXPECT_EQ(collect->src[s].type, AGX_INDEX_UNDEF);
collect = NULL;
}
EXPECT_EQ(samples, 4u);
EXPECT_EQ(own, 2u);

/* RA may be retried after a failed allocation: no second scratch. */
EXPECT_FALSE(agx3_reserve_cube_scratch(b->shader));
ralloc_free(mem);
}

/* A cube sample that reads its scratch is valid IR: the scratch source is
* four words wide. agx_validate checks only in builds with assertions. */
TEST(AGX3CubeScratch, ScratchSourceValidates)
{
void *mem = ralloc_context(NULL);
agx_shader_key key = {};
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
agx_builder *b = agx_test_builder(mem);
b->shader->key = &key;
for (unsigned array = 0; array < 2; ++array) {
const unsigned comps = 3 + array;
agx_index coords = agx_vec_temp(b->shader, AGX_SIZE_32, comps);
agx_instr *collect = agx_collect_to(b, coords, comps);
agx_foreach_src(collect, c)
collect->src[c] = agx_undef(AGX_SIZE_32);
agx_texture_sample_to(b, agx_vec_temp(b->shader, AGX_SIZE_16, 4), coords,
agx_immediate(0), agx_immediate(0),
agx_immediate(0), agx_immediate(0), agx_null(),
array ? AGX_DIM_CUBE_ARRAY : AGX_DIM_CUBE,
AGX_LOD_MODE_AUTO_LOD, 0xf, false, false, false,
AGX_GATHER_NONE, false);
}
agx_validate(b->shader, "cube sample test shader");
ASSERT_TRUE(agx3_reserve_cube_scratch(b->shader));
agx_validate(b->shader, "cube-array scratch");
ralloc_free(mem);
}
22 changes: 20 additions & 2 deletions src/asahi/drm-shim/asahi_noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,9 +1116,22 @@ asahi_ioctl_noop(int fd, unsigned long request, void *arg)
static int
asahi_ioctl_queue_create(int fd, unsigned long request, void *arg)
{
const struct drm_asahi_queue_create *create = arg;

struct drm_asahi_queue_create *create = arg;
static uint32_t next_queue_id = 1;

/* Model authorization and a credential change after the screen probe. */
static unsigned high_requests;
const char *policy = getenv("ASAHI_SHIM_HIGH_PRIORITY");
if (create->priority == DRM_ASAHI_PRIORITY_HIGH) {
high_requests++;
if (policy && (!strcmp(policy, "deny") ||
(!strcmp(policy, "once") && high_requests > 1))) {
errno = EACCES;
return -1;
}
}
shim_usc_exec_base = create->usc_exec_base;
create->queue_id = next_queue_id++;
return 0;
}

Expand Down Expand Up @@ -1323,6 +1336,11 @@ asahi_ioctl_get_param(int fd, unsigned long request, void *arg)
size_t size = MIN2((size_t)gp->size, sizeof(struct drm_asahi_params_global));
struct drm_asahi_params_global params = *shim_params();
params.features = shim_features();
if (shim_params() == &params_g15g &&
shim_env_on("ASAHI_SHIM_G15G_HAL200")) {
params.gpu_hal_generation = DRM_ASAHI_GPU_HAL_200;
params.vm_end = UINT64_C(0x3ffffff8000);
}
const char *command_limit = getenv("ASAHI_SHIM_COMMAND_LIMIT");
if (command_limit) {
unsigned limit = strtoul(command_limit, NULL, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/asahi/lib/agx_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void
agx_bo_cache_start_idle_trim(struct agx_device *dev)
{
#ifdef HAVE_LIBDRM
if (dev->ops.bo_free != agx_drm_bo_close)
if (dev->ops.bo_free != agx_drm_bo_close && !dev->is_virtio)
return;
if (mtx_init(&dev->bo_cache.idle_lock, mtx_plain) != thrd_success)
return;
Expand Down
Loading