[Mesa-dev] [PATCH 3/4] i965/drm: Searching for a cached buffer for reuse

James Xiong james.xiong at intel.com
Sat May 5 00:56:04 UTC 2018


From: "Xiong, James" <james.xiong at intel.com>

Now that a bucket contains cached buffers with different sizes, go
through its list and search for a cached buffer with enough size.

Signed-off-by: Xiong, James <james.xiong at intel.com>
---
 src/mesa/drivers/dri/i965/brw_bufmgr.c | 21 +++++++++++++++------
 src/util/list.h                        |  5 +++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 6a9b005..5235aa6 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -281,7 +281,7 @@ cached_bo_for_size(struct brw_bufmgr *bufmgr,
    assert(!(busy && zeroed));
 
    if(bucket != NULL && !list_empty(&bucket->head)) {
-      struct brw_bo *bo;
+      struct brw_bo *bo, *temp_bo;
 retry:
       bo = NULL;
 
@@ -292,8 +292,13 @@ retry:
           * asked us to zero the buffer, we don't want this
           * because we are going to mmap it.
           */
-         bo = LIST_ENTRY(struct brw_bo, bucket->head.prev, head);
-         list_del(&bo->head);
+         LIST_FOR_EACH_ENTRY_REV(temp_bo, &bucket->head, head) {
+            if (temp_bo->size >= size) {
+               bo = temp_bo;
+               list_del(&bo->head);
+               break;
+            }
+         }
       } else {
          /* For non-render-target BOs (where we're probably
           * going to map it first thing in order to fill it
@@ -302,9 +307,13 @@ retry:
           * allocating a new buffer is probably faster than
           * waiting for the GPU to finish.
           */
-         bo = LIST_ENTRY(struct brw_bo, bucket->head.next, head);
-         if (!brw_bo_busy(bo)) {
-            list_del(&bo->head);
+         LIST_FOR_EACH_ENTRY(temp_bo, &bucket->head, head) {
+            if (temp_bo->size >= size &&
+                !brw_bo_busy(temp_bo)) {
+               bo = temp_bo;
+               list_del(&bo->head);
+               break;
+            }
          }
       }
 
diff --git a/src/util/list.h b/src/util/list.h
index 6edb750..9362072 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -189,6 +189,11 @@ static inline void list_validate(struct list_head *list)
 	&pos->member != (head);						\
 	pos = container_of(pos->member.next, pos, member))
 
+#define LIST_FOR_EACH_ENTRY_REV(pos, head, member)                      \
+   for (pos = NULL, pos = container_of((head)->prev, pos, member);      \
+        &pos->member != (head);                                         \
+        pos = container_of(pos->member.prev, pos, member))
+
 #define LIST_FOR_EACH_ENTRY_SAFE(pos, storage, head, member)	\
    for (pos = NULL, pos = container_of((head)->next, pos, member),	\
 	storage = container_of(pos->member.next, pos, member);	\
-- 
2.7.4



More information about the mesa-dev mailing list