st/mesa: consolidate and simplify code flagging program::affected_states
authorMarek Olšák <marek.olsak@amd.com>
Sat, 2 Nov 2019 02:19:28 +0000 (22:19 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 19 Nov 2019 23:02:06 +0000 (18:02 -0500)
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_cb_program.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_shader_cache.c

index ccf58b10e9e954b7501fdb41c6ef5828dcac6005..ffc64bd83f13e2666c55d9641c691a97d8a594bb 100644 (file)
@@ -110,7 +110,7 @@ enum {
                                  ST_NEW_SAMPLE_STATE | \
                                  ST_NEW_SAMPLE_SHADING)
 
-#define ST_NEW_VERTEX_PROGRAM(st, p) (p->affected_states | \
+#define ST_NEW_VERTEX_PROGRAM(st, p) ((p)->affected_states | \
                                       (st_user_clip_planes_enabled(st->ctx) ? \
                                        ST_NEW_CLIP_STATE : 0))
 
index 50fa5d2ad673b3f1b39523b085d06bd337029f3a..62a67cf7fa8875dcda49591b5eaf58d1eb33d94f 100644 (file)
@@ -150,9 +150,6 @@ st_program_string_notify( struct gl_context *ctx,
       if (!stfp->shader_program && /* not GLSL->NIR */
           !st_translate_fragment_program(st, stfp))
          return false;
-
-      if (st->fp == stfp)
-        st->dirty |= stfp->affected_states;
    } else if (target == GL_VERTEX_PROGRAM_ARB) {
       struct st_vertex_program *stvp = (struct st_vertex_program *) prog;
 
@@ -160,9 +157,6 @@ st_program_string_notify( struct gl_context *ctx,
       if (!stvp->shader_program && /* not GLSL->NIR */
           !st_translate_vertex_program(st, stvp))
          return false;
-
-      if (st->vp == stvp)
-        st->dirty |= ST_NEW_VERTEX_PROGRAM(st, stvp);
    } else {
       struct st_common_program *stcp = st_common_program(prog);
 
@@ -170,12 +164,6 @@ st_program_string_notify( struct gl_context *ctx,
       if (!stcp->shader_program && /* not GLSL->NIR */
           !st_translate_common_program(st, stcp))
          return false;
-
-      if ((prog->info.stage == MESA_SHADER_TESS_CTRL && st->tcp == stcp) ||
-          (prog->info.stage == MESA_SHADER_TESS_EVAL && st->tep == stcp) ||
-          (prog->info.stage == MESA_SHADER_GEOMETRY && st->gp == stcp) ||
-          (prog->info.stage == MESA_SHADER_COMPUTE && st->cp == stcp))
-        st->dirty |= stcp->affected_states;
    }
 
    st_finalize_program(st, prog);
index 21ba2f41ac0158c8b60093a147b491dc9a6eda9c..cf2f636df6ed11af911d5a00f645547df728f7e9 100644 (file)
@@ -244,12 +244,17 @@ struct st_context
     */
    unsigned active_queries;
 
-   struct st_vertex_program *vp;    /**< Currently bound vertex program */
-   struct st_common_program *fp;  /**< Currently bound fragment program */
-   struct st_common_program *gp;  /**< Currently bound geometry program */
-   struct st_common_program *tcp; /**< Currently bound tess control program */
-   struct st_common_program *tep; /**< Currently bound tess eval program */
-   struct st_common_program *cp;   /**< Currently bound compute program */
+   union {
+      struct {
+         struct st_vertex_program *vp;    /**< Currently bound vertex program */
+         struct st_common_program *tcp; /**< Currently bound tess control program */
+         struct st_common_program *tep; /**< Currently bound tess eval program */
+         struct st_common_program *gp;  /**< Currently bound geometry program */
+         struct st_common_program *fp;  /**< Currently bound fragment program */
+         struct st_common_program *cp;   /**< Currently bound compute program */
+      };
+      struct gl_program *current_program[MESA_SHADER_STAGES];
+   };
 
    struct st_vp_variant *vp_variant;
 
index 597a0a6135fe8900bcd69813427527c26535da16..05b5353780dd8a68f27bfadddd73649500777a1c 100644 (file)
@@ -62,6 +62,7 @@
 #include "st_atifs_to_tgsi.h"
 #include "st_nir.h"
 #include "st_shader_cache.h"
+#include "st_util.h"
 #include "cso_cache/cso_context.h"
 
 
@@ -2054,6 +2055,13 @@ st_precompile_shader_variant(struct st_context *st,
 void
 st_finalize_program(struct st_context *st, struct gl_program *prog)
 {
+   if (st->current_program[prog->info.stage] == prog) {
+      if (prog->info.stage == MESA_SHADER_VERTEX)
+         st->dirty |= ST_NEW_VERTEX_PROGRAM(st, (struct st_vertex_program *)prog);
+      else
+         st->dirty |= ((struct st_common_program *)prog)->affected_states;
+   }
+
    /* Create Gallium shaders now instead of on demand. */
    if (ST_DEBUG & DEBUG_PRECOMPILE ||
        st->shader_has_one_variant[prog->info.stage])
index 5cd969f3fe55504dc011a8cdc252c3154b801e6d..a5b755b04ec7ffa465d6589839251ac674e5104d 100644 (file)
@@ -214,10 +214,6 @@ st_deserialise_ir_program(struct gl_context *ctx,
       } else {
          read_tgsi_from_cache(&blob_reader, &stvp->state.tokens);
       }
-
-      if (st->vp == stvp)
-         st->dirty |= ST_NEW_VERTEX_PROGRAM(st, stvp);
-
       break;
    }
    case MESA_SHADER_TESS_CTRL:
@@ -244,13 +240,6 @@ st_deserialise_ir_program(struct gl_context *ctx,
       } else {
          read_tgsi_from_cache(&blob_reader, &stcp->state.tokens);
       }
-
-      if ((prog->info.stage == MESA_SHADER_TESS_CTRL && st->tcp == stcp) ||
-          (prog->info.stage == MESA_SHADER_TESS_EVAL && st->tep == stcp) ||
-          (prog->info.stage == MESA_SHADER_GEOMETRY && st->gp == stcp) ||
-          (prog->info.stage == MESA_SHADER_FRAGMENT && st->fp == stcp) ||
-          (prog->info.stage == MESA_SHADER_COMPUTE && st->cp == stcp))
-         st->dirty |= stcp->affected_states;
       break;
    }
    default: