From 830d16e9f09a02e121048e3f20c4595666cad09c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 6 Feb 2022 17:39:08 -0500 Subject: [PATCH] asahi: Add AGX_PUSH_ARRAY_SIZE_MINUS_1 Required to clamp array indices against the array sizes per the GLSL spec. Metal also does this, implying it's required by the hardware for correct operation. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_compile.h | 5 +++++ src/gallium/drivers/asahi/agx_uniforms.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index a3392faeec1..f1da07427bc 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -47,6 +47,11 @@ enum agx_push_type { /* RGBA blend constant (FP32) */ AGX_PUSH_BLEND_CONST = 8, + /* Array of 16-bit (array_size - 1) for indexed array textures, used to + * lower access to indexed array textures + */ + AGX_PUSH_ARRAY_SIZE_MINUS_1 = 9, + /* Keep last */ AGX_PUSH_NUM_TYPES }; diff --git a/src/gallium/drivers/asahi/agx_uniforms.c b/src/gallium/drivers/asahi/agx_uniforms.c index 13650373732..61668435fad 100644 --- a/src/gallium/drivers/asahi/agx_uniforms.c +++ b/src/gallium/drivers/asahi/agx_uniforms.c @@ -90,6 +90,24 @@ agx_push_location_direct(struct agx_context *ctx, struct agx_push push, sizeof(ctx->blend_color), 8); } + case AGX_PUSH_ARRAY_SIZE_MINUS_1: { + struct agx_stage *st = &ctx->stage[stage]; + unsigned count = st->texture_count; + struct agx_ptr ptr = agx_pool_alloc_aligned(&batch->pool, count * sizeof(uint16_t), 8); + uint16_t *d1 = ptr.cpu; + + for (unsigned i = 0; i < count; ++i) { + unsigned array_size = 1; + + if (st->textures[i]) + array_size = st->textures[i]->base.texture->array_size; + + d1[i] = array_size - 1; + } + + return ptr.gpu; + } + default: unreachable("todo: push more"); }