st/mesa: move set_prog_affected_state_flags() to st_program.c
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 21 Feb 2017 23:59:13 +0000 (10:59 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 22 Feb 2017 22:20:22 +0000 (09:20 +1100)
We want to use this in the new tgsi shader cache so we move it here
and make it available externally.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/mesa/state_tracker/st_glsl_to_tgsi.cpp
src/mesa/state_tracker/st_program.c
src/mesa/state_tracker/st_program.h

index 630f5af821c5b794be192109c5ef91d3e91ccc5e..476d18534d92ce804917406c26391c47d0ec7ad5 100644 (file)
@@ -6809,146 +6809,6 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    return prog;
 }
 
-static void
-set_affected_state_flags(uint64_t *states,
-                         struct gl_program *prog,
-                         uint64_t new_constants,
-                         uint64_t new_sampler_views,
-                         uint64_t new_samplers,
-                         uint64_t new_images,
-                         uint64_t new_ubos,
-                         uint64_t new_ssbos,
-                         uint64_t new_atomics)
-{
-   if (prog->Parameters->NumParameters)
-      *states |= new_constants;
-
-   if (prog->info.num_textures)
-      *states |= new_sampler_views | new_samplers;
-
-   if (prog->info.num_images)
-      *states |= new_images;
-
-   if (prog->info.num_ubos)
-      *states |= new_ubos;
-
-   if (prog->info.num_ssbos)
-      *states |= new_ssbos;
-
-   if (prog->info.num_abos)
-      *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");
-   }
-}
-
 /* See if there are unsupported control flow statements. */
 class ir_control_flow_info_visitor : public ir_hierarchical_visitor {
 private:
@@ -7158,7 +7018,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       }
 
       if (linked_prog) {
-         set_prog_affected_state_flags(linked_prog);
+         st_set_prog_affected_state_flags(linked_prog);
          if (!ctx->Driver.ProgramStringNotify(ctx,
                                               _mesa_shader_stage_to_program(i),
                                               linked_prog)) {
index b2d15863b1989774792cad9aded6682947b30ec6..3795f25a74e505a3f65f87e4edac2dc3e0d8a6ff 100644 (file)
 
 
 
+static void
+set_affected_state_flags(uint64_t *states,
+                         struct gl_program *prog,
+                         uint64_t new_constants,
+                         uint64_t new_sampler_views,
+                         uint64_t new_samplers,
+                         uint64_t new_images,
+                         uint64_t new_ubos,
+                         uint64_t new_ssbos,
+                         uint64_t new_atomics)
+{
+   if (prog->Parameters->NumParameters)
+      *states |= new_constants;
+
+   if (prog->info.num_textures)
+      *states |= new_sampler_views | new_samplers;
+
+   if (prog->info.num_images)
+      *states |= new_images;
+
+   if (prog->info.num_ubos)
+      *states |= new_ubos;
+
+   if (prog->info.num_ssbos)
+      *states |= new_ssbos;
+
+   if (prog->info.num_abos)
+      *states |= new_atomics;
+}
+
+/**
+ * This determines which states will be updated when the shader is bound.
+ */
+void
+st_set_prog_affected_state_flags(struct gl_program *prog)
+{
+   uint64_t *states;
+
+   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");
+   }
+}
+
 /**
  * Delete a vertex program variant.  Note the caller must unlink
  * the variant from the linked list.
index eb36ac3282579789d40d1139e08beaddc5166feb..9f9777a7d559edad4f7f3f05901c54c862ed34ed 100644 (file)
@@ -423,6 +423,8 @@ st_get_generic_varying_index(struct st_context *st, GLuint attr)
    return 0;
 }
 
+extern void
+st_set_prog_affected_state_flags(struct gl_program *prog);
 
 extern struct st_vp_variant *
 st_get_vp_variant(struct st_context *st,