From: Ian Romanick <ian.d.roman...@intel.com> v2: Also account for the ralloc header overhead.
Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- src/glsl/Makefile.sources | 1 + src/glsl/ir_memory_usage.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++ src/glsl/ir_memory_usage.h | 48 ++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 src/glsl/ir_memory_usage.cpp create mode 100644 src/glsl/ir_memory_usage.h diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources index 5945590..6e230f7 100644 --- a/src/glsl/Makefile.sources +++ b/src/glsl/Makefile.sources @@ -41,6 +41,7 @@ LIBGLSL_FILES = \ $(GLSL_SRCDIR)/ir_hierarchical_visitor.cpp \ $(GLSL_SRCDIR)/ir_hv_accept.cpp \ $(GLSL_SRCDIR)/ir_import_prototypes.cpp \ + $(GLSL_SRCDIR)/ir_memory_usage.cpp \ $(GLSL_SRCDIR)/ir_print_visitor.cpp \ $(GLSL_SRCDIR)/ir_reader.cpp \ $(GLSL_SRCDIR)/ir_rvalue_visitor.cpp \ diff --git a/src/glsl/ir_memory_usage.cpp b/src/glsl/ir_memory_usage.cpp new file mode 100644 index 0000000..68c0b5c --- /dev/null +++ b/src/glsl/ir_memory_usage.cpp @@ -0,0 +1,104 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_memory_usage.cpp + * Determine the amount of memory used by different kinds of IR in a shader. + */ + +#include "ir.h" +#include "ir_hierarchical_visitor.h" +#include "ir_memory_usage.h" + +class ir_memory_usage : public ir_hierarchical_visitor { +public: + ir_memory_usage() + { + memset(&this->s, 0, sizeof(this->s)); + } + + ~ir_memory_usage() + { + /* empty */ + } + + virtual ir_visitor_status visit(ir_variable *v); + virtual ir_visitor_status visit(ir_dereference_variable *ir); + virtual ir_visitor_status visit_enter(class ir_dereference_array *); + virtual ir_visitor_status visit_enter(class ir_dereference_record *); + + ir_memory_statistics s; +}; + +/* In release builds, the ralloc header contains 5 pointers. + */ +static const unsigned ralloc_header_size = 5 * sizeof(void *); + +ir_visitor_status +ir_memory_usage::visit(ir_variable *ir) +{ + this->s.variable_usage += sizeof(*ir); + + if (ir->state_slots != NULL) + this->s.variable_usage += (sizeof(ir_state_slot) * ir->num_state_slots) + + ralloc_header_size; + + this->s.variable_name_usage += strlen(ir->name) + 1 + ralloc_header_size; + + return visit_continue; +} + + +ir_visitor_status +ir_memory_usage::visit(ir_dereference_variable *ir) +{ + this->s.dereference_variable_usage += sizeof(*ir); + + return visit_continue; +} + +ir_visitor_status +ir_memory_usage::visit_enter(class ir_dereference_array *ir) +{ + this->s.dereference_array_usage += sizeof(*ir); + return visit_continue; +} + +ir_visitor_status +ir_memory_usage::visit_enter(class ir_dereference_record *ir) +{ + this->s.dereference_record_usage += sizeof(*ir); + this->s.dereference_record_field_usage += strlen(ir->field) + 1 + + ralloc_header_size; + return visit_continue; +} + +extern "C" void +calculate_ir_tree_memory_usage(exec_list *instructions, + struct ir_memory_statistics *stats) +{ + ir_memory_usage v; + + v.run(instructions); + *stats = v.s; +} diff --git a/src/glsl/ir_memory_usage.h b/src/glsl/ir_memory_usage.h new file mode 100644 index 0000000..3d137a3 --- /dev/null +++ b/src/glsl/ir_memory_usage.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef IR_MEMORY_USAGE_H +#define IR_MEMORY_USAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct ir_memory_statistics { + unsigned variable_usage; + unsigned variable_name_usage; + unsigned dereference_variable_usage; + unsigned dereference_array_usage; + unsigned dereference_record_usage; + unsigned dereference_record_field_usage; +}; + +void +calculate_ir_tree_memory_usage(struct exec_list *instructions, + struct ir_memory_statistics *stats); + +#ifdef __cplusplus +} +#endif + +#endif /* IR_MEMORY_USAGE_H */ -- 1.8.1.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev