mesa: be precise about when to set _NEW_CURRENT_ATTRIB and _NEW_MATERIAL
authorMarek Olšák <marek.olsak@amd.com>
Wed, 3 Feb 2021 17:41:18 +0000 (12:41 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 26 Feb 2021 23:38:02 +0000 (23:38 +0000)
This commit fixes _mesa_update_color_material, which allows cleaning up
the unnecessary state flagging.

Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8850>

src/mesa/main/attrib.c
src/mesa/main/light.c
src/mesa/program/prog_statevars.c
src/mesa/vbo/vbo_exec_api.c
src/mesa/vbo/vbo_save_draw.c

index d17fc4c..2063956 100644 (file)
@@ -896,8 +896,7 @@ _mesa_PopAttrib(void)
    if (mask & GL_CURRENT_BIT) {
       memcpy(&ctx->Current, &attr->Current,
              sizeof(struct gl_current_attrib));
-      /* Set _NEW_MATERIAL because current attribs may reference materials. */
-      ctx->NewState |= _NEW_CURRENT_ATTRIB | _NEW_MATERIAL;
+      ctx->NewState |= _NEW_CURRENT_ATTRIB;
    }
 
    if (mask & GL_DEPTH_BUFFER_BIT) {
@@ -1012,9 +1011,8 @@ _mesa_PopAttrib(void)
                      ColorMaterial);
       TEST_AND_UPDATE(ctx->Light.ColorMaterialEnabled,
                       attr->Light.ColorMaterialEnabled, GL_COLOR_MATERIAL);
-      /* Materials - they might be used by current attribs. */
       /* Shininess material is used by the fixed-func vertex program. */
-      ctx->NewState |= _NEW_MATERIAL | _NEW_CURRENT_ATTRIB | _NEW_FF_VERT_PROGRAM;
+      ctx->NewState |= _NEW_MATERIAL | _NEW_FF_VERT_PROGRAM;
       memcpy(&ctx->Light.Material, &attr->Light.Material,
              sizeof(struct gl_material));
       if (ctx->Extensions.ARB_color_buffer_float) {
index e8a1684..8317173 100644 (file)
@@ -781,7 +781,10 @@ _mesa_update_color_material( struct gl_context *ctx, const GLfloat color[4] )
    while (bitmask) {
       const int i = u_bit_scan(&bitmask);
 
-      COPY_4FV( mat->Attrib[i], color );
+      if (memcmp(mat->Attrib[i], color, sizeof(mat->Attrib[i]))) {
+         COPY_4FV(mat->Attrib[i], color);
+         ctx->NewState |= _NEW_MATERIAL;
+      }
    }
 }
 
index c30e3c2..8508157 100644 (file)
@@ -805,16 +805,14 @@ _mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH])
 {
    switch (state[0]) {
    case STATE_MATERIAL:
-      /* these can be affected by glColor when colormaterial mode is used */
-      return _NEW_MATERIAL | _NEW_CURRENT_ATTRIB;
+      return _NEW_MATERIAL;
 
    case STATE_LIGHTPROD:
    case STATE_LIGHTPROD_ARRAY_FRONT:
    case STATE_LIGHTPROD_ARRAY_BACK:
    case STATE_LIGHTPROD_ARRAY_TWOSIDE:
    case STATE_LIGHTMODEL_SCENECOLOR:
-      /* these can be affected by glColor when colormaterial mode is used */
-      return _NEW_LIGHT_CONSTANTS | _NEW_MATERIAL | _NEW_CURRENT_ATTRIB;
+      return _NEW_LIGHT_CONSTANTS | _NEW_MATERIAL;
 
    case STATE_LIGHT:
    case STATE_LIGHT_ARRAY:
index 8e7d4b8..af42473 100644 (file)
@@ -218,10 +218,10 @@ vbo_exec_copy_to_current(struct vbo_exec_context *exec)
             if (i == VBO_ATTRIB_MAT_FRONT_SHININESS ||
                 i == VBO_ATTRIB_MAT_BACK_SHININESS)
                ctx->NewState |= _NEW_FF_VERT_PROGRAM;
+         } else {
+            ctx->NewState |= _NEW_CURRENT_ATTRIB;
+            ctx->PopAttribState |= GL_CURRENT_BIT;
          }
-
-         ctx->NewState |= _NEW_CURRENT_ATTRIB;
-         ctx->PopAttribState |= GL_CURRENT_BIT;
       }
 
       /* Given that we explicitly state size here, there is no need
index 4ee136f..19ecc34 100644 (file)
@@ -110,8 +110,7 @@ playback_copy_to_current(struct gl_context *ctx,
             _NEW_CURRENT_ATTRIB, GL_CURRENT_BIT, 0, &data, &color0_changed);
    /* Copy materials */
    copy_vao(ctx, node->VAO[VP_MODE_FF], VERT_BIT_MAT_ALL,
-            _NEW_CURRENT_ATTRIB | _NEW_MATERIAL,
-            GL_CURRENT_BIT | GL_LIGHTING_BIT,
+            _NEW_MATERIAL, GL_LIGHTING_BIT,
             VBO_MATERIAL_SHIFT, &data, &color0_changed);
 
    if (color0_changed && ctx->Light.ColorMaterialEnabled) {