panfrost: XMLify UBOs
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 6 Aug 2020 01:39:25 +0000 (21:39 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Thu, 13 Aug 2020 06:55:16 +0000 (08:55 +0200)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6195>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/bifrost/test/bi_submit.c
src/panfrost/include/panfrost-job.h
src/panfrost/lib/midgard.xml

index d2091e6f07b92ef91ddc04acd9ef18195eb2e872..8376cafd2f1e7882820722c228a8db70601c68ba 100644 (file)
@@ -1251,12 +1251,20 @@ panfrost_emit_const_buf(struct panfrost_batch *batch,
         unsigned ubo_count = panfrost_ubo_count(ctx, stage);
         assert(ubo_count >= 1);
 
         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 */
 
         /* 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 */
 
 
         /* 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) {
                 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;
                 }
 
                         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->uniforms = transfer.gpu;
-        postfix->uniform_buffers = ubufs;
+        postfix->uniform_buffers = ubos.gpu;
 
         buf->dirty_mask = 0;
 }
 
         buf->dirty_mask = 0;
 }
index a131adda55a7d118cbd26b8bd216fd90424abb3d..be43f95dac629f414ca358a57582976c428ff367 100644 (file)
@@ -154,9 +154,11 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog,
                 .size = 1024
         };
 
                 .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? */
         memcpy(var->cpu, &vmeta, sizeof(vmeta));
 
         vmeta.unknown1 = 0x2; /* XXX: only attrib? */
index 8a9fb6854c170772ea22e0ce3e969ce6c7c4e872..6d409a5ecb7c9ddf76692276d1ced40883281577 100644 (file)
@@ -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)
 
 /* 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.
 /* 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.
index f6df1d555801cc1a1247c486904f9672e49027db..54493a444aadc941dc228c769a6da62110c1fb52 100644 (file)
     <value name="Mirrored Clamp to Border" value="15"/>
   </enum>
 
     <value name="Mirrored Clamp to Border" value="15"/>
   </enum>
 
+  <struct name="Uniform Buffer">
+    <field name="Entries" size="12" start="0" type="uint" modifier="minus(1)"/>
+    <field name="Pointer" size="52" start="12" type="address" modifier="shr(4)" element="16" count="Entries"/>
+  </struct>
+
   <struct name="Viewport">
     <field name="Minimum X" size="32" start="0:0" default="-INFINITY" type="float"/>
     <field name="Minimum Y" size="32" start="1:0" default="-INFINITY" type="float"/>
   <struct name="Viewport">
     <field name="Minimum X" size="32" start="0:0" default="-INFINITY" type="float"/>
     <field name="Minimum Y" size="32" start="1:0" default="-INFINITY" type="float"/>