_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
struct gl_program *prog)
{
- memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
+ GLbitfield mask = prog->SamplersUsed;
+ gl_shader_stage prog_stage =
+ _mesa_program_enum_to_shader_stage(prog->Target);
+ struct gl_linked_shader *shader = shProg->_LinkedShaders[prog_stage];
- shProg->SamplersValidated = GL_TRUE;
+ assert(shader);
+
+ memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
- GLbitfield mask = prog->SamplersUsed;
while (mask) {
const int s = u_bit_scan(&mask);
GLuint unit = prog->SamplerUnits[s];
* types pointing to the same texture image unit within a program
* object."
*/
- if (prog->TexturesUsed[unit] & ~(1 << tgt))
- shProg->SamplersValidated = GL_FALSE;
+ unsigned stages_mask = shProg->data->linked_stages;
+ while (stages_mask) {
+ const int stage = u_bit_scan(&stages_mask);
+
+ /* Skip validation if we are yet to update textures used in this
+ * stage.
+ */
+ if (prog_stage < stage)
+ break;
+
+ struct gl_program *glprog = shProg->_LinkedShaders[stage]->Program;
+ if (glprog->TexturesUsed[unit] & ~(1 << tgt))
+ shProg->SamplersValidated = GL_FALSE;
+ }
prog->TexturesUsed[unit] |= (1 << tgt);
}
}
if (prog->data->LinkStatus) {
+ /* Reset sampler validated to true, validation happens via the
+ * LinkShader call below.
+ */
+ prog->SamplersValidated = GL_TRUE;
+
if (!ctx->Driver.LinkShader(ctx, prog)) {
prog->data->LinkStatus = linking_failure;
}