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

mesa: add upper bound to limit program state var iterations

State parameters are sometimes not perfectly sorted.
This optimizes the number of iterations we have to do for fetch_state.
Reviewed-by: Zoltán Böszörményi's avatarZoltán Böszörményi <zboszor@gmail.com>
Part-of: <mesa/mesa!8183>
parent 0f7877d9
......@@ -1046,6 +1046,7 @@ write_shader_parameters(struct blob *metadata,
blob_write_uint32(metadata, params->StateFlags);
blob_write_uint32(metadata, params->UniformBytes);
blob_write_uint32(metadata, params->FirstStateVarIndex);
blob_write_uint32(metadata, params->LastStateVarIndex);
}
static void
......@@ -1082,6 +1083,7 @@ read_shader_parameters(struct blob_reader *metadata,
params->StateFlags = blob_read_uint32(metadata);
params->UniformBytes = blob_read_uint32(metadata);
params->FirstStateVarIndex = blob_read_uint32(metadata);
params->LastStateVarIndex = blob_read_uint32(metadata);
}
static void
......
......@@ -142,6 +142,7 @@ _mesa_new_parameter_list(void)
list->UniformBytes = 0;
list->FirstStateVarIndex = INT_MAX;
list->LastStateVarIndex = 0;
return list;
}
......@@ -339,6 +340,8 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
} else if (type == PROGRAM_STATE_VAR) {
paramList->FirstStateVarIndex =
MIN2(paramList->FirstStateVarIndex, oldNum);
paramList->LastStateVarIndex =
MAX2(paramList->LastStateVarIndex, oldNum);
} else {
unreachable("invalid parameter type");
}
......@@ -455,10 +458,12 @@ void
_mesa_recompute_parameter_bounds(struct gl_program_parameter_list *list)
{
list->FirstStateVarIndex = INT_MAX;
list->LastStateVarIndex = 0;
for (int i = 0; i < (int)list->NumParameters; i++) {
if (list->Parameters[i].Type == PROGRAM_STATE_VAR) {
list->FirstStateVarIndex = MIN2(list->FirstStateVarIndex, i);
list->LastStateVarIndex = MAX2(list->LastStateVarIndex, i);
} else {
list->UniformBytes = MAX2(list->UniformBytes, list->NumParameterValues * 4);
}
......
......@@ -154,6 +154,7 @@ struct gl_program_parameter_list
*/
int UniformBytes;
int FirstStateVarIndex;
int LastStateVarIndex;
};
......
......@@ -1256,9 +1256,9 @@ _mesa_load_state_parameters(struct gl_context *ctx,
if (!paramList)
return;
int num = paramList->NumParameters;
int last = paramList->LastStateVarIndex;
for (int i = paramList->FirstStateVarIndex; i < num; i++) {
for (int i = paramList->FirstStateVarIndex; i <= last; i++) {
unsigned pvo = paramList->Parameters[i].ValueOffset;
fetch_state(ctx, paramList->Parameters[i].StateIndexes,
paramList->ParameterValues + pvo);
......@@ -1270,9 +1270,9 @@ _mesa_upload_state_parameters(struct gl_context *ctx,
struct gl_program_parameter_list *paramList,
uint32_t *dst)
{
int num = paramList->NumParameters;
int last = paramList->LastStateVarIndex;
for (int i = paramList->FirstStateVarIndex; i < num; i++) {
for (int i = paramList->FirstStateVarIndex; i <= last; i++) {
unsigned pvo = paramList->Parameters[i].ValueOffset;
fetch_state(ctx, paramList->Parameters[i].StateIndexes,
(gl_constant_value*)(dst + pvo));
......@@ -1462,4 +1462,6 @@ _mesa_optimize_state_parameters(struct gl_constants *consts,
list->NumParameters -= param_diff;
}
}
_mesa_recompute_parameter_bounds(list);
}
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