st/mesa: _NEW_TEXTURE & CONSTANTS shouldn't flag states that aren't used
authorMarek Olšák <marek.olsak@amd.com>
Tue, 2 Aug 2016 14:59:41 +0000 (16:59 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 12 Aug 2016 16:50:01 +0000 (18:50 +0200)
Tested-by: Edmondo Tommasina <edmondo.tommasina@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h

index c206343b16b72ff5e5652049b1fbb50b1d4fed03..37e382c445679ce8d5075b40aad49337bfce5d45 100644 (file)
@@ -134,6 +134,14 @@ enum {
                                  ST_NEW_FS_IMAGES | \
                                  ST_NEW_CS_IMAGES)
 
+#define ST_ALL_SHADER_RESOURCES (ST_NEW_SAMPLER_VIEWS | \
+                                 ST_NEW_SAMPLERS | \
+                                 ST_NEW_CONSTANTS | \
+                                 ST_NEW_UNIFORM_BUFFER | \
+                                 ST_NEW_ATOMIC_BUFFER | \
+                                 ST_NEW_STORAGE_BUFFER | \
+                                 ST_NEW_IMAGE_UNITS)
+
 /* All state flags within each group: */
 #define ST_PIPELINE_RENDER_STATE_MASK  (ST_NEW_CS_STATE - 1)
 #define ST_PIPELINE_COMPUTE_STATE_MASK (0xffllu << ST_NEW_CS_STATE_INDEX)
index 1ff035586c393d890399d1a06260bd30e1e9e13d..687ca199016a1791355735ef423a702cb5dac34b 100644 (file)
@@ -123,6 +123,41 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out)
 }
 
 
+uint64_t
+st_get_active_states(struct gl_context *ctx)
+{
+   struct st_vertex_program *vp =
+      st_vertex_program(ctx->VertexProgram._Current);
+   struct st_tessctrl_program *tcp =
+      st_tessctrl_program(ctx->TessCtrlProgram._Current);
+   struct st_tesseval_program *tep =
+      st_tesseval_program(ctx->TessEvalProgram._Current);
+   struct st_geometry_program *gp =
+      st_geometry_program(ctx->GeometryProgram._Current);
+   struct st_fragment_program *fp =
+      st_fragment_program(ctx->FragmentProgram._Current);
+   struct st_compute_program *cp =
+      st_compute_program(ctx->ComputeProgram._Current);
+   uint64_t active_shader_states = 0;
+
+   if (vp)
+      active_shader_states |= vp->affected_states;
+   if (tcp)
+      active_shader_states |= tcp->affected_states;
+   if (tep)
+      active_shader_states |= tep->affected_states;
+   if (gp)
+      active_shader_states |= gp->affected_states;
+   if (fp)
+      active_shader_states |= fp->affected_states;
+   if (cp)
+      active_shader_states |= cp->affected_states;
+
+   /* Mark non-shader-resource shader states as "always active". */
+   return active_shader_states | ~ST_ALL_SHADER_RESOURCES;
+}
+
+
 /**
  * Called via ctx->Driver.UpdateState()
  */
@@ -204,17 +239,9 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
    if (new_state & _NEW_PIXEL)
       st->dirty |= ST_NEW_PIXEL_TRANSFER;
 
-   if (new_state & _NEW_TEXTURE)
-      st->dirty |= ST_NEW_SAMPLER_VIEWS |
-                   ST_NEW_SAMPLERS |
-                   ST_NEW_IMAGE_UNITS;
-
    if (new_state & _NEW_CURRENT_ATTRIB)
       st->dirty |= ST_NEW_VERTEX_ARRAYS;
 
-   if (new_state & _NEW_PROGRAM_CONSTANTS)
-      st->dirty |= ST_NEW_CONSTANTS;
-
    /* Update the vertex shader if ctx->Light._ClampVertexColor was changed. */
    if (st->clamp_vert_color_in_shader && (new_state & _NEW_LIGHT))
       st->dirty |= ST_NEW_VS_STATE;
@@ -223,8 +250,19 @@ void st_invalidate_state(struct gl_context * ctx, GLbitfield new_state)
    if (new_state & _NEW_PROGRAM) {
       st->gfx_shaders_may_be_dirty = true;
       st->compute_shader_may_be_dirty = true;
+      /* This will mask out unused shader resources. */
+      st->active_states = st_get_active_states(ctx);
    }
 
+   if (new_state & _NEW_TEXTURE)
+      st->dirty |= st->active_states &
+                   (ST_NEW_SAMPLER_VIEWS |
+                    ST_NEW_SAMPLERS |
+                    ST_NEW_IMAGE_UNITS);
+
+   if (new_state & _NEW_PROGRAM_CONSTANTS)
+      st->dirty |= st->active_states & ST_NEW_CONSTANTS;
+
    /* This is the only core Mesa module we depend upon.
     * No longer use swrast, swsetup, tnl.
     */
index 556b9c99a23a0f6762d4e11eebe5369ae5611611..f82cf3a85aac2f27c14c1f0b1f92fe75f441caab 100644 (file)
@@ -140,6 +140,9 @@ struct st_context
 
    uint64_t dirty; /**< dirty states */
 
+   /** This masks out unused shader resources. Only valid in draw calls. */
+   uint64_t active_states;
+
    /* If true, further analysis of states is required to know if something
     * has changed. Used mainly for shaders.
     */
@@ -357,6 +360,9 @@ st_create_context(gl_api api, struct pipe_context *pipe,
 extern void
 st_destroy_context(struct st_context *st);
 
+uint64_t
+st_get_active_states(struct gl_context *ctx);
+
 
 #ifdef __cplusplus
 }