[Mesa-dev] [PATCH 02/21] mesa: Log memory usage statistics for all known shaders
Ian Romanick
idr at freedesktop.org
Tue May 27 19:48:57 PDT 2014
From: Ian Romanick <ian.d.romanick at intel.com>
Currently this is done at each call to glLinkProgram. This seems like
as good a place as any. This is the main place where memory usage will
change, and it enables tracking as applications progress (e.g., load new
levels).
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/mesa/main/shaderapi.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 28739da..8e8170e 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -58,6 +58,7 @@
#include "../glsl/ir.h"
#include "../glsl/ir_uniform.h"
#include "../glsl/program.h"
+#include "../glsl/ir_memory_usage.h"
/** Define this to enable shader substitution (see below) */
#define SHADER_SUBST 0
@@ -887,6 +888,56 @@ compile_shader(struct gl_context *ctx, GLuint shaderObj)
}
+#ifdef DEBUG
+static void
+memory_stats_cb(GLuint key, void *data, void *userData)
+{
+ struct ir_memory_statistics *total =
+ (struct ir_memory_statistics *) userData;
+ struct ir_memory_statistics stats;
+ struct gl_shader_program *shProg = (struct gl_shader_program *) data;
+
+ (void) key;
+
+ if (shProg->Type == GL_SHADER_PROGRAM_MESA) {
+ unsigned i;
+
+ for (i = 0; i < MESA_SHADER_STAGES; i++) {
+ struct gl_shader *sh = shProg->_LinkedShaders[i];
+
+ if (shProg->_LinkedShaders[i] != NULL) {
+ calculate_ir_tree_memory_usage(sh->ir, &stats);
+
+ total->variable_usage += stats.variable_usage;
+ total->variable_name_usage += stats.variable_name_usage;
+ total->dereference_variable_usage +=
+ stats.dereference_variable_usage;
+ total->dereference_array_usage += stats.dereference_array_usage;
+ total->dereference_record_usage += stats.dereference_record_usage;
+ total->dereference_record_field_usage +=
+ stats.dereference_record_field_usage;
+ }
+ }
+ } else {
+ struct gl_shader *sh = (struct gl_shader *) data;
+
+ assert(sh->Type == GL_FRAGMENT_SHADER
+ || sh->Type == GL_VERTEX_SHADER
+ || sh->Type == GL_GEOMETRY_SHADER_ARB);
+
+ calculate_ir_tree_memory_usage(sh->ir, &stats);
+
+ total->variable_usage += stats.variable_usage;
+ total->variable_name_usage += stats.variable_name_usage;
+ total->dereference_variable_usage += stats.dereference_variable_usage;
+ total->dereference_array_usage += stats.dereference_array_usage;
+ total->dereference_record_usage += stats.dereference_record_usage;
+ total->dereference_record_field_usage +=
+ stats.dereference_record_field_usage;
+ }
+}
+#endif /* DEBUG */
+
/**
* Link a program's shaders.
*/
@@ -920,6 +971,34 @@ link_program(struct gl_context *ctx, GLuint program)
shProg->Name, shProg->InfoLog);
}
+ /* On the first draw call, dump the memory usage statistics for *ALL*
+ * known shaders.
+ */
+#ifdef DEBUG
+ if (ctx->_Shader->Flags & GLSL_LOG) {
+ struct ir_memory_statistics stats;
+
+ memset(&stats, 0, sizeof(stats));
+ _mesa_HashWalk(ctx->Shared->ShaderObjects,
+ memory_stats_cb,
+ &stats);
+
+ printf("IR MEM: variable usage / name / total: %u %u %u\n",
+ stats.variable_usage,
+ stats.variable_name_usage,
+ stats.variable_usage + stats.variable_name_usage);
+ printf("IR MEM: dereference variable usage: %u\n",
+ stats.dereference_variable_usage);
+ printf("IR MEM: dereference array usage: %u\n",
+ stats.dereference_array_usage);
+ printf("IR MEM: dereference record usage / field / total: %u %u %u\n",
+ stats.dereference_record_usage,
+ stats.dereference_record_field_usage,
+ stats.dereference_record_usage
+ + stats.dereference_record_field_usage);
+ }
+#endif /* DEBUG */
+
/* debug code */
if (0) {
GLuint i;
--
1.8.1.4
More information about the mesa-dev
mailing list