From 7d3c48f131ec84aa759a6290a20e2b0c02ad8834 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sun, 16 Feb 2020 17:01:02 -0500 Subject: [PATCH] panfrost: Debitfieldize mali_uniform_buffer_meta It fits snugly in a u64, just give a macro for direct computation rather than fudging around with bitfields. Not sure if this actually matters with well-optimized compilers but it makes the code subjectively cleaner so it's worth it for that if nothing else. Signed-off-by: Alyssa Rosenzweig Tested-by: Marge Bot Part-of: --- src/gallium/drivers/panfrost/pan_context.c | 16 ++++-------- src/panfrost/include/panfrost-job.h | 29 ++++++++++++---------- src/panfrost/pandecode/decode.c | 8 +++--- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 60ccf66f841..6f45901ee81 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -1097,12 +1097,11 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) unsigned ubo_count = panfrost_ubo_count(ctx, i); assert(ubo_count >= 1); - size_t sz = sizeof(struct mali_uniform_buffer_meta) * ubo_count; - struct mali_uniform_buffer_meta ubos[PAN_MAX_CONST_BUFFERS]; + size_t sz = sizeof(uint64_t) * ubo_count; + uint64_t ubos[PAN_MAX_CONST_BUFFERS]; /* Upload uniforms as a UBO */ - ubos[0].size = MALI_POSITIVE((2 + uniform_count)); - ubos[0].ptr = transfer.gpu >> 2; + ubos[0] = MALI_MAKE_UBO(2 + uniform_count, transfer.gpu); /* The rest are honest-to-goodness UBOs */ @@ -1114,9 +1113,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) if (!enabled || empty) { /* Stub out disabled UBOs to catch accesses */ - - ubos[ubo].size = 0; - ubos[ubo].ptr = 0xDEAD0000; + ubos[ubo] = MALI_MAKE_UBO(0, 0xDEAD0000); continue; } @@ -1124,10 +1121,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) unsigned bytes_per_field = 16; unsigned aligned = ALIGN_POT(usz, bytes_per_field); - unsigned fields = aligned / bytes_per_field; - - ubos[ubo].size = MALI_POSITIVE(fields); - ubos[ubo].ptr = gpu >> 2; + ubos[ubo] = MALI_MAKE_UBO(aligned / bytes_per_field, gpu); } mali_ptr ubufs = panfrost_upload_transient(batch, ubos, sz); diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index 940b5860e95..405440146e6 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -876,20 +876,23 @@ struct mali_attr_meta { /* ORed into an MFBD address to specify the fbx section is included */ #define MALI_MFBD_TAG_EXTRA (0x2) -struct mali_uniform_buffer_meta { - /* This 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. - */ - u64 size : 10; +/* 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. + */ - /* This 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. - */ - mali_ptr ptr : 64 - 10; -}; +#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 diff --git a/src/panfrost/pandecode/decode.c b/src/panfrost/pandecode/decode.c index 97c2a255f31..0a75e66351f 100644 --- a/src/panfrost/pandecode/decode.c +++ b/src/panfrost/pandecode/decode.c @@ -1783,15 +1783,15 @@ static void pandecode_uniform_buffers(mali_ptr pubufs, int ubufs_count, int job_no) { struct pandecode_mapped_memory *umem = pandecode_find_mapped_gpu_mem_containing(pubufs); - struct mali_uniform_buffer_meta *PANDECODE_PTR_VAR(ubufs, umem, pubufs); + uint64_t *PANDECODE_PTR_VAR(ubufs, umem, pubufs); for (int i = 0; i < ubufs_count; i++) { - unsigned size = (ubufs[i].size + 1) * 16; - mali_ptr addr = ubufs[i].ptr << 2; + unsigned size = (ubufs[i] & ((1 << 10) - 1)) * 16; + mali_ptr addr = (ubufs[i] >> 10) << 2; pandecode_validate_buffer(addr, size); - char *ptr = pointer_as_memory_reference(ubufs[i].ptr << 2); + char *ptr = pointer_as_memory_reference(addr); pandecode_log("ubuf_%d[%u] = %s;\n", i, size, ptr); free(ptr); } -- 2.30.2