From 0e1680a1e2aa67b3cb132bdd4f615694ff9454af Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 20 Sep 2019 18:04:15 +0200 Subject: [PATCH] glsl: Add a method to get precision from a deref instruction Adds ir_dereference::precision(). For a normal variable dereference, the precision comes from the variable. For a record member it comes from the field within the record. For an array it can come from either, depending on where the underlying array is stored. The method recursively walks the derefs until it finds one of the first two. Reviewed-by: Kristian H. Kristensen Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/ir.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index 2e20f4bee7a..e84da9a5027 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -2047,6 +2047,12 @@ public: */ virtual ir_variable *variable_referenced() const = 0; + /** + * Get the precision. This can either come from the eventual variable that + * is dereferenced, or from a record member. + */ + virtual int precision() const = 0; + protected: ir_dereference(enum ir_node_type t) : ir_rvalue(t) @@ -2076,6 +2082,11 @@ public: return this->var; } + virtual int precision() const + { + return this->var->data.precision; + } + virtual ir_variable *whole_variable_referenced() { /* ir_dereference_variable objects always dereference the entire @@ -2124,6 +2135,16 @@ public: return this->array->variable_referenced(); } + virtual int precision() const + { + ir_dereference *deref = this->array->as_dereference(); + + if (deref == NULL) + return GLSL_PRECISION_NONE; + else + return deref->precision(); + } + virtual void accept(ir_visitor *v) { v->visit(this); @@ -2159,6 +2180,13 @@ public: return this->record->variable_referenced(); } + virtual int precision() const + { + glsl_struct_field *field = record->type->fields.structure + field_idx; + + return field->precision; + } + virtual void accept(ir_visitor *v) { v->visit(this); -- 2.30.2