Mesa (master): glsl: use a non-malloc' d storage for short ir_variable names
Marek Olšák
mareko at kemper.freedesktop.org
Mon Oct 31 11:26:38 UTC 2016
Module: Mesa
Branch: master
Commit: 7a2387c3e0e91f649676661c607d71f3b4eba5d5
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a2387c3e0e91f649676661c607d71f3b4eba5d5
Author: Marek Olšák <marek.olsak at amd.com>
Date: Fri Oct 7 22:26:58 2016 +0200
glsl: use a non-malloc'd storage for short ir_variable names
Tested-by: Edmondo Tommasina <edmondo.tommasina at gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/compiler/glsl/ir.cpp | 4 ++++
src/compiler/glsl/ir.h | 13 ++++++++++++-
src/compiler/glsl/lower_packed_varyings.cpp | 8 ++++++--
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index c5943e5..8e4b382 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -1523,6 +1523,10 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
if (mode == ir_var_temporary
&& (name == NULL || name == ir_variable::tmp_name)) {
this->name = ir_variable::tmp_name;
+ } else if (name == NULL ||
+ strlen(name) < ARRAY_SIZE(this->name_storage)) {
+ strcpy(this->name_storage, name ? name : "");
+ this->name = this->name_storage;
} else {
this->name = ralloc_strdup(this, name);
}
diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index f07e3b2..433ba19 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -599,7 +599,8 @@ public:
inline bool is_name_ralloced() const
{
- return this->name != ir_variable::tmp_name;
+ return this->name != ir_variable::tmp_name &&
+ this->name != this->name_storage;
}
/**
@@ -624,6 +625,16 @@ public:
*/
const char *name;
+private:
+ /**
+ * If the name length fits into name_storage, it's used, otherwise
+ * the name is ralloc'd. shader-db mining showed that 70% of variables
+ * fit here. This is a win over ralloc where only ralloc_header has
+ * 20 bytes on 64-bit (28 bytes with DEBUG), and we can also skip malloc.
+ */
+ char name_storage[16];
+
+public:
struct ir_variable_data {
/**
diff --git a/src/compiler/glsl/lower_packed_varyings.cpp b/src/compiler/glsl/lower_packed_varyings.cpp
index 1e8cf11..19bbe57 100644
--- a/src/compiler/glsl/lower_packed_varyings.cpp
+++ b/src/compiler/glsl/lower_packed_varyings.cpp
@@ -639,8 +639,12 @@ lower_packed_varyings_visitor::get_packed_varying_deref(
* first time we visit each component.
*/
if (this->gs_input_vertices == 0 || vertex_index == 0) {
- ralloc_asprintf_append((char **) &this->packed_varyings[slot]->name,
- ",%s", name);
+ ir_variable *var = this->packed_varyings[slot];
+
+ if (var->is_name_ralloced())
+ ralloc_asprintf_append((char **) &var->name, ",%s", name);
+ else
+ var->name = ralloc_asprintf(var, "%s,%s", var->name, name);
}
}
More information about the mesa-commit
mailing list