Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Unified Diff: src/sksl/ir/SkSLType.h

Issue 2509673002: Revert of added support for push_constant layout (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/sksl/ir/SkSLModifiers.h ('k') | tests/SkSLErrorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+ }
}
/**
« no previous file with comments | « src/sksl/ir/SkSLModifiers.h ('k') | tests/SkSLErrorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698