glsl: Use ir_builder more in opt_algebraic.
[mesa.git] / src / glsl / link_uniform_blocks.cpp
index 1083653c7d6db27a1fab50104c2af3d78f938a48..72d6c5323a6ebe90a4117bf4e8ac56eaa88d4df6 100644 (file)
@@ -29,6 +29,8 @@
 #include "main/hash_table.h"
 #include "program.h"
 
+namespace {
+
 class ubo_visitor : public program_resource_visitor {
 public:
    ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
@@ -58,6 +60,15 @@ public:
 private:
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool row_major)
+   {
+      (void) type;
+      (void) name;
+      (void) row_major;
+      assert(!"Should not get here.");
+   }
+
+   virtual void visit_field(const glsl_type *type, const char *name,
+                            bool row_major, const glsl_type *record_type)
    {
       assert(this->index < this->num_variables);
 
@@ -85,7 +96,9 @@ private:
          v->IndexName = v->Name;
       }
 
-      unsigned alignment = type->std140_base_alignment(v->RowMajor);
+      const unsigned alignment = record_type
+        ? record_type->std140_base_alignment(v->RowMajor)
+        : type->std140_base_alignment(v->RowMajor);
       unsigned size = type->std140_size(v->RowMajor);
 
       this->offset = glsl_align(this->offset, alignment);
@@ -107,6 +120,10 @@ private:
 
    virtual void visit_field(const glsl_struct_field *field)
    {
+      /* FINISHME: When support for doubles (dvec4, etc.) is added to the
+       * FINISHME: compiler, this may be incorrect for a structure in a UBO
+       * FINISHME: like struct s { struct { float f } s1; dvec4 v; };.
+       */
       this->offset = glsl_align(this->offset,
                                 field->type->std140_base_alignment(false));
    }
@@ -132,6 +149,8 @@ private:
    }
 };
 
+} /* anonymous namespace */
+
 struct block {
    const glsl_type *type;
    bool has_instance_name;