diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index fd14766..3e5b322 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6664,6 +6664,37 @@ get_mesa_program_tgsi(struct gl_context *ctx,
return prog;
}
+static void
+set_affected_state_flags(uint64_t *states,
+ struct gl_program *prog,
+ struct gl_linked_shader *shader,
+ 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 (shader->num_samplers)
+ *states |= new_sampler_views | new_samplers;
+
+ if (shader->NumImages)
+ *states |= new_images;
+
+ if (shader->NumUniformBlocks)
+ *states |= new_ubos;
+
+ if (shader->NumShaderStorageBlocks)
+ *states |= new_ssbos;
+
+ if (shader->NumAtomicBuffers)
+ *states |= new_atomics;
+}
+
static struct gl_program *
get_mesa_program(struct gl_context *ctx,
struct gl_shader_program *shader_program,
@@ -6702,24 +6733,14 @@ get_mesa_program(struct gl_context *ctx,
ST_NEW_RASTERIZER |
ST_NEW_VERTEX_ARRAYS;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_VS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_VS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_VS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_VS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_VS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_VS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
@@ -6727,24 +6748,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_TCS_STATE;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_TCS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_TCS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_TCS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_TCS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_TCS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_TCS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
@@ -6753,24 +6764,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_TES_STATE |
ST_NEW_RASTERIZER;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_TES_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_TES_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_TES_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_TES_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_TES_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_TES_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
@@ -6779,24 +6780,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_GS_STATE |
ST_NEW_RASTERIZER;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_GS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_GS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_GS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_GS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_GS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_GS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
@@ -6807,21 +6798,14 @@ get_mesa_program(struct gl_context *ctx,
ST_NEW_SAMPLE_SHADING |
ST_NEW_FS_CONSTANTS;
- if (shader->num_samplers)
- *states |= ST_NEW_FS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_FS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_FS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_FS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_FS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
@@ -6829,24 +6813,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_CS_STATE;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_CS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_CS_SAMPLER_VIEWS |
- ST_NEW_CS_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_CS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_CS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_CS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_CS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ 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:
Marek