mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 00:58:05 +02:00
mesa: glsl: add usage tracking for uniform vars
Unused uniforms are no longer included in the active uniforms list.
This commit is contained in:
parent
df9bd01ea0
commit
3e1706f720
4 changed files with 35 additions and 3 deletions
|
|
@ -277,6 +277,26 @@ _mesa_add_uniform(struct gl_program_parameter_list *paramList,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark the named uniform as 'used'.
|
||||
*/
|
||||
void
|
||||
_mesa_use_uniform(struct gl_program_parameter_list *paramList,
|
||||
const char *name)
|
||||
{
|
||||
GLuint i;
|
||||
for (i = 0; i < paramList->NumParameters; i++) {
|
||||
struct gl_program_parameter *p = paramList->Parameters + i;
|
||||
if (p->Type == PROGRAM_UNIFORM && _mesa_strcmp(p->Name, name) == 0) {
|
||||
p->Used = GL_TRUE;
|
||||
/* Note that large uniforms may occupy several slots so we're
|
||||
* not done searching yet.
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a sampler to the parameter list.
|
||||
* \param name uniform's name
|
||||
|
|
@ -591,21 +611,24 @@ _mesa_clone_parameter_list(const struct gl_program_parameter_list *list)
|
|||
/** Not too efficient, but correct */
|
||||
for (i = 0; i < list->NumParameters; i++) {
|
||||
struct gl_program_parameter *p = list->Parameters + i;
|
||||
struct gl_program_parameter *pCopy;
|
||||
GLuint size = MIN2(p->Size, 4);
|
||||
GLint j = _mesa_add_parameter(clone, p->Type, p->Name, size, p->DataType,
|
||||
list->ParameterValues[i], NULL);
|
||||
ASSERT(j >= 0);
|
||||
pCopy = clone->Parameters + j;
|
||||
pCopy->Used = p->Used;
|
||||
/* copy state indexes */
|
||||
if (p->Type == PROGRAM_STATE_VAR) {
|
||||
GLint k;
|
||||
struct gl_program_parameter *q = clone->Parameters + j;
|
||||
for (k = 0; k < STATE_LENGTH; k++) {
|
||||
q->StateIndexes[k] = p->StateIndexes[k];
|
||||
pCopy->StateIndexes[k] = p->StateIndexes[k];
|
||||
}
|
||||
}
|
||||
else {
|
||||
clone->Parameters[j].Size = p->Size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clone->StateFlags = list->StateFlags;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ struct gl_program_parameter
|
|||
enum register_file Type; /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
|
||||
GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
|
||||
GLuint Size; /**< Number of components (1..4) */
|
||||
GLboolean Used; /**< Helper flag for GLSL uniform tracking */
|
||||
/**
|
||||
* A sequence of STATE_* tokens and integers to identify GL state.
|
||||
*/
|
||||
|
|
@ -112,6 +113,10 @@ extern GLint
|
|||
_mesa_add_uniform(struct gl_program_parameter_list *paramList,
|
||||
const char *name, GLuint size, GLenum datatype);
|
||||
|
||||
extern void
|
||||
_mesa_use_uniform(struct gl_program_parameter_list *paramList,
|
||||
const char *name);
|
||||
|
||||
extern GLint
|
||||
_mesa_add_sampler(struct gl_program_parameter_list *paramList,
|
||||
const char *name, GLenum datatype);
|
||||
|
|
|
|||
|
|
@ -1703,6 +1703,10 @@ emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n)
|
|||
if (n->Store->File == PROGRAM_STATE_VAR && n->Store->Index < 0) {
|
||||
n->Store->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters);
|
||||
}
|
||||
else if (n->Store->File == PROGRAM_UNIFORM) {
|
||||
/* mark var as used */
|
||||
_mesa_use_uniform(emitInfo->prog->Parameters, (char *) n->Var->a_name);
|
||||
}
|
||||
|
||||
if (n->Store->Index < 0) {
|
||||
/* probably ran out of registers */
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ link_uniform_vars(struct gl_shader_program *shProg,
|
|||
* Furthermore, we'll need to fix the state-var's size/datatype info.
|
||||
*/
|
||||
|
||||
if (p->Type == PROGRAM_UNIFORM ||
|
||||
if ((p->Type == PROGRAM_UNIFORM && p->Used) ||
|
||||
p->Type == PROGRAM_SAMPLER) {
|
||||
_mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue