From bc05833c8a114256a48cd7b2b905581767f0dcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 1 Feb 2021 13:17:13 -0500 Subject: [PATCH] mesa: rework _MESA_NEW_NEED_EYE_COORDS to reduce fixed-func program updates This eliminates a lot of the remaining no-op fixed-func program key recomputations in _mesa_update_state. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mesa/main/light.c | 11 +++++++---- src/mesa/main/light.h | 3 ++- src/mesa/main/mtypes.h | 4 ++-- src/mesa/main/state.c | 11 +++++++---- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index a3c99c07b4e..c50989706bd 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -1120,8 +1120,10 @@ update_modelview_scale( struct gl_context *ctx ) /** * Bring up to date any state that relies on _NeedEyeCoords. + * + * Return true if ctx->_NeedEyeCoords has been changed. */ -void +bool _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ) { const GLuint oldneedeyecoords = ctx->_NeedEyeCoords; @@ -1150,6 +1152,7 @@ _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ) if (ctx->Driver.LightingSpaceChange) ctx->Driver.LightingSpaceChange( ctx ); + return true; } else { GLuint new_state2 = ctx->NewState; @@ -1162,6 +1165,8 @@ _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ) if (new_state2 & (_NEW_LIGHT_CONSTANTS | _NEW_MODELVIEW)) compute_light_positions( ctx ); + + return false; } } @@ -1174,9 +1179,7 @@ void _mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag ) { ctx->_ForceEyeCoords = !flag; - ctx->NewState |= _NEW_POINT; /* one of the bits from - * _MESA_NEW_NEED_EYE_COORDS. - */ + ctx->NewState |= _NEW_POINT; /* for _mesa_update_tnl_spaces */ } diff --git a/src/mesa/main/light.h b/src/mesa/main/light.h index d009aa1759e..46f979e4170 100644 --- a/src/mesa/main/light.h +++ b/src/mesa/main/light.h @@ -28,6 +28,7 @@ #define LIGHT_H +#include #include "glheader.h" struct gl_context; @@ -92,7 +93,7 @@ extern GLuint _mesa_material_bitmask( struct gl_context *ctx, extern void _mesa_update_lighting( struct gl_context *ctx ); -extern void _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ); +extern bool _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state ); extern void _mesa_update_material( struct gl_context *ctx, GLuint bitmask ); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 661c0f0d2d5..643f6ffaf71 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4654,7 +4654,7 @@ struct gl_matrix_stack #define _NEW_TRACK_MATRIX (1u << 25) /**< gl_context::VertexProgram */ #define _NEW_PROGRAM (1u << 26) /**< New program/shader state */ #define _NEW_PROGRAM_CONSTANTS (1u << 27) -/* gap */ +#define _NEW_FF_VERT_PROGRAM (1u << 28) #define _NEW_FRAG_CLAMP (1u << 29) /* gap, re-use for core Mesa state only; use ctx->DriverFlags otherwise */ #define _NEW_VARYING_VP_INPUTS (1u << 31) /**< gl_context::VertexProgram._VaryingInputs */ @@ -4663,7 +4663,7 @@ struct gl_matrix_stack /** - * Composite state flags + * Composite state flags, deprecated and inefficient, do not use. */ /*@{*/ #define _NEW_LIGHT (_NEW_LIGHT_FF_PROGRAM | /* fixed-func programs */ \ diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 4406c81737f..c4985393aed 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -468,7 +468,7 @@ _mesa_update_state_locked( struct gl_context *ctx ) if (new_state & _NEW_PIXEL) _mesa_update_pixel( ctx ); - /* ctx->_NeedEyeCoords is now up to date. + /* ctx->_NeedEyeCoords is determined here. * * If the truth value of this variable has changed, update for the * new lighting space and recompute the positions of lights and the @@ -477,8 +477,11 @@ _mesa_update_state_locked( struct gl_context *ctx ) * If the lighting space hasn't changed, may still need to recompute * light positions & normal transforms for other reasons. */ - if (new_state & _MESA_NEW_NEED_EYE_COORDS) - _mesa_update_tnl_spaces( ctx, new_state ); + if (new_state & (_NEW_LIGHT_FF_PROGRAM | _NEW_LIGHT_CONSTANTS | + _NEW_TEXTURE_STATE | _NEW_POINT | _NEW_MODELVIEW)) { + if (_mesa_update_tnl_spaces(ctx, new_state)) + new_state |= _NEW_FF_VERT_PROGRAM; + } if (new_state & _NEW_PROGRAM) update_fixed_func_program_usage(ctx); @@ -497,7 +500,7 @@ _mesa_update_state_locked( struct gl_context *ctx ) prog_flags |= _NEW_VARYING_VP_INPUTS | _NEW_TEXTURE_OBJECT | _NEW_TEXTURE_MATRIX | _NEW_TRANSFORM | _NEW_POINT | _NEW_FOG | _NEW_LIGHT_FF_PROGRAM | _NEW_TEXTURE_STATE | - _MESA_NEW_NEED_EYE_COORDS; + _NEW_FF_VERT_PROGRAM; } if (new_state & prog_flags) {