st/mesa: create set_prog_affected_state_flags() helper
authorTimothy Arceri <t_arceri@yahoo.com.au>
Tue, 31 Jan 2017 06:15:09 +0000 (17:15 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 1 Feb 2017 21:31:28 +0000 (08:31 +1100)
This will be used when restoring tgsi from the on-disk shader
cache.

Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 224789e359469342639d63be0354e9382d1e0673..823a2b4fe984f24180eb890fecaa0b0f0cfd447a 100644 (file)
@@ -6841,6 +6841,116 @@ set_affected_state_flags(uint64_t *states,
       *states |= new_atomics;
 }
 
+static void
+set_prog_affected_state_flags(struct gl_program *prog)
+{
+   uint64_t *states;
+
+   /* This determines which states will be updated when the shader is bound.
+    */
+   switch (prog->info.stage) {
+   case MESA_SHADER_VERTEX:
+      states = &((struct st_vertex_program*)prog)->affected_states;
+
+      *states = ST_NEW_VS_STATE |
+                ST_NEW_RASTERIZER |
+                ST_NEW_VERTEX_ARRAYS;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_VS_CONSTANTS,
+                               ST_NEW_VS_SAMPLER_VIEWS,
+                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_VS_IMAGES,
+                               ST_NEW_VS_UBOS,
+                               ST_NEW_VS_SSBOS,
+                               ST_NEW_VS_ATOMICS);
+      break;
+
+   case MESA_SHADER_TESS_CTRL:
+      states = &((struct st_tessctrl_program*)prog)->affected_states;
+
+      *states = ST_NEW_TCS_STATE;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_TCS_CONSTANTS,
+                               ST_NEW_TCS_SAMPLER_VIEWS,
+                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_TCS_IMAGES,
+                               ST_NEW_TCS_UBOS,
+                               ST_NEW_TCS_SSBOS,
+                               ST_NEW_TCS_ATOMICS);
+      break;
+
+   case MESA_SHADER_TESS_EVAL:
+      states = &((struct st_tesseval_program*)prog)->affected_states;
+
+      *states = ST_NEW_TES_STATE |
+                ST_NEW_RASTERIZER;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_TES_CONSTANTS,
+                               ST_NEW_TES_SAMPLER_VIEWS,
+                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_TES_IMAGES,
+                               ST_NEW_TES_UBOS,
+                               ST_NEW_TES_SSBOS,
+                               ST_NEW_TES_ATOMICS);
+      break;
+
+   case MESA_SHADER_GEOMETRY:
+      states = &((struct st_geometry_program*)prog)->affected_states;
+
+      *states = ST_NEW_GS_STATE |
+                ST_NEW_RASTERIZER;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_GS_CONSTANTS,
+                               ST_NEW_GS_SAMPLER_VIEWS,
+                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_GS_IMAGES,
+                               ST_NEW_GS_UBOS,
+                               ST_NEW_GS_SSBOS,
+                               ST_NEW_GS_ATOMICS);
+      break;
+
+   case MESA_SHADER_FRAGMENT:
+      states = &((struct st_fragment_program*)prog)->affected_states;
+
+      /* gl_FragCoord and glDrawPixels always use constants. */
+      *states = ST_NEW_FS_STATE |
+                ST_NEW_SAMPLE_SHADING |
+                ST_NEW_FS_CONSTANTS;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_FS_CONSTANTS,
+                               ST_NEW_FS_SAMPLER_VIEWS,
+                               ST_NEW_RENDER_SAMPLERS,
+                               ST_NEW_FS_IMAGES,
+                               ST_NEW_FS_UBOS,
+                               ST_NEW_FS_SSBOS,
+                               ST_NEW_FS_ATOMICS);
+      break;
+
+   case MESA_SHADER_COMPUTE:
+      states = &((struct st_compute_program*)prog)->affected_states;
+
+      *states = ST_NEW_CS_STATE;
+
+      set_affected_state_flags(states, prog,
+                               ST_NEW_CS_CONSTANTS,
+                               ST_NEW_CS_SAMPLER_VIEWS,
+                               ST_NEW_CS_SAMPLERS,
+                               ST_NEW_CS_IMAGES,
+                               ST_NEW_CS_UBOS,
+                               ST_NEW_CS_SSBOS,
+                               ST_NEW_CS_ATOMICS);
+      break;
+
+   default:
+      unreachable("unhandled shader stage");
+   }
+}
+
 static struct gl_program *
 get_mesa_program(struct gl_context *ctx,
                  struct gl_shader_program *shader_program,
@@ -6866,112 +6976,7 @@ get_mesa_program(struct gl_context *ctx,
    }
 
    if (prog) {
-      uint64_t *states;
-
-      /* This determines which states will be updated when the shader is
-       * bound.
-       */
-      switch (shader->Stage) {
-      case MESA_SHADER_VERTEX:
-         states = &((struct st_vertex_program*)prog)->affected_states;
-
-         *states = ST_NEW_VS_STATE |
-                   ST_NEW_RASTERIZER |
-                   ST_NEW_VERTEX_ARRAYS;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_VS_CONSTANTS,
-                                  ST_NEW_VS_SAMPLER_VIEWS,
-                                  ST_NEW_RENDER_SAMPLERS,
-                                  ST_NEW_VS_IMAGES,
-                                  ST_NEW_VS_UBOS,
-                                  ST_NEW_VS_SSBOS,
-                                  ST_NEW_VS_ATOMICS);
-         break;
-
-      case MESA_SHADER_TESS_CTRL:
-         states = &((struct st_tessctrl_program*)prog)->affected_states;
-
-         *states = ST_NEW_TCS_STATE;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_TCS_CONSTANTS,
-                                  ST_NEW_TCS_SAMPLER_VIEWS,
-                                  ST_NEW_RENDER_SAMPLERS,
-                                  ST_NEW_TCS_IMAGES,
-                                  ST_NEW_TCS_UBOS,
-                                  ST_NEW_TCS_SSBOS,
-                                  ST_NEW_TCS_ATOMICS);
-         break;
-
-      case MESA_SHADER_TESS_EVAL:
-         states = &((struct st_tesseval_program*)prog)->affected_states;
-
-         *states = ST_NEW_TES_STATE |
-                   ST_NEW_RASTERIZER;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_TES_CONSTANTS,
-                                  ST_NEW_TES_SAMPLER_VIEWS,
-                                  ST_NEW_RENDER_SAMPLERS,
-                                  ST_NEW_TES_IMAGES,
-                                  ST_NEW_TES_UBOS,
-                                  ST_NEW_TES_SSBOS,
-                                  ST_NEW_TES_ATOMICS);
-         break;
-
-      case MESA_SHADER_GEOMETRY:
-         states = &((struct st_geometry_program*)prog)->affected_states;
-
-         *states = ST_NEW_GS_STATE |
-                   ST_NEW_RASTERIZER;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_GS_CONSTANTS,
-                                  ST_NEW_GS_SAMPLER_VIEWS,
-                                  ST_NEW_RENDER_SAMPLERS,
-                                  ST_NEW_GS_IMAGES,
-                                  ST_NEW_GS_UBOS,
-                                  ST_NEW_GS_SSBOS,
-                                  ST_NEW_GS_ATOMICS);
-         break;
-
-      case MESA_SHADER_FRAGMENT:
-         states = &((struct st_fragment_program*)prog)->affected_states;
-
-         /* gl_FragCoord and glDrawPixels always use constants. */
-         *states = ST_NEW_FS_STATE |
-                   ST_NEW_SAMPLE_SHADING |
-                   ST_NEW_FS_CONSTANTS;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_FS_CONSTANTS,
-                                  ST_NEW_FS_SAMPLER_VIEWS,
-                                  ST_NEW_RENDER_SAMPLERS,
-                                  ST_NEW_FS_IMAGES,
-                                  ST_NEW_FS_UBOS,
-                                  ST_NEW_FS_SSBOS,
-                                  ST_NEW_FS_ATOMICS);
-         break;
-
-      case MESA_SHADER_COMPUTE:
-         states = &((struct st_compute_program*)prog)->affected_states;
-
-         *states = ST_NEW_CS_STATE;
-
-         set_affected_state_flags(states, prog,
-                                  ST_NEW_CS_CONSTANTS,
-                                  ST_NEW_CS_SAMPLER_VIEWS,
-                                  ST_NEW_CS_SAMPLERS,
-                                  ST_NEW_CS_IMAGES,
-                                  ST_NEW_CS_UBOS,
-                                  ST_NEW_CS_SSBOS,
-                                  ST_NEW_CS_ATOMICS);
-         break;
-
-      default:
-         unreachable("unhandled shader stage");
-      }
+      set_prog_affected_state_flags(prog);
    }
 
    return prog;