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 <alyssa.rosenzweig@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3838>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3838>
This commit is contained in:
Alyssa Rosenzweig 2020-02-16 17:01:02 -05:00 committed by Marge Bot
parent 027944c7c8
commit 7d3c48f131
3 changed files with 25 additions and 28 deletions

View File

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

View File

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

View File

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