From 44d79d39b6bdbc87e821de55e51d5cdd04e4ccb4 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 1 Sep 2022 23:08:26 -0400 Subject: [PATCH] agx: Defeature indirect vbufs vb_mask can include garbage vbufs, we can't rely on it. This will prevent a regression when switching to u_blitter based clears. This is also simpler and shrinks the VS shader key so all in all a good thing. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.c | 5 +--- src/asahi/compiler/agx_compile.h | 6 ++++- src/asahi/compiler/agx_compiler.h | 3 +++ src/asahi/compiler/agx_uniforms.c | 30 ++++++++++++++++++++++++ src/gallium/drivers/asahi/agx_state.c | 4 +--- src/gallium/drivers/asahi/agx_uniforms.c | 20 +++++++--------- 6 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 42e56d26b84..68cf0544521 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -311,10 +311,7 @@ agx_emit_load_attr(agx_builder *b, agx_index *dests, nir_intrinsic_instr *instr) agx_index offset = agx_imad(b, element_id, shifted_stride, src_offset, 0); /* Each VBO has a 64-bit = 4 x 16-bit address, lookup the base address as a sysval */ - unsigned num_vbos = key->vs.num_vbufs; - unsigned base_length = (num_vbos * 4); - agx_index base = agx_indexed_sysval(b->shader, - AGX_PUSH_VBO_BASES, AGX_SIZE_64, buf * 4, base_length); + agx_index base = agx_vbo_base(b->shader, buf); /* Load the data */ assert(instr->num_components <= 4); diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index ced53da362b..9ebb3df5496 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -33,11 +33,13 @@ enum agx_push_type { * 16-bit sizes for optional bounds checking (SIZES) */ AGX_PUSH_UBO_BASES, AGX_PUSH_UBO_SIZES, - AGX_PUSH_VBO_BASES, AGX_PUSH_VBO_SIZES, AGX_PUSH_SSBO_BASES, AGX_PUSH_SSBO_SIZES, + /* 64-bit VBO base pointer */ + AGX_PUSH_VBO_BASE, + /* Push the attached constant memory */ AGX_PUSH_CONSTANTS, @@ -79,6 +81,8 @@ struct agx_push { uint16_t ubo; uint16_t offset; } ubo_data; + + uint32_t vbo; }; }; diff --git a/src/asahi/compiler/agx_compiler.h b/src/asahi/compiler/agx_compiler.h index 7dc732c23e8..cd315379a7d 100644 --- a/src/asahi/compiler/agx_compiler.h +++ b/src/asahi/compiler/agx_compiler.h @@ -696,6 +696,9 @@ agx_index agx_indexed_sysval(agx_context *ctx, enum agx_push_type type, enum agx_size size, unsigned index, unsigned length); +agx_index +agx_vbo_base(agx_context *ctx, unsigned vbo); + /* Routines defined for AIR */ void agx_print_instr(agx_instr *I, FILE *fp); diff --git a/src/asahi/compiler/agx_uniforms.c b/src/asahi/compiler/agx_uniforms.c index 7f7d0255fbc..3c072a4f898 100644 --- a/src/asahi/compiler/agx_uniforms.c +++ b/src/asahi/compiler/agx_uniforms.c @@ -62,3 +62,33 @@ agx_indexed_sysval(agx_context *ctx, enum agx_push_type type, return agx_uniform(base + index, size); } + +agx_index +agx_vbo_base(agx_context *ctx, unsigned vbo) +{ + /* Check if we already pushed */ + for (unsigned i = 0; i < ctx->out->push_ranges; ++i) { + struct agx_push push = ctx->out->push[i]; + + if (push.type == AGX_PUSH_VBO_BASE && push.vbo == vbo) { + return agx_uniform(push.base, AGX_SIZE_64); + } + } + + /* Otherwise, push */ + assert(ctx->out->push_ranges < AGX_MAX_PUSH_RANGES); + + ctx->push_base = ALIGN_POT(ctx->push_base, 4); + + unsigned base = ctx->push_base; + ctx->push_base += 4; + + ctx->out->push[ctx->out->push_ranges++] = (struct agx_push) { + .type = AGX_PUSH_VBO_BASE, + .base = base, + .length = 4, + .vbo = vbo, + }; + + return agx_uniform(base, AGX_SIZE_64); +} diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index bded47a4938..02d1237540c 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1083,9 +1083,7 @@ agx_update_shader(struct agx_context *ctx, struct agx_compiled_shader **out, static bool agx_update_vs(struct agx_context *ctx) { - struct agx_vs_shader_key key = { - .num_vbufs = util_last_bit(ctx->vb_mask), - }; + struct agx_vs_shader_key key = { 0 }; memcpy(key.attributes, ctx->attributes, sizeof(key.attributes[0]) * AGX_MAX_ATTRIBS); diff --git a/src/gallium/drivers/asahi/agx_uniforms.c b/src/gallium/drivers/asahi/agx_uniforms.c index 61668435fad..f406a799d6b 100644 --- a/src/gallium/drivers/asahi/agx_uniforms.c +++ b/src/gallium/drivers/asahi/agx_uniforms.c @@ -66,21 +66,19 @@ agx_push_location_direct(struct agx_context *ctx, struct agx_push push, return ptr.gpu; } - case AGX_PUSH_VBO_BASES: { - unsigned count = util_last_bit(ctx->vb_mask); - struct agx_ptr ptr = agx_pool_alloc_aligned(&batch->pool, count * sizeof(uint64_t), 8); - uint64_t *addresses = ptr.cpu; + case AGX_PUSH_VBO_BASE: { + struct agx_ptr ptr = agx_pool_alloc_aligned(&batch->pool, sizeof(uint64_t), 8); + uint64_t *address = ptr.cpu; - u_foreach_bit(i, ctx->vb_mask) { - struct pipe_vertex_buffer vb = ctx->vertex_buffers[i]; - assert(!vb.is_user_buffer); + assert(ctx->vb_mask & BITFIELD_BIT(push.vbo) && "oob"); - struct agx_bo *bo = agx_resource(vb.buffer.resource)->bo; - agx_batch_add_bo(batch, bo); + struct pipe_vertex_buffer vb = ctx->vertex_buffers[push.vbo]; + assert(!vb.is_user_buffer); - addresses[i] = bo->ptr.gpu + vb.buffer_offset; - } + struct agx_bo *bo = agx_resource(vb.buffer.resource)->bo; + agx_batch_add_bo(batch, bo); + *address = bo->ptr.gpu + vb.buffer_offset; return ptr.gpu; }