#define PATH_MAX _MAX_PATH
#endif
+static void _mesa_shader_write_subroutine_index(struct gl_context *ctx, struct gl_linked_shader *sh);
/**
* Return mask of GLSL_x flags by examining the MESA_GLSL env var.
*/
shProg = NULL;
if (shProg)
- _mesa_shader_program_init_subroutine_defaults(shProg);
+ _mesa_shader_program_init_subroutine_defaults(ctx, shProg);
if (*target != shProg) {
/* Program is current, flush it */
_mesa_error(ctx, GL_INVALID_OPERATION, "%s", api_name);
return;
}
+
+ ctx->SubroutineIndex[sh->Stage].IndexPtr[j] = indices[j];
}
i += uni_count;
} while(i < count);
FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
- i = 0;
- do {
- struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i];
- if (uni == NULL) {
- i++;
- continue;
- }
-
- int uni_count = uni->array_elements ? uni->array_elements : 1;
-
- memcpy(&uni->storage[0], &indices[i],
- sizeof(GLuint) * uni_count);
- _mesa_propagate_uniforms_to_driver_storage(uni, 0, uni_count);
- i += uni_count;
- } while(i < count);
+ _mesa_shader_write_subroutine_index(ctx, sh);
}
return;
}
- {
- struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[location];
- int offset = location - uni->opaque[stage].index;
- memcpy(params, &uni->storage[offset],
- sizeof(GLuint));
- }
+ *params = ctx->SubroutineIndex[sh->Stage].IndexPtr[location];
}
}
static void
-_mesa_shader_init_subroutine_defaults(struct gl_linked_shader *sh)
+_mesa_shader_write_subroutine_index(struct gl_context *ctx,
+ struct gl_linked_shader *sh)
{
int i, j;
- for (i = 0; i < sh->NumSubroutineUniformRemapTable; i++) {
+ if (sh->NumSubroutineUniformRemapTable == 0)
+ return;
+
+ i = 0;
+ do {
struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i];
int uni_count;
int val;
- if (!uni)
+ if (!uni) {
+ i++;
continue;
- uni_count = uni->array_elements ? uni->array_elements : 1;
- val = find_compat_subroutine(sh, uni->type);
+ }
- for (j = 0; j < uni_count; j++)
+ uni_count = uni->array_elements ? uni->array_elements : 1;
+ for (j = 0; j < uni_count; j++) {
+ val = ctx->SubroutineIndex[sh->Stage].IndexPtr[i + j];
memcpy(&uni->storage[j], &val, sizeof(int));
+ }
_mesa_propagate_uniforms_to_driver_storage(uni, 0, uni_count);
+ i += uni_count;
+ } while(i < sh->NumSubroutineUniformRemapTable);
+}
+
+static void
+_mesa_shader_init_subroutine_defaults(struct gl_context *ctx,
+ struct gl_linked_shader *sh)
+{
+ int i;
+ struct gl_subroutine_index_binding *binding = &ctx->SubroutineIndex[sh->Stage];
+ if (binding->NumIndex != sh->NumSubroutineUniformRemapTable) {
+ binding->IndexPtr = realloc(binding->IndexPtr,
+ sh->NumSubroutineUniformRemapTable * (sizeof(GLuint)));
+ binding->NumIndex = sh->NumSubroutineUniformRemapTable;
+ }
+
+ for (i = 0; i < sh->NumSubroutineUniformRemapTable; i++) {
+ struct gl_uniform_storage *uni = sh->SubroutineUniformRemapTable[i];
+
+ if (!uni)
+ continue;
+
+ binding->IndexPtr[i] = find_compat_subroutine(sh, uni->type);
}
+
+ _mesa_shader_write_subroutine_index(ctx, sh);
}
void
-_mesa_shader_program_init_subroutine_defaults(struct gl_shader_program *shProg)
+_mesa_shader_program_init_subroutine_defaults(struct gl_context *ctx,
+ struct gl_shader_program *shProg)
{
int i;
if (!shProg->_LinkedShaders[i])
continue;
- _mesa_shader_init_subroutine_defaults(shProg->_LinkedShaders[i]);
+ _mesa_shader_init_subroutine_defaults(ctx, shProg->_LinkedShaders[i]);
}
}