From e6ecd22140fe6c6e8ac26966c8409f7254370479 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 23 Aug 2022 00:13:37 -0400 Subject: [PATCH] mesa: make glPopMatrix a no-op if the matrix hasn't changed This happens a lot with viewperf because glMultMatrixf contains identity matrices. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/matrix.c | 15 ++++++++++++++- src/mesa/main/mtypes.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index ac23e70..0793cb1 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -122,6 +122,7 @@ static void matrix_frustum(struct gl_matrix_stack* stack, (GLfloat) left, (GLfloat) right, (GLfloat) bottom, (GLfloat) top, (GLfloat) nearval, (GLfloat) farval); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -203,6 +204,7 @@ matrix_ortho(struct gl_matrix_stack* stack, (GLfloat) left, (GLfloat) right, (GLfloat) bottom, (GLfloat) top, (GLfloat) nearval, (GLfloat) farval ); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -328,6 +330,7 @@ push_matrix(struct gl_context *ctx, struct gl_matrix_stack *stack, &stack->Stack[stack->Depth]); stack->Depth++; stack->Top = &(stack->Stack[stack->Depth]); + stack->ChangedSincePush = false; } @@ -377,7 +380,8 @@ pop_matrix( struct gl_context *ctx, struct gl_matrix_stack *stack ) /* If the popped matrix is the same as the current one, treat it as * a no-op change. */ - if (memcmp(stack->Top, &stack->Stack[stack->Depth], + if (stack->ChangedSincePush && + memcmp(stack->Top, &stack->Stack[stack->Depth], sizeof(GLmatrix))) { FLUSH_VERTICES(ctx, 0, 0); ctx->NewState |= stack->DirtyFlag; @@ -450,6 +454,7 @@ _mesa_load_identity_matrix(struct gl_context *ctx, struct gl_matrix_stack *stack FLUSH_VERTICES(ctx, 0, 0); _math_matrix_set_identity(stack->Top); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -495,6 +500,7 @@ _mesa_load_matrix(struct gl_context *ctx, struct gl_matrix_stack *stack, if (memcmp(m, stack->Top->m, 16 * sizeof(GLfloat)) != 0) { FLUSH_VERTICES(ctx, 0, 0); _math_matrix_loadf(stack->Top, m); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } } @@ -583,6 +589,7 @@ matrix_mult(struct gl_matrix_stack *stack, const GLfloat *m, const char* caller) FLUSH_VERTICES(ctx, 0, 0); _math_matrix_mul_floats(stack->Top, m); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -628,6 +635,7 @@ matrix_rotate(struct gl_matrix_stack *stack, GLfloat angle, FLUSH_VERTICES(ctx, 0, 0); if (angle != 0.0F) { _math_matrix_rotate(stack->Top, angle, x, y, z); + stack->ChangedSincePush = true; ctx->NewState |=stack->DirtyFlag; } } @@ -688,6 +696,7 @@ _mesa_Scalef( GLfloat x, GLfloat y, GLfloat z ) FLUSH_VERTICES(ctx, 0, 0); _math_matrix_scale( ctx->CurrentStack->Top, x, y, z); + ctx->CurrentStack->ChangedSincePush = true; ctx->NewState |= ctx->CurrentStack->DirtyFlag; } @@ -704,6 +713,7 @@ _mesa_MatrixScalefEXT( GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z ) FLUSH_VERTICES(ctx, 0, 0); _math_matrix_scale(stack->Top, x, y, z); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -728,6 +738,7 @@ _mesa_Translatef( GLfloat x, GLfloat y, GLfloat z ) FLUSH_VERTICES(ctx, 0, 0); _math_matrix_translate( ctx->CurrentStack->Top, x, y, z); + ctx->CurrentStack->ChangedSincePush = true; ctx->NewState |= ctx->CurrentStack->DirtyFlag; } @@ -743,6 +754,7 @@ _mesa_MatrixTranslatefEXT( GLenum matrixMode, GLfloat x, GLfloat y, GLfloat z ) FLUSH_VERTICES(ctx, 0, 0); _math_matrix_translate(stack->Top, x, y, z); + stack->ChangedSincePush = true; ctx->NewState |= stack->DirtyFlag; } @@ -1004,6 +1016,7 @@ init_matrix_stack(struct gl_matrix_stack *stack, stack->StackSize = 1; _math_matrix_ctr(&stack->Stack[0]); stack->Top = stack->Stack; + stack->ChangedSincePush = false; } /** diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 7b3d30e..42bea71 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2791,6 +2791,7 @@ struct gl_matrix_stack GLuint Depth; /**< 0 <= Depth < MaxDepth */ GLuint MaxDepth; /**< size of Stack[] array */ GLuint DirtyFlag; /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */ + bool ChangedSincePush; }; -- 2.7.4