mesa: don't update shaders on fixed-func state changes if user shaders are bound
authorMarek Olšák <marek.olsak@amd.com>
Sun, 22 Mar 2020 05:07:54 +0000 (01:07 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 30 Apr 2020 22:01:55 +0000 (22:01 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4314>

src/mesa/main/mtypes.h
src/mesa/main/state.c

index 8bfeeaf7cd4137a639f6095158cdf6063bb4c983..c99d6b97f005f51edd1f325ecafeae783e4aac4f 100644 (file)
@@ -2290,6 +2290,8 @@ struct gl_vertex_program_state
    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
    /** Should fixed-function T&L be implemented with a vertex prog? */
    GLboolean _MaintainTnlProgram;
+   /** Whether the fixed-func program is being used right now. */
+   GLboolean _UsesTnlProgram;
 
    struct gl_program *Current;  /**< User-bound vertex program */
 
@@ -2363,6 +2365,8 @@ struct gl_fragment_program_state
    GLboolean Enabled;     /**< User-set fragment program enable flag */
    /** Should fixed-function texturing be implemented with a fragment prog? */
    GLboolean _MaintainTexEnvProgram;
+   /** Whether the fixed-func program is being used right now. */
+   GLboolean _UsesTexEnvProgram;
 
    struct gl_program *Current;  /**< User-bound fragment program */
 
index 88feb16b6ea50e8c7fbdfd384ee5d864f47ff01d..2f89cecd8abd3d04f682c7f85a13daea89e24ed1 100644 (file)
@@ -363,6 +363,23 @@ update_program_constants(struct gl_context *ctx)
 }
 
 
+static void
+update_fixed_func_program_usage(struct gl_context *ctx)
+{
+   ctx->FragmentProgram._UsesTexEnvProgram =
+      ctx->FragmentProgram._MaintainTexEnvProgram &&
+      !ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT] && /* GLSL*/
+      !_mesa_arb_fragment_program_enabled(ctx) &&
+      !(_mesa_ati_fragment_shader_enabled(ctx) &&
+        ctx->ATIFragmentShader.Current->Program);
+
+   ctx->VertexProgram._UsesTnlProgram =
+      ctx->VertexProgram._MaintainTnlProgram &&
+      !ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX] && /* GLSL */
+      !_mesa_arb_vertex_program_enabled(ctx);
+}
+
+
 /**
  * Compute derived GL state.
  * If __struct gl_contextRec::NewState is non-zero then this function \b must
@@ -399,13 +416,17 @@ _mesa_update_state_locked( struct gl_context *ctx )
        ctx->API == API_OPENGLES) {
       GLbitfield prog_flags = _NEW_PROGRAM;
 
-      /* Determine which state flags effect vertex/fragment program state */
-      if (ctx->FragmentProgram._MaintainTexEnvProgram) {
+      if (new_state & _NEW_PROGRAM)
+         update_fixed_func_program_usage(ctx);
+
+      /* Determine which states affect fixed-func vertex/fragment program. */
+      if (ctx->FragmentProgram._UsesTexEnvProgram) {
          prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE_OBJECT | _NEW_FOG |
                         _NEW_VARYING_VP_INPUTS | _NEW_LIGHT | _NEW_POINT |
                         _NEW_RENDERMODE | _NEW_COLOR | _NEW_TEXTURE_STATE);
       }
-      if (ctx->VertexProgram._MaintainTnlProgram) {
+
+      if (ctx->VertexProgram._UsesTnlProgram) {
          prog_flags |= (_NEW_VARYING_VP_INPUTS | _NEW_TEXTURE_OBJECT |
                         _NEW_TEXTURE_MATRIX | _NEW_TRANSFORM | _NEW_POINT |
                         _NEW_FOG | _NEW_LIGHT | _NEW_TEXTURE_STATE |