[Mesa-dev] [PATCH 4/7] nir: add couple array length fields
Rob Clark
robdclark at gmail.com
Sat Oct 24 10:07:57 PDT 2015
From: Rob Clark <robclark at freedesktop.org>
This will simplify things somewhat in clone.
Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
src/glsl/nir/glsl_to_nir.cpp | 6 ++++++
src/glsl/nir/nir.h | 11 +++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 9b50a93..8f83012 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -238,6 +238,8 @@ constant_copy(ir_constant *ir, void *mem_ctx)
unsigned total_elems = ir->type->components();
unsigned i;
+
+ ret->num_elements = 0;
switch (ir->type->base_type) {
case GLSL_TYPE_UINT:
for (i = 0; i < total_elems; i++)
@@ -262,6 +264,8 @@ constant_copy(ir_constant *ir, void *mem_ctx)
case GLSL_TYPE_STRUCT:
ret->elements = ralloc_array(mem_ctx, nir_constant *,
ir->type->length);
+ ret->num_elements = ir->type->length;
+
i = 0;
foreach_in_list(ir_constant, field, &ir->components) {
ret->elements[i] = constant_copy(field, mem_ctx);
@@ -272,6 +276,7 @@ constant_copy(ir_constant *ir, void *mem_ctx)
case GLSL_TYPE_ARRAY:
ret->elements = ralloc_array(mem_ctx, nir_constant *,
ir->type->length);
+ ret->num_elements = ir->type->length;
for (i = 0; i < ir->type->length; i++)
ret->elements[i] = constant_copy(ir->array_elements[i], mem_ctx);
@@ -293,6 +298,7 @@ nir_visitor::visit(ir_variable *ir)
if (ir->is_interface_instance() && ir->get_max_ifc_array_access() != NULL) {
unsigned size = ir->get_interface_type()->length;
+ var->num_max_ifc_array_access = size;
var->max_ifc_array_access = ralloc_array(var, unsigned, size);
memcpy(var->max_ifc_array_access, ir->get_max_ifc_array_access(),
size * sizeof(unsigned));
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index a09c2a6..2d9c94c 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -112,6 +112,11 @@ typedef struct nir_constant {
*/
union nir_constant_data value;
+ /* we could get this from the var->type but makes clone *much* easier to
+ * not have to care about the type.
+ */
+ unsigned num_elements;
+
/* Array elements / Structure Fields */
struct nir_constant **elements;
} nir_constant;
@@ -148,6 +153,12 @@ typedef struct {
*/
char *name;
+ /* we could figure this out from interface_type but it isn't exposed
+ * cleanly outside of c++ and just having the length here simplifies
+ * clone:
+ */
+ unsigned num_max_ifc_array_access;
+
/**
* For variables which satisfy the is_interface_instance() predicate, this
* points to an array of integers such that if the ith member of the
--
2.5.0
More information about the mesa-dev
mailing list