+ /* From section 7.3 (Program Objects) of the OpenGL 4.5 spec:
+ *
+ * "If LinkProgram or ProgramBinary successfully re-links a program
+ * object that is active for any shader stage, then the newly generated
+ * executable code will be installed as part of the current rendering
+ * state for all shader stages where the program is active.
+ * Additionally, the newly generated executable code is made part of
+ * the state of any program pipeline for all stages where the program
+ * is attached."
+ */
+ if (shProg->data->LinkStatus && programs_in_use) {
+ while (programs_in_use) {
+ const int stage = u_bit_scan(&programs_in_use);
+
+ struct gl_program *prog = NULL;
+ if (shProg->_LinkedShaders[stage])
+ prog = shProg->_LinkedShaders[stage]->Program;
+
+ _mesa_use_program(ctx, stage, shProg, prog, ctx->_Shader);
+ }
+ }
+
+ /* Capture .shader_test files. */
+ const char *capture_path = _mesa_get_shader_capture_path();
+ if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) {
+ FILE *file;
+ char *filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
+ capture_path, shProg->Name);
+ file = fopen(filename, "w");
+ if (file) {
+ fprintf(file, "[require]\nGLSL%s >= %u.%02u\n",
+ shProg->IsES ? " ES" : "",
+ shProg->data->Version / 100, shProg->data->Version % 100);
+ if (shProg->SeparateShader)
+ fprintf(file, "GL_ARB_separate_shader_objects\nSSO ENABLED\n");
+ fprintf(file, "\n");
+
+ for (unsigned i = 0; i < shProg->NumShaders; i++) {
+ fprintf(file, "[%s shader]\n%s\n",
+ _mesa_shader_stage_to_string(shProg->Shaders[i]->Stage),
+ shProg->Shaders[i]->Source);
+ }
+ fclose(file);
+ } else {
+ _mesa_warning(ctx, "Failed to open %s", filename);
+ }
+
+ ralloc_free(filename);
+ }
+
+ if (shProg->data->LinkStatus == linking_failure &&