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 <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14903>
This commit is contained in:
Alyssa Rosenzweig 2022-02-06 17:39:08 -05:00 committed by Marge Bot
parent 7b4ea2fd38
commit 830d16e9f0
2 changed files with 23 additions and 0 deletions

View file

@ -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
};

View file

@ -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");
}