diff options
author | Ian Romanick <[email protected]> | 2013-08-17 00:27:43 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2013-08-19 16:39:04 -0700 |
commit | 574e4843e9e26aa6affa31c80ac42f745b68268b (patch) | |
tree | 6ce82887a557f927b81c3393d49aac2d29e2d44b /src/glsl/link_uniform_blocks.cpp | |
parent | 5ac884fd9f213baed1de52eb7d17b86455c48a02 (diff) |
glsl: Use alignment of container record for its first field
The first field of a record in a UBO has the aligment of the record
itself.
Fixes piglit vs-struct-pad, fs-struct-pad, and (with the patch posted to
the piglit list that extends the test) layout-std140.
NOTE: The bit of strangeness with the version of visit_field without the
record_type poitner is because that method is pure virtual in the base
class. The original implementation of the class did this to ensure
derived classes remembered to implement that flavor. Now they can
implement either flavor but not both. I don't know a C++ way to enforce
that.
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Paul Berry <[email protected]>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=68195
Cc: "9.2 9.1" [email protected]
Diffstat (limited to 'src/glsl/link_uniform_blocks.cpp')
-rw-r--r-- | src/glsl/link_uniform_blocks.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/glsl/link_uniform_blocks.cpp b/src/glsl/link_uniform_blocks.cpp index 1083653c7d6..d9607584970 100644 --- a/src/glsl/link_uniform_blocks.cpp +++ b/src/glsl/link_uniform_blocks.cpp @@ -59,6 +59,15 @@ 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); gl_uniform_buffer_variable *v = &this->variables[this->index++]; @@ -85,7 +94,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 +118,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)); } |