Mesa (master): mesa: fix assertion paramList->LastUniformIndex < paramList->FirstStateVarIndex
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Dec 18 05:12:35 UTC 2020
Module: Mesa
Branch: master
Commit: 23dc21b9d6d777831e3faa50db297b54d4caf1b7
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=23dc21b9d6d777831e3faa50db297b54d4caf1b7
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Dec 11 16:04:58 2020 -0500
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: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3914
Reviewed-by: Zoltán Böszörményi <zboszor at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8046>
---
src/mesa/program/prog_parameter.c | 3 ++-
src/mesa/program/prog_parameter.h | 4 +++-
src/mesa/program/prog_statevars.c | 18 ++++++++++++------
src/mesa/program/prog_statevars.h | 2 ++
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index 712eccebc3e..40b1c10a49f 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -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);
}
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index bc07dc09531..d625897692a 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -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;
diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index da547cb419c..64bff6fcfa8 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -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:
diff --git a/src/mesa/program/prog_statevars.h b/src/mesa/program/prog_statevars.h
index bc7325a32ae..8832d4ef9c5 100644
--- a/src/mesa/program/prog_statevars.h
+++ b/src/mesa/program/prog_statevars.h
@@ -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. */
More information about the mesa-commit
mailing list