Mesa (master): r600g: Fix bug when adding new items to the compute memory pool

Tom Stellard tstellar at kemper.freedesktop.org
Mon Oct 1 16:11:47 UTC 2012


Module: Mesa
Branch: master
Commit: 44b1050e6ce9f484724d88db8d338e3aa9651548
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=44b1050e6ce9f484724d88db8d338e3aa9651548

Author: Tom Stellard <thomas.stellard at amd.com>
Date:   Thu Sep 13 17:11:32 2012 +0000

r600g: Fix bug when adding new items to the compute memory pool

The items are ordered in the item list by their offsets, with the lowest
offset coming first in the list.  The old code was assuming that new
items being added to the list would always have a greater offset than
the first item in the list, however this is not always the case.

---

 src/gallium/drivers/r600/compute_memory_pool.c |   29 +++++++++++++++++++-----
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c
index 04f0be1..04d24f6 100644
--- a/src/gallium/drivers/r600/compute_memory_pool.c
+++ b/src/gallium/drivers/r600/compute_memory_pool.c
@@ -135,6 +135,11 @@ struct compute_memory_item* compute_memory_postalloc_chunk(
 	COMPUTE_DBG("* compute_memory_postalloc_chunck() start_in_dw = %ld\n",
 		start_in_dw);
 
+	/* Check if we can insert it in the front of the list */
+	if (pool->item_list && pool->item_list->start_in_dw > start_in_dw) {
+		return NULL;
+	}
+
 	for (item = pool->item_list; item; item = item->next) {
 		if (item->next) {
 			if (item->start_in_dw < start_in_dw
@@ -336,12 +341,24 @@ void compute_memory_finalize_pending(struct compute_memory_pool* pool,
 			struct compute_memory_item *pos;
 
 			pos = compute_memory_postalloc_chunk(pool, start_in_dw);
-			item->prev = pos;
-			item->next = pos->next;
-			pos->next = item;
-
-			if (item->next) {
-				item->next->prev = item;
+			if (pos) {
+				item->prev = pos;
+				item->next = pos->next;
+				pos->next = item;
+				if (item->next) {
+					item->next->prev = item;
+				}
+			} else {
+				/* Add item to the front of the list */
+				item->next = pool->item_list->next;
+				if (pool->item_list->next) {
+					pool->item_list->next->prev = item;
+				}
+				item->prev = pool->item_list->prev;
+				if (pool->item_list->prev) {
+					pool->item_list->prev->next = item;
+				}
+				pool->item_list = item;
 			}
 		}
 		else {




More information about the mesa-commit mailing list