From 10371c520c1841006795f0a113ae14194dfbf31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 1 Feb 2021 14:21:29 -0500 Subject: [PATCH] mesa: don't compute the ModelView * Projection matrix if not used Only GLSL built-in uniforms use it. This further reduces the time spent in _mesa_update_state. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/matrix.c | 28 ++++------------------------ src/mesa/program/prog_statevars.c | 6 ++++-- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index b91bb3d82a4..41c504f8755 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -944,26 +944,6 @@ update_projection( struct gl_context *ctx ) } -/** - * Calculate the combined modelview-projection matrix. - * - * \param ctx GL context. - * - * Multiplies the top matrices of the projection and model view stacks into - * __struct gl_contextRec::_ModelProjectMatrix via _math_matrix_mul_matrix() - * and analyzes the resulting matrix via _math_matrix_analyse(). - */ -static void -calculate_model_project_matrix( struct gl_context *ctx ) -{ - _math_matrix_mul_matrix( &ctx->_ModelProjectMatrix, - ctx->ProjectionMatrixStack.Top, - ctx->ModelviewMatrixStack.Top ); - - _math_matrix_analyse( &ctx->_ModelProjectMatrix ); -} - - /** * Updates the combined modelview-projection matrix. * @@ -983,10 +963,10 @@ void _mesa_update_modelview_project( struct gl_context *ctx, GLuint new_state ) if (new_state & _NEW_PROJECTION) update_projection( ctx ); - /* Keep ModelviewProject up to date always to allow tnl - * implementations that go model->clip even when eye is required. - */ - calculate_model_project_matrix(ctx); + /* Calculate ModelViewMatrix * ProjectionMatrix. */ + _math_matrix_mul_matrix(&ctx->_ModelProjectMatrix, + ctx->ProjectionMatrixStack.Top, + ctx->ModelviewMatrixStack.Top); } /*@}*/ diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index 92484d7c524..307c693e0c3 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -297,7 +297,8 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[], return; } case STATE_MVP_MATRIX_INVERSE: { - const GLmatrix *matrix = &ctx->_ModelProjectMatrix; + GLmatrix *matrix = &ctx->_ModelProjectMatrix; + _math_matrix_analyse(matrix); /* make sure the inverse is up to date */ copy_matrix(value, matrix->inv, state[2], state[3]); return; } @@ -307,7 +308,8 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[], return; } case STATE_MVP_MATRIX_INVTRANS: { - const GLmatrix *matrix = &ctx->_ModelProjectMatrix; + GLmatrix *matrix = &ctx->_ModelProjectMatrix; + _math_matrix_analyse(matrix); /* make sure the inverse is up to date */ copy_matrix_transposed(value, matrix->inv, state[2], state[3]); return; }