Mesa (master): mesa: add upper bound to limit program state var iterations
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jan 21 22:16:31 UTC 2021
Module: Mesa
Branch: master
Commit: fb73058ad2b6b0d143078b9bdc6688ec6275ec87
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fb73058ad2b6b0d143078b9bdc6688ec6275ec87
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Dec 11 19:35:16 2020 -0500
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 <zboszor at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8183>
---
src/compiler/glsl/serialize.cpp | 2 ++
src/mesa/program/prog_parameter.c | 5 +++++
src/mesa/program/prog_parameter.h | 1 +
src/mesa/program/prog_statevars.c | 10 ++++++----
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/compiler/glsl/serialize.cpp b/src/compiler/glsl/serialize.cpp
index cb12253f5a2..b5c286b0f2c 100644
--- a/src/compiler/glsl/serialize.cpp
+++ b/src/compiler/glsl/serialize.cpp
@@ -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
diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index 910bb269913..542d6e1f5a2 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -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);
}
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index 013515ca69e..2ea4f368abd 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -154,6 +154,7 @@ struct gl_program_parameter_list
*/
int UniformBytes;
int FirstStateVarIndex;
+ int LastStateVarIndex;
};
diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
index 3d0f14d9a8e..eb48a5e8a3c 100644
--- a/src/mesa/program/prog_statevars.c
+++ b/src/mesa/program/prog_statevars.c
@@ -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);
}
More information about the mesa-commit
mailing list