From fa949678c1985de2d728691ffc177f1054dc35c8 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 5 Aug 2020 21:39:25 -0400 Subject: [PATCH] panfrost: XMLify UBOs Signed-off-by: Alyssa Rosenzweig Reviewed-by: Tomeu Vizoso Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 33 +++++++++++--------- src/panfrost/bifrost/test/bi_submit.c | 6 ++-- src/panfrost/include/panfrost-job.h | 18 ----------- src/panfrost/lib/midgard.xml | 5 +++ 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index d2091e6f07b..8376cafd2f1 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -1251,12 +1251,20 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, unsigned ubo_count = panfrost_ubo_count(ctx, stage); assert(ubo_count >= 1); - size_t sz = sizeof(uint64_t) * ubo_count; - uint64_t ubos[PAN_MAX_CONST_BUFFERS]; - int uniform_count = ss->uniform_count; + size_t sz = MALI_UNIFORM_BUFFER_LENGTH * ubo_count; + struct panfrost_transfer ubos = panfrost_pool_alloc(&batch->pool, sz); + uint64_t *ubo_ptr = (uint64_t *) ubos.cpu; /* Upload uniforms as a UBO */ - ubos[0] = MALI_MAKE_UBO(2 + uniform_count, transfer.gpu); + + if (ss->uniform_count) { + pan_pack(ubo_ptr, UNIFORM_BUFFER, cfg) { + cfg.entries = ss->uniform_count; + cfg.pointer = transfer.gpu; + } + } else { + *ubo_ptr = 0; + } /* The rest are honest-to-goodness UBOs */ @@ -1266,22 +1274,19 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, bool empty = usz == 0; if (!enabled || empty) { - /* Stub out disabled UBOs to catch accesses */ - ubos[ubo] = MALI_MAKE_UBO(0, 0xDEAD0000); + ubo_ptr[ubo] = 0; continue; } - mali_ptr gpu = panfrost_map_constant_buffer_gpu(batch, stage, - buf, ubo); - - unsigned bytes_per_field = 16; - unsigned aligned = ALIGN_POT(usz, bytes_per_field); - ubos[ubo] = MALI_MAKE_UBO(aligned / bytes_per_field, gpu); + pan_pack(ubo_ptr + ubo, UNIFORM_BUFFER, cfg) { + cfg.entries = DIV_ROUND_UP(usz, 16); + cfg.pointer = panfrost_map_constant_buffer_gpu(batch, + stage, buf, ubo); + } } - mali_ptr ubufs = panfrost_pool_upload(&batch->pool, ubos, sz); postfix->uniforms = transfer.gpu; - postfix->uniform_buffers = ubufs; + postfix->uniform_buffers = ubos.gpu; buf->dirty_mask = 0; } diff --git a/src/panfrost/bifrost/test/bi_submit.c b/src/panfrost/bifrost/test/bi_submit.c index a131adda55a..be43f95dac6 100644 --- a/src/panfrost/bifrost/test/bi_submit.c +++ b/src/panfrost/bifrost/test/bi_submit.c @@ -154,9 +154,11 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog, .size = 1024 }; - uint64_t my_ubo = MALI_MAKE_UBO(64, ubo->gpu + 1024); + pan_pack(ubo->cpu, UNIFORM_BUFFER, cfg) { + cfg.entries = 64; + cfg.pointer = ubo->gpu + 1024; + } - memcpy(ubo->cpu, &my_ubo, sizeof(my_ubo)); memcpy(var->cpu, &vmeta, sizeof(vmeta)); vmeta.unknown1 = 0x2; /* XXX: only attrib? */ diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 8a9fb6854c1..6d409a5ecb7 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -907,24 +907,6 @@ struct mali_attr_meta { /* ORed into an MFBD address to specify the fbx section is included */ #define MALI_MFBD_TAG_EXTRA (0x2) -/* Uniform buffer objects are 64-bit fields divided as: - * - * u64 size : 10; - * mali_ptr ptr : 64 - 10; - * - * The size is actually the size minus 1 (MALI_POSITIVE), in units of 16 bytes. - * This gives a maximum of 2^14 bytes, which just so happens to be the GL - * minimum-maximum for GL_MAX_UNIFORM_BLOCK_SIZE. - * - * The pointer is missing the bottom 2 bits and top 8 bits. The top 8 bits - * should be 0 for userspace pointers, according to - * https://lwn.net/Articles/718895/. By reusing these bits, we can make each - * entry in the table only 64 bits. - */ - -#define MALI_MAKE_UBO(elements, ptr) \ - (MALI_POSITIVE((elements)) | (((ptr) >> 2) << 10)) - /* On Bifrost, these fields are the same between the vertex and tiler payloads. * They also seem to be the same between Bifrost and Midgard. They're shared in * fused payloads. diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml index f6df1d55580..54493a444aa 100644 --- a/src/panfrost/lib/midgard.xml +++ b/src/panfrost/lib/midgard.xml @@ -60,6 +60,11 @@ + + + + + -- 2.30.2