[Mesa-dev] [PATCH 2/5] glsl: Adds ir_variable class a location_tree * field.
Vincent Lejeune
vljn at ovi.com
Tue Jan 24 13:05:11 PST 2012
This patch adds a location_tree * field to ir_variable class.
Such field is aimed at replacing the location field in 2 cases :
- If the variable is a varying,
- If the variable is stored in an UBO.
In the later case, the UBO spec has precise requirements on the storage
layout of every UBO variables. These requirements cannot be met with
the current way of representing a variable location (float alignement is
4 bytes, not 16).
In the former case, code generator requires at least the ability to
distinguish components of varyings sharing a same register. Moreover
aggressive packing algorithms might want to reorder structure fields,
and interleaves array components to minimise output register usage.
location_tree data structure answers both use cases.
---
src/glsl/ir.cpp | 2 ++
src/glsl/ir.h | 12 +++++++++++-
src/glsl/ir_clone.cpp | 4 ++++
3 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index a5eca5a..ce89b1b 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -26,6 +26,7 @@
#include "ir_visitor.h"
#include "glsl_types.h"
+
ir_rvalue::ir_rvalue()
{
this->type = glsl_type::error_type;
@@ -1328,6 +1329,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
this->explicit_location = false;
this->has_initializer = false;
this->location = -1;
+ this->complete_location = NULL;
this->warn_extension = NULL;
this->constant_value = NULL;
this->constant_initializer = NULL;
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 1faae3c..d206326 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -34,6 +34,7 @@
#include "list.h"
#include "ir_visitor.h"
#include "ir_hierarchical_visitor.h"
+#include "location_tree.h"
#include "main/mtypes.h"
/**
@@ -131,7 +132,6 @@ protected:
}
};
-
class ir_rvalue : public ir_instruction {
public:
virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0;
@@ -398,6 +398,16 @@ public:
int location;
/**
+ * Precise storage locations of this variable
+ * It is not always sufficient to associate a single int to location of
+ * a variable. For instance one might want to store a variable in an order
+ * not following declaration order or to have arrays whose registers
+ * overlap (but not components inside these registers, of course).
+ *
+ */
+ union location_tree *complete_location;
+
+ /**
* Built-in state that backs this uniform
*
* Once set at variable creation, \c state_slots must remain invariant.
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index c63615c..429127b 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -53,6 +53,10 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
var->has_initializer = this->has_initializer;
var->depth_layout = this->depth_layout;
+ if (this->complete_location) {
+ var->complete_location = location_tree_duplicate(var, this->complete_location, var->type);
+ }
+
var->num_state_slots = this->num_state_slots;
if (this->state_slots) {
/* FINISHME: This really wants to use something like talloc_reference, but
--
1.7.7
More information about the mesa-dev
mailing list