mesa: allocate the attribute stack on demand

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6946>
This commit is contained in:
Marek Olšák
2020-11-11 19:11:09 -05:00
committed by Marge Bot
parent c0456a6565
commit f097c8773e
2 changed files with 15 additions and 4 deletions

View File

@@ -78,7 +78,15 @@ _mesa_PushAttrib(GLbitfield mask)
return;
}
head = &ctx->AttribStack[ctx->AttribStackDepth];
head = ctx->AttribStack[ctx->AttribStackDepth];
if (unlikely(!head)) {
head = CALLOC_STRUCT(gl_attrib_node);
if (unlikely(!head)) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushAttrib");
return;
}
ctx->AttribStack[ctx->AttribStackDepth] = head;
}
head->Mask = mask;
if (mask & GL_ACCUM_BUFFER_BIT)
@@ -650,7 +658,7 @@ _mesa_PopAttrib(void)
}
ctx->AttribStackDepth--;
attr = &ctx->AttribStack[ctx->AttribStackDepth];
attr = ctx->AttribStack[ctx->AttribStackDepth];
unsigned mask = attr->Mask;
@@ -1471,11 +1479,14 @@ _mesa_free_attrib_data(struct gl_context *ctx)
struct gl_attrib_node *attr;
ctx->AttribStackDepth--;
attr = &ctx->AttribStack[ctx->AttribStackDepth];
attr = ctx->AttribStack[ctx->AttribStackDepth];
if (attr->Mask & GL_TEXTURE_BIT)
_mesa_reference_shared_state(ctx, &attr->Texture.SharedRef, NULL);
}
for (unsigned i = 0; i < ARRAY_SIZE(ctx->AttribStack); i++)
free(ctx->AttribStack[i]);
}

View File

@@ -5195,7 +5195,7 @@ struct gl_context
/** \name State attribute stack (for glPush/PopAttrib) */
/*@{*/
GLuint AttribStackDepth;
struct gl_attrib_node AttribStack[MAX_ATTRIB_STACK_DEPTH];
struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
/*@}*/
/** \name Renderer attribute groups