<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Nov 24, 2013 at 9:00 AM, Brian Paul <span dir="ltr"><<a href="mailto:brian.e.paul@gmail.com" target="_blank">brian.e.paul@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Brian Paul <<a href="mailto:brianp@vmware.com">brianp@vmware.com</a>><br>
<br>
Display lists allocate memory in chunks of 256 tokens (1KB) at a time.<br>
If an app creates many short display lists or uses glXUseXFont() this<br>
can waste quite a bit of memory.<br>
<br>
This patch uses realloc() to trim short lists and reduce the memory<br>
used.<br>
<br>
Also, null/zero-out some list construction fields in _mesa_EndList().<br>
---<br>
src/mesa/main/dlist.c | 35 +++++++++++++++++++++++++++++++++++<br>
1 file changed, 35 insertions(+)<br>
<br>
diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c<br>
index d1e2035..cb40ff4 100644<br>
--- a/src/mesa/main/dlist.c<br>
+++ b/src/mesa/main/dlist.c<br>
@@ -1067,6 +1067,37 @@ alloc_instruction(struct gl_context *ctx, OpCode opcode, GLuint nparams)<br>
}<br>
<br>
<br>
+/**<br>
+ * Called by EndList to try to reduce memory used for the list.<br>
+ */<br>
+static void<br>
+trim_list(struct gl_context *ctx)<br>
+{<br>
+ /* If the list we're ending only has one allocated block of nodes/tokens<br>
+ * and its size isn't a full block size, realloc the block to use less<br>
+ * memory. This is important for apps that create many small display<br>
+ * lists and apps that use glXUseXFont (many lists each containing one<br>
+ * glBitmap call).<br>
+ * Note: we currently only trim display lists that allocated one block<br>
+ * of tokens. That hits the short list case which is what we're mainly<br>
+ * concerned with. Trimming longer lists would involve traversing the<br>
+ * linked list of blocks.<br>
+ */<br>
+ struct gl_dlist_state *list = &ctx->ListState;<br>
+<br>
+ if ((list->CurrentList->Head == list->CurrentBlock) &&<br>
+ (list->CurrentPos < BLOCK_SIZE)) {<br>
+ /* There's only one block and it's not full, so realloc */<br>
+ GLuint newSize = list->CurrentPos * sizeof(Node);<br>
+ list->CurrentList->Head =<br>
+ list->CurrentBlock = realloc(list->CurrentBlock, newSize);<br>
+ if (!list->CurrentBlock) {<br>
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glEndList");<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+<br>
<br>
/*<br>
* Display List compilation functions<br>
@@ -8242,6 +8273,8 @@ _mesa_EndList(void)<br>
<br>
(void) alloc_instruction(ctx, OPCODE_END_OF_LIST, 0);<br>
<br>
+ trim_list(ctx);<br>
+<br>
/* Destroy old list, if any */<br>
destroy_list(ctx, ctx->ListState.CurrentList->Name);<br>
<br>
@@ -8255,6 +8288,8 @@ _mesa_EndList(void)<br>
mesa_print_display_list(ctx->ListState.CurrentList->Name);<br>
<br>
ctx->ListState.CurrentList = NULL;<br>
+ ctx->ListState.CurrentBlock = NULL;<br>
+ ctx->ListState.CurrentPos = 0;<br>
ctx->ExecuteFlag = GL_TRUE;<br>
ctx->CompileFlag = GL_FALSE;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.9.5<br>
<br></font></span></blockquote><div><br></div><div>Ping.<br> <br></div></div><br></div></div>