[Mesa-dev] [RFC 3/3] u_vbuf: use single vertex buffer if needed

Christian Gmeiner christian.gmeiner at gmail.com
Sat Jun 11 19:21:53 UTC 2016


From: "Wladimir J. van der Laan" <laanwj at gmail.com>

CONST, VERTEX and INSTANCE attributes into one vertex buffer if
necessary due to hardware constraints.

Signed-off-by: Wladimir J. van der Laan <laanwj at gmail.com>
---
 src/gallium/auxiliary/util/u_vbuf.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c
index 464c279..d35f3b0 100644
--- a/src/gallium/auxiliary/util/u_vbuf.c
+++ b/src/gallium/auxiliary/util/u_vbuf.c
@@ -539,25 +539,45 @@ u_vbuf_translate_find_free_vb_slots(struct u_vbuf *mgr,
    uint32_t unused_vb_mask =
       (mgr->ve->incompatible_vb_mask_all | mgr->incompatible_vb_mask |
       ~mgr->enabled_vb_mask | extra_free_vb_mask) & mgr->allowed_vb_mask;
+   uint32_t unused_vb_mask_temp;
+   boolean insufficient_buffers = false;
+
+   /* No vertex buffers available at all */
+   if(!unused_vb_mask)
+      return FALSE;
 
    memset(fallback_vbs, ~0, sizeof(fallback_vbs));
 
    /* Find free slots for each type if needed. */
+   unused_vb_mask_temp = unused_vb_mask;
    for (type = 0; type < VB_NUM; type++) {
       if (mask[type]) {
          uint32_t index;
 
-         if (!unused_vb_mask) {
-            return FALSE;
+         if (!unused_vb_mask_temp) {
+            insufficient_buffers = TRUE;
+            break;
          }
 
-         index = ffs(unused_vb_mask) - 1;
+         index = ffs(unused_vb_mask_temp) - 1;
          fallback_vbs[type] = index;
-         unused_vb_mask &= ~(1 << index);
+         unused_vb_mask_temp &= ~(1 << index);
          /*printf("found slot=%i for type=%i\n", index, type);*/
       }
    }
 
+   if (insufficient_buffers) {
+      /* not enough vbs for all types supported by the hardware, they will have to
+       * share one buffer */
+      uint32_t index = ffs(unused_vb_mask) - 1;
+
+      /* When sharing one vertex buffer use per-vertex frequency for everything. */
+      fallback_vbs[VB_VERTEX] = index;
+      mask[VB_VERTEX] = mask[VB_VERTEX] | mask[VB_CONST] | mask[VB_INSTANCE];
+      mask[VB_CONST] = 0;
+      mask[VB_INSTANCE] = 0;
+   }
+
    for (type = 0; type < VB_NUM; type++) {
       if (mask[type]) {
          mgr->dirty_real_vb_mask |= 1 << fallback_vbs[type];
-- 
2.5.5



More information about the mesa-dev mailing list