From 9f632df4b2ba18e71b704cf5fd431adcb0193dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 1 Feb 2021 14:03:46 -0500 Subject: [PATCH] mesa: don't compute the inverted projection matrix if not used Only clip planes and GLSL built-in uniforms use it. update_projection (called by _mesa_update_state) removes the _math_matrix_analyse call, reducing the time spent in _mesa_update_state. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/clip.c | 1 + src/mesa/main/matrix.c | 25 +++++++++++++------------ src/mesa/program/prog_statevars.c | 6 ++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/mesa/main/clip.c b/src/mesa/main/clip.c index 72308604e78..6a1e00fc4cb 100644 --- a/src/mesa/main/clip.c +++ b/src/mesa/main/clip.c @@ -38,6 +38,7 @@ void _mesa_update_clip_plane(struct gl_context *ctx, GLuint plane) { + /* make sure the inverse is up to date */ if (_math_matrix_is_dirty(ctx->ProjectionMatrixStack.Top)) _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c index f9ae68f67d4..b91bb3d82a4 100644 --- a/src/mesa/main/matrix.c +++ b/src/mesa/main/matrix.c @@ -914,8 +914,7 @@ _mesa_MatrixMultTransposedEXT( GLenum matrixMode, const GLdouble *m ) * * \param ctx GL context. * - * Calls _math_matrix_analyse() with the top-matrix of the projection matrix - * stack, and recomputes user clip positions if necessary. + * Recomputes user clip positions if necessary. * * \note This routine references __struct gl_contextRec::Tranform attribute * values to compute userclip positions in clip space, but is only called on @@ -925,20 +924,22 @@ _mesa_MatrixMultTransposedEXT( GLenum matrixMode, const GLdouble *m ) static void update_projection( struct gl_context *ctx ) { - GLbitfield mask; - - _math_matrix_analyse( ctx->ProjectionMatrixStack.Top ); - /* Recompute clip plane positions in clipspace. This is also done * in _mesa_ClipPlane(). */ - mask = ctx->Transform.ClipPlanesEnabled; - while (mask) { - const int p = u_bit_scan(&mask); + GLbitfield mask = ctx->Transform.ClipPlanesEnabled; - _mesa_transform_vector( ctx->Transform._ClipUserPlane[p], - ctx->Transform.EyeUserPlane[p], - ctx->ProjectionMatrixStack.Top->inv ); + if (mask) { + /* make sure the inverse is up to date */ + _math_matrix_analyse(ctx->ProjectionMatrixStack.Top); + + do { + const int p = u_bit_scan(&mask); + + _mesa_transform_vector(ctx->Transform._ClipUserPlane[p], + ctx->Transform.EyeUserPlane[p], + ctx->ProjectionMatrixStack.Top->inv); + } while (mask); } } diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c index 349e257d345..92484d7c524 100644 --- a/src/mesa/program/prog_statevars.c +++ b/src/mesa/program/prog_statevars.c @@ -275,7 +275,8 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[], return; } case STATE_PROJECTION_MATRIX_INVERSE: { - const GLmatrix *matrix = ctx->ProjectionMatrixStack.Top; + GLmatrix *matrix = ctx->ProjectionMatrixStack.Top; + _math_matrix_analyse(matrix); /* make sure the inverse is up to date */ copy_matrix(value, matrix->inv, state[2], state[3]); return; } @@ -285,7 +286,8 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[], return; } case STATE_PROJECTION_MATRIX_INVTRANS: { - const GLmatrix *matrix = ctx->ProjectionMatrixStack.Top; + GLmatrix *matrix = ctx->ProjectionMatrixStack.Top; + _math_matrix_analyse(matrix); /* make sure the inverse is up to date */ copy_matrix_transposed(value, matrix->inv, state[2], state[3]); return; }