| Index: src/sksl/ir/SkSLType.h
|
| diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
|
| index 3c31b6b53d49ef0a9ec9b8fa8788037ce8dc801f..afd00d8b2af41d9a54c7b61047558dcb871d34f8 100644
|
| --- a/src/sksl/ir/SkSLType.h
|
| +++ b/src/sksl/ir/SkSLType.h
|
| @@ -236,6 +236,87 @@
|
| bool isSampled() const {
|
| ASSERT(fTypeKind == kSampler_Kind);
|
| return fIsSampled;
|
| + }
|
| +
|
| + static size_t vector_alignment(size_t componentSize, int columns) {
|
| + return componentSize * (columns + columns % 2);
|
| + }
|
| +
|
| + /**
|
| + * Returns the type's required alignment (when putting this type into a struct, the offset must
|
| + * be a multiple of the alignment).
|
| + */
|
| + size_t alignment() const {
|
| + // See OpenGL Spec 7.6.2.2 Standard Uniform Block Layout
|
| + switch (fTypeKind) {
|
| + case kScalar_Kind:
|
| + return this->size();
|
| + case kVector_Kind:
|
| + return vector_alignment(fComponentType->size(), fColumns);
|
| + case kMatrix_Kind:
|
| + return (vector_alignment(fComponentType->size(), fRows) + 15) & ~15;
|
| + case kArray_Kind:
|
| + // round up to next multiple of 16
|
| + return (fComponentType->alignment() + 15) & ~15;
|
| + case kStruct_Kind: {
|
| + size_t result = 16;
|
| + for (size_t i = 0; i < fFields.size(); i++) {
|
| + size_t alignment = fFields[i].fType->alignment();
|
| + if (alignment > result) {
|
| + result = alignment;
|
| + }
|
| + }
|
| + }
|
| + default:
|
| + ABORT(("cannot determine size of type " + fName).c_str());
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * For matrices and arrays, returns the number of bytes from the start of one entry (row, in
|
| + * the case of matrices) to the start of the next.
|
| + */
|
| + size_t stride() const {
|
| + switch (fTypeKind) {
|
| + case kMatrix_Kind: // fall through
|
| + case kArray_Kind:
|
| + return this->alignment();
|
| + default:
|
| + ABORT("type does not have a stride");
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Returns the size of this type in bytes.
|
| + */
|
| + size_t size() const {
|
| + switch (fTypeKind) {
|
| + case kScalar_Kind:
|
| + // FIXME need to take precision into account, once we figure out how we want to
|
| + // handle it...
|
| + return 4;
|
| + case kVector_Kind:
|
| + return fColumns * fComponentType->size();
|
| + case kMatrix_Kind:
|
| + return vector_alignment(fComponentType->size(), fRows) * fColumns;
|
| + case kArray_Kind:
|
| + return fColumns * this->stride();
|
| + case kStruct_Kind: {
|
| + size_t total = 0;
|
| + for (size_t i = 0; i < fFields.size(); i++) {
|
| + size_t alignment = fFields[i].fType->alignment();
|
| + if (total % alignment != 0) {
|
| + total += alignment - total % alignment;
|
| + }
|
| + ASSERT(false);
|
| + ASSERT(total % alignment == 0);
|
| + total += fFields[i].fType->size();
|
| + }
|
| + return total;
|
| + }
|
| + default:
|
| + ABORT(("cannot determine size of type " + fName).c_str());
|
| + }
|
| }
|
|
|
| /**
|
|
|