mesa/st: only update samplers for stages that have changed
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 11 Apr 2017 01:05:22 +0000 (11:05 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Thu, 13 Apr 2017 02:08:31 +0000 (12:08 +1000)
Might help reduce cpu for some apps that use sso.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_atom_list.h
src/mesa/state_tracker/st_atom_sampler.c
src/mesa/state_tracker/st_program.c

index 45c3e4876471684c7b6df9714779d4b1f0173032..0145cefd040cdac00bdc24984234416292ee106d 100644 (file)
@@ -83,7 +83,11 @@ enum {
 #undef ST_STATE
 
 /* Combined state flags. */
-#define ST_NEW_SAMPLERS         (ST_NEW_RENDER_SAMPLERS | \
+#define ST_NEW_SAMPLERS         (ST_NEW_VS_SAMPLERS | \
+                                 ST_NEW_TCS_SAMPLERS | \
+                                 ST_NEW_TES_SAMPLERS | \
+                                 ST_NEW_GS_SAMPLERS | \
+                                 ST_NEW_FS_SAMPLERS | \
                                  ST_NEW_CS_SAMPLERS)
 
 #define ST_NEW_FRAMEBUFFER      (ST_NEW_FB_STATE | \
index d0d5a05398d98669bbe8ccd22cf35c2ed54f1b51..4212dacfa989341b2c2a5306996758327b2ef22f 100644 (file)
@@ -22,7 +22,11 @@ ST_STATE(ST_NEW_TCS_SAMPLER_VIEWS, st_update_tessctrl_texture)
 ST_STATE(ST_NEW_TES_SAMPLER_VIEWS, st_update_tesseval_texture)
 
 /* Non-compute samplers. */
-ST_STATE(ST_NEW_RENDER_SAMPLERS, st_update_sampler) /* depends on update_*_texture for swizzle */
+ST_STATE(ST_NEW_VS_SAMPLERS, st_update_vertex_sampler) /* depends on update_*_texture for swizzle */
+ST_STATE(ST_NEW_TCS_SAMPLERS, st_update_tessctrl_sampler) /* depends on update_*_texture for swizzle */
+ST_STATE(ST_NEW_TES_SAMPLERS, st_update_tesseval_sampler) /* depends on update_*_texture for swizzle */
+ST_STATE(ST_NEW_GS_SAMPLERS, st_update_geometry_sampler) /* depends on update_*_texture for swizzle */
+ST_STATE(ST_NEW_FS_SAMPLERS, st_update_fragment_sampler) /* depends on update_*_texture for swizzle */
 
 ST_STATE(ST_NEW_VS_IMAGES, st_bind_vs_images)
 ST_STATE(ST_NEW_TCS_IMAGES, st_bind_tcs_images)
@@ -67,7 +71,7 @@ ST_STATE(ST_NEW_VERTEX_ARRAYS, st_update_array)
 /* Compute states must be last. */
 ST_STATE(ST_NEW_CS_STATE, st_update_cp)
 ST_STATE(ST_NEW_CS_SAMPLER_VIEWS, st_update_compute_texture)
-ST_STATE(ST_NEW_CS_SAMPLERS, st_update_sampler) /* depends on update_compute_texture for swizzle */
+ST_STATE(ST_NEW_CS_SAMPLERS, st_update_compute_sampler) /* depends on update_compute_texture for swizzle */
 ST_STATE(ST_NEW_CS_CONSTANTS, st_update_cs_constants)
 ST_STATE(ST_NEW_CS_UBOS, st_bind_cs_ubos)
 ST_STATE(ST_NEW_CS_ATOMICS, st_bind_cs_atomics)
index d67b2fcab4f7654e34af42ef06e5f27ccb990fda..820a57dd4f5e0d8bc60c9dd43dcdbae326cffc76 100644 (file)
@@ -317,32 +317,24 @@ update_shader_samplers(struct st_context *st,
 
 
 static void
-update_samplers(struct st_context *st)
+update_vertex_samplers(struct st_context *st)
 {
    const struct gl_context *ctx = st->ctx;
 
-   update_shader_samplers(st,
-                          PIPE_SHADER_FRAGMENT,
-                          ctx->FragmentProgram._Current,
-                          ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
-                          st->state.samplers[PIPE_SHADER_FRAGMENT],
-                          &st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
-
    update_shader_samplers(st,
                           PIPE_SHADER_VERTEX,
                           ctx->VertexProgram._Current,
                           ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits,
                           st->state.samplers[PIPE_SHADER_VERTEX],
                           &st->state.num_samplers[PIPE_SHADER_VERTEX]);
+}
+
+
+static void
+update_tessctrl_samplers(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
 
-   if (ctx->GeometryProgram._Current) {
-      update_shader_samplers(st,
-                             PIPE_SHADER_GEOMETRY,
-                             ctx->GeometryProgram._Current,
-                             ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits,
-                             st->state.samplers[PIPE_SHADER_GEOMETRY],
-                             &st->state.num_samplers[PIPE_SHADER_GEOMETRY]);
-   }
    if (ctx->TessCtrlProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_TESS_CTRL,
@@ -351,6 +343,14 @@ update_samplers(struct st_context *st)
                              st->state.samplers[PIPE_SHADER_TESS_CTRL],
                              &st->state.num_samplers[PIPE_SHADER_TESS_CTRL]);
    }
+}
+
+
+static void
+update_tesseval_samplers(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
+
    if (ctx->TessEvalProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_TESS_EVAL,
@@ -359,6 +359,44 @@ update_samplers(struct st_context *st)
                              st->state.samplers[PIPE_SHADER_TESS_EVAL],
                              &st->state.num_samplers[PIPE_SHADER_TESS_EVAL]);
    }
+}
+
+
+static void
+update_geometry_samplers(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
+
+   if (ctx->GeometryProgram._Current) {
+      update_shader_samplers(st,
+                             PIPE_SHADER_GEOMETRY,
+                             ctx->GeometryProgram._Current,
+                             ctx->Const.Program[MESA_SHADER_GEOMETRY].MaxTextureImageUnits,
+                             st->state.samplers[PIPE_SHADER_GEOMETRY],
+                             &st->state.num_samplers[PIPE_SHADER_GEOMETRY]);
+   }
+}
+
+
+static void
+update_fragment_samplers(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
+
+   update_shader_samplers(st,
+                          PIPE_SHADER_FRAGMENT,
+                          ctx->FragmentProgram._Current,
+                          ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits,
+                          st->state.samplers[PIPE_SHADER_FRAGMENT],
+                          &st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
+}
+
+
+static void
+update_compute_samplers(struct st_context *st)
+{
+   const struct gl_context *ctx = st->ctx;
+
    if (ctx->ComputeProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_COMPUTE,
@@ -370,6 +408,26 @@ update_samplers(struct st_context *st)
 }
 
 
-const struct st_tracked_state st_update_sampler = {
-   update_samplers                                     /* update */
+const struct st_tracked_state st_update_vertex_sampler = {
+   update_vertex_samplers                              /* update */
+};
+
+const struct st_tracked_state st_update_tessctrl_sampler = {
+   update_tessctrl_samplers                            /* update */
+};
+
+const struct st_tracked_state st_update_tesseval_sampler = {
+   update_tesseval_samplers                            /* update */
+};
+
+const struct st_tracked_state st_update_geometry_sampler = {
+   update_geometry_samplers                            /* update */
+};
+
+const struct st_tracked_state st_update_fragment_sampler = {
+   update_fragment_samplers                            /* update */
+};
+
+const struct st_tracked_state st_update_compute_sampler = {
+   update_compute_samplers                             /* update */
 };
index 4d9250b73ccb499ae0faf3267c069548f3e1bcf8..0dc3b1ea9bda8402e8186cdbd6e47d11a506dbbd 100644 (file)
@@ -112,7 +112,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       set_affected_state_flags(states, prog,
                                ST_NEW_VS_CONSTANTS,
                                ST_NEW_VS_SAMPLER_VIEWS,
-                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_VS_SAMPLERS,
                                ST_NEW_VS_IMAGES,
                                ST_NEW_VS_UBOS,
                                ST_NEW_VS_SSBOS,
@@ -127,7 +127,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       set_affected_state_flags(states, prog,
                                ST_NEW_TCS_CONSTANTS,
                                ST_NEW_TCS_SAMPLER_VIEWS,
-                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_TCS_SAMPLERS,
                                ST_NEW_TCS_IMAGES,
                                ST_NEW_TCS_UBOS,
                                ST_NEW_TCS_SSBOS,
@@ -143,7 +143,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       set_affected_state_flags(states, prog,
                                ST_NEW_TES_CONSTANTS,
                                ST_NEW_TES_SAMPLER_VIEWS,
-                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_TES_SAMPLERS,
                                ST_NEW_TES_IMAGES,
                                ST_NEW_TES_UBOS,
                                ST_NEW_TES_SSBOS,
@@ -159,7 +159,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       set_affected_state_flags(states, prog,
                                ST_NEW_GS_CONSTANTS,
                                ST_NEW_GS_SAMPLER_VIEWS,
-                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_GS_SAMPLERS,
                                ST_NEW_GS_IMAGES,
                                ST_NEW_GS_UBOS,
                                ST_NEW_GS_SSBOS,
@@ -177,7 +177,7 @@ st_set_prog_affected_state_flags(struct gl_program *prog)
       set_affected_state_flags(states, prog,
                                ST_NEW_FS_CONSTANTS,
                                ST_NEW_FS_SAMPLER_VIEWS,
-                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_FS_SAMPLERS,
                                ST_NEW_FS_IMAGES,
                                ST_NEW_FS_UBOS,
                                ST_NEW_FS_SSBOS,
@@ -754,12 +754,12 @@ st_translate_fragment_program(struct st_context *st,
       if (stfp->ati_fs) {
          /* Just set them for ATI_fs unconditionally. */
          stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
-                                  ST_NEW_RENDER_SAMPLERS;
+                                  ST_NEW_FS_SAMPLERS;
       } else {
          /* ARB_fp */
          if (stfp->Base.SamplersUsed)
             stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
-                                     ST_NEW_RENDER_SAMPLERS;
+                                     ST_NEW_FS_SAMPLERS;
       }
    }