Commit 23dc21b9 authored by Marek Olšák's avatar Marek Olšák Committed by Marge Bot

mesa: fix assertion paramList->LastUniformIndex < paramList->FirstStateVarIndex

This changes the code so that program parameters no longer have to be
sorted (meaning uniforms and constants are before state variables).

Instead of checking if the parameter is a state variable for every element,
teach all functions to handle non-state parameters safely. This is better
for the most common case where parameters are sorted or semi-sorted.

The new enum STATE_NOT_STATE_VAR identifes that a parameter is not
a state variable.

Fixes: 63f7d7dd - mesa: take advantage of sorted parameters in _mesa_load_state_parameters
Closes: mesa/mesa#3914Reviewed-by: Zoltán Böszörményi's avatarZoltán Böszörményi <zboszor@gmail.com>
Reviewed-by: Eric Anholt's avatarEric Anholt <eric@anholt.net>
Part-of: <mesa/mesa!8046>
parent 2c92df43
......@@ -326,6 +326,8 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
if (state) {
for (unsigned i = 0; i < STATE_LENGTH; i++)
paramList->Parameters[oldNum].StateIndexes[i] = state[i];
} else {
paramList->Parameters[oldNum].StateIndexes[0] = STATE_NOT_STATE_VAR;
}
if (type == PROGRAM_UNIFORM || type == PROGRAM_CONSTANT) {
......@@ -462,5 +464,4 @@ _mesa_recompute_parameter_bounds(struct gl_program_parameter_list *list)
list->UniformBytes = MAX2(list->UniformBytes, list->NumParameterValues * 4);
}
}
assert(list->LastUniformIndex < list->FirstStateVarIndex);
}
......@@ -148,7 +148,9 @@ struct gl_program_parameter_list
bool DisallowRealloc;
/* Parameters are optionally sorted as follows. Uniforms and constants
* are first, then state vars.
* are first, then state vars. This should be true in all cases except
* ir_to_mesa, which adds constants at the end, and ARB_vp with ARL,
* which can't sort parameters.
*/
int UniformBytes;
int LastUniformIndex;
......
......@@ -674,6 +674,12 @@ fetch_state(struct gl_context *ctx, const gl_state_index16 state[],
}
return;
case STATE_NOT_STATE_VAR:
/* Most likely PROGRAM_CONSTANT. This only happens in rare cases, e.g.
* ARB_vp with ARL, which can't sort parameters by type.
*/
return;
default:
unreachable("Invalid state in _mesa_fetch_state");
return;
......@@ -812,6 +818,9 @@ _mesa_program_state_flags(const gl_state_index16 state[STATE_LENGTH])
return 0;
}
case STATE_NOT_STATE_VAR:
return 0;
default:
_mesa_problem(NULL, "unexpected state[0] in make_state_flags()");
return 0;
......@@ -1201,6 +1210,9 @@ _mesa_program_state_string(const gl_state_index16 state[STATE_LENGTH])
state[1] == STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED)
append_index(str, state[2], false);
break;
case STATE_NOT_STATE_VAR:
append(str, "not_state");
break;
default:
_mesa_problem(NULL, "Invalid state in _mesa_program_state_string");
break;
......@@ -1225,7 +1237,6 @@ _mesa_load_state_parameters(struct gl_context *ctx,
if (!paramList)
return;
assert(paramList->LastUniformIndex < paramList->FirstStateVarIndex);
int num = paramList->NumParameters;
for (int i = paramList->FirstStateVarIndex; i < num; i++) {
......@@ -1240,7 +1251,6 @@ _mesa_upload_state_parameters(struct gl_context *ctx,
struct gl_program_parameter_list *paramList,
uint32_t *dst)
{
assert(paramList->LastUniformIndex < paramList->FirstStateVarIndex);
int num = paramList->NumParameters;
for (int i = paramList->FirstStateVarIndex; i < num; i++) {
......@@ -1260,15 +1270,11 @@ _mesa_upload_state_parameters(struct gl_context *ctx,
void
_mesa_optimize_state_parameters(struct gl_program_parameter_list *list)
{
assert(list->LastUniformIndex < list->FirstStateVarIndex);
for (int first_param = list->FirstStateVarIndex;
first_param < (int)list->NumParameters; first_param++) {
int last_param = first_param;
int param_diff = 0;
assert(list->Parameters[first_param].Type == PROGRAM_STATE_VAR);
switch (list->Parameters[first_param].StateIndexes[0]) {
case STATE_MODELVIEW_MATRIX:
case STATE_MODELVIEW_MATRIX_INVERSE:
......
......@@ -50,6 +50,8 @@ struct gl_program_parameter_list;
* always be the array index.
*/
typedef enum gl_state_index_ {
STATE_NOT_STATE_VAR = 0,
STATE_MATERIAL = 100, /* start at 100 so small ints are seen as ints */
STATE_LIGHT, /* One gl_light attribute. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment