Chromium Code Reviews| Index: tests/SkSLMemoryLayoutTest.cpp |
| diff --git a/tests/SkSLMemoryLayoutTest.cpp b/tests/SkSLMemoryLayoutTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a9e6102d95ee8f48208ab364aa04ec45efde640 |
| --- /dev/null |
| +++ b/tests/SkSLMemoryLayoutTest.cpp |
| @@ -0,0 +1,156 @@ |
| +/* |
| + * Copyright 2016 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkSLContext.h" |
| +#include "SkSLMemoryLayout.h" |
| + |
| +#include "Test.h" |
| + |
| +#if SK_SUPPORT_GPU |
| + |
| +DEF_TEST(SkSLMemoryLayout140Test, r) { |
| + SkSL::Context context; |
| + SkSL::MemoryLayout layout(SkSL::MemoryLayout::k140_Standard); |
| + |
| + // basic types |
| + REPORTER_ASSERT(r, layout.size(*context.fFloat_Type) == 4); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec3_Type) == 12); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.size(*context.fInt_Type) == 4); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec3_Type) == 12); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec4_Type) == 16); |
|
egdaniel
2016/11/15 15:31:18
Add mats to this
|
| + REPORTER_ASSERT(r, layout.size(*context.fBool_Type) == 1); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec2_Type) == 2); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec3_Type) == 3); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec4_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fFloat_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec3_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fInt_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec3_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBool_Type) == 1); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec2_Type) == 2); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec3_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec4_Type) == 4); |
| + |
| + // struct 1 |
| + std::vector<SkSL::Type::Field> fields1; |
| + fields1.emplace_back(SkSL::Modifiers(), "a", context.fVec3_Type.get()); |
| + SkSL::Type s1("s1", fields1); |
| + REPORTER_ASSERT(r, layout.size(s1) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(s1) == 16); |
| + |
| + fields1.emplace_back(SkSL::Modifiers(), "b", context.fFloat_Type.get()); |
| + SkSL::Type s2("s2", fields1); |
| + REPORTER_ASSERT(r, layout.size(s2) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(s2) == 16); |
| + |
| + fields1.emplace_back(SkSL::Modifiers(), "c", context.fBool_Type.get()); |
| + SkSL::Type s3("s3", fields1); |
| + REPORTER_ASSERT(r, layout.size(s3) == 32); |
| + REPORTER_ASSERT(r, layout.alignment(s3) == 16); |
| + |
| + // struct 2 |
| + std::vector<SkSL::Type::Field> fields2; |
| + fields2.emplace_back(SkSL::Modifiers(), "a", context.fInt_Type.get()); |
| + SkSL::Type s4("s4", fields2); |
| + REPORTER_ASSERT(r, layout.size(s4) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(s4) == 16); |
| + |
| + fields2.emplace_back(SkSL::Modifiers(), "b", context.fVec3_Type.get()); |
| + SkSL::Type s5("s5", fields2); |
| + REPORTER_ASSERT(r, layout.size(s5) == 32); |
| + REPORTER_ASSERT(r, layout.alignment(s5) == 16); |
| + |
| + // arrays |
| + SkSL::Type array1("float[4]", SkSL::Type::kArray_Kind, *context.fFloat_Type, 4); |
| + REPORTER_ASSERT(r, layout.size(array1) == 64); |
| + REPORTER_ASSERT(r, layout.alignment(array1) == 16); |
| + REPORTER_ASSERT(r, layout.stride(array1) == 16); |
| + |
| + SkSL::Type array2("vec4[4]", SkSL::Type::kArray_Kind, *context.fVec4_Type, 4); |
| + REPORTER_ASSERT(r, layout.size(array2) == 64); |
| + REPORTER_ASSERT(r, layout.alignment(array2) == 16); |
| + REPORTER_ASSERT(r, layout.stride(array2) == 16); |
| +} |
| + |
| +DEF_TEST(SkSLMemoryLayout430Test, r) { |
| + SkSL::Context context; |
| + SkSL::MemoryLayout layout(SkSL::MemoryLayout::k430_Standard); |
| + |
| + // basic types |
| + REPORTER_ASSERT(r, layout.size(*context.fFloat_Type) == 4); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec3_Type) == 12); |
| + REPORTER_ASSERT(r, layout.size(*context.fVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.size(*context.fInt_Type) == 4); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec3_Type) == 12); |
| + REPORTER_ASSERT(r, layout.size(*context.fIVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.size(*context.fBool_Type) == 1); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec2_Type) == 2); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec3_Type) == 3); |
| + REPORTER_ASSERT(r, layout.size(*context.fBVec4_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fFloat_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec3_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fInt_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec2_Type) == 8); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec3_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fIVec4_Type) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBool_Type) == 1); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec2_Type) == 2); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec3_Type) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(*context.fBVec4_Type) == 4); |
| + |
| + // struct 1 |
| + std::vector<SkSL::Type::Field> fields1; |
| + fields1.emplace_back(SkSL::Modifiers(), "a", context.fVec3_Type.get()); |
| + SkSL::Type s1("s1", fields1); |
| + REPORTER_ASSERT(r, layout.size(s1) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(s1) == 16); |
| + |
| + fields1.emplace_back(SkSL::Modifiers(), "b", context.fFloat_Type.get()); |
| + SkSL::Type s2("s2", fields1); |
| + REPORTER_ASSERT(r, layout.size(s2) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(s2) == 16); |
| + |
| + fields1.emplace_back(SkSL::Modifiers(), "c", context.fBool_Type.get()); |
| + SkSL::Type s3("s3", fields1); |
| + REPORTER_ASSERT(r, layout.size(s3) == 32); |
| + REPORTER_ASSERT(r, layout.alignment(s3) == 16); |
| + |
| + // struct 2 |
| + std::vector<SkSL::Type::Field> fields2; |
| + fields2.emplace_back(SkSL::Modifiers(), "a", context.fInt_Type.get()); |
| + SkSL::Type s4("s4", fields2); |
| + REPORTER_ASSERT(r, layout.size(s4) == 4); |
| + REPORTER_ASSERT(r, layout.alignment(s4) == 4); |
| + |
| + fields2.emplace_back(SkSL::Modifiers(), "b", context.fVec3_Type.get()); |
| + SkSL::Type s5("s5", fields2); |
| + REPORTER_ASSERT(r, layout.size(s5) == 32); |
| + REPORTER_ASSERT(r, layout.alignment(s5) == 16); |
| + |
| + // arrays |
| + SkSL::Type array1("float[4]", SkSL::Type::kArray_Kind, *context.fFloat_Type, 4); |
| + REPORTER_ASSERT(r, layout.size(array1) == 16); |
| + REPORTER_ASSERT(r, layout.alignment(array1) == 4); |
| + REPORTER_ASSERT(r, layout.stride(array1) == 4); |
| + |
| + SkSL::Type array2("vec4[4]", SkSL::Type::kArray_Kind, *context.fVec4_Type, 4); |
| + REPORTER_ASSERT(r, layout.size(array2) == 64); |
| + REPORTER_ASSERT(r, layout.alignment(array2) == 16); |
| + REPORTER_ASSERT(r, layout.stride(array2) == 16); |
| +} |
| +#endif |