From 76558262439e36a7583d8967407ba25108053772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 3 Mar 2025 08:06:23 -0500 Subject: [PATCH] mesa: allocate GLmatrix aligned to 16 bytes The declaration has: typedef struct { alignas(16) GLfloat m[16]; /**< 16 matrix elements (16-byte aligned) */ alignas(16) GLfloat inv[16]; /**< 16-element inverse (16-byte aligned) */ ... } GLmatrix; We should honor that. Fixes: 3175b63a0dfa2 - mesa: don't allocate matrices with malloc Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10237 Reviewed-by: Ian Romanick Part-of: --- src/mesa/main/matrix.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index aefd7658ba5..f8782b57054 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -311,8 +311,9 @@ push_matrix(struct gl_context *ctx, struct gl_matrix_stack *stack, if (stack->Depth + 1 >= stack->StackSize) { unsigned new_stack_size = stack->StackSize * 2; unsigned i; - GLmatrix *new_stack = realloc(stack->Stack, - sizeof(*new_stack) * new_stack_size); + GLmatrix *new_stack = + os_realloc_aligned(stack->Stack, stack->StackSize * sizeof(GLmatrix), + new_stack_size * sizeof(GLmatrix), 16); if (!new_stack) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func); @@ -1008,7 +1009,7 @@ init_matrix_stack(struct gl_matrix_stack *stack, stack->MaxDepth = maxDepth; stack->DirtyFlag = dirtyFlag; /* The stack will be dynamically resized at glPushMatrix() time */ - stack->Stack = calloc(1, sizeof(GLmatrix)); + stack->Stack = os_malloc_aligned(sizeof(GLmatrix), 16); stack->StackSize = 1; _math_matrix_ctr(&stack->Stack[0]); stack->Top = stack->Stack; @@ -1023,7 +1024,7 @@ init_matrix_stack(struct gl_matrix_stack *stack, static void free_matrix_stack( struct gl_matrix_stack *stack ) { - free(stack->Stack); + os_free_aligned(stack->Stack); stack->Stack = stack->Top = NULL; stack->StackSize = 0; }