From d7b35325533ed38f75a73bbce021068b5b2c6fd1 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 7 Apr 2022 11:26:30 -0400 Subject: [PATCH] panfrost: Add helper to emit UBOs Either as uniform remap table entries on Bifrost, or as simple buffer descriptors on Valhall. The underlying hardware is different (and there are compiler changes for load_ubo handling), but the high level UBO upload logic does not have to care about that. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index f2312d2681b..7678511623c 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -1331,6 +1331,35 @@ panfrost_map_constant_buffer_cpu(struct panfrost_context *ctx, unreachable("No constant buffer"); } +/* Emit a single UBO record. On Valhall, UBOs are dumb buffers and are + * implemented with buffer descriptors in the resource table, sized in terms of + * bytes. On Bifrost and older, UBOs have special uniform buffer data + * structure, sized in terms of entries. + */ +static void +panfrost_emit_ubo(void *base, unsigned index, mali_ptr address, size_t size) +{ +#if PAN_ARCH >= 9 + struct mali_buffer_packed *out = base; + + pan_pack(out + index, BUFFER, cfg) { + cfg.size = size; + cfg.address = address; + } +#else + struct mali_uniform_buffer_packed *out = base; + + /* Issue (57) for the ARB_uniform_buffer_object spec says that + * the buffer can be larger than the uniform data inside it, + * so clamp ubo size to what hardware supports. */ + + pan_pack(out + index, UNIFORM_BUFFER, cfg) { + cfg.entries = MIN2(DIV_ROUND_UP(size, 16), 1 << 12); + cfg.pointer = address; + } +#endif +} + static mali_ptr panfrost_emit_const_buf(struct panfrost_batch *batch, enum pipe_shader_type stage,