Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkSLContext.h" | |
| 9 #include "SkSLMemoryLayout.h" | |
| 10 | |
| 11 #include "Test.h" | |
| 12 | |
| 13 #if SK_SUPPORT_GPU | |
| 14 | |
| 15 DEF_TEST(SkSLMemoryLayout140Test, r) { | |
| 16 SkSL::Context context; | |
| 17 SkSL::MemoryLayout layout(SkSL::MemoryLayout::k140_Standard); | |
| 18 | |
| 19 // basic types | |
| 20 REPORTER_ASSERT(r, 4 == layout.size(*context.fFloat_Type)); | |
| 21 REPORTER_ASSERT(r, 8 == layout.size(*context.fVec2_Type)); | |
| 22 REPORTER_ASSERT(r, 12 == layout.size(*context.fVec3_Type)); | |
| 23 REPORTER_ASSERT(r, 16 == layout.size(*context.fVec4_Type)); | |
| 24 REPORTER_ASSERT(r, 4 == layout.size(*context.fInt_Type)); | |
| 25 REPORTER_ASSERT(r, 8 == layout.size(*context.fIVec2_Type)); | |
| 26 REPORTER_ASSERT(r, 12 == layout.size(*context.fIVec3_Type)); | |
| 27 REPORTER_ASSERT(r, 16 == layout.size(*context.fIVec4_Type)); | |
| 28 REPORTER_ASSERT(r, 1 == layout.size(*context.fBool_Type)); | |
| 29 REPORTER_ASSERT(r, 2 == layout.size(*context.fBVec2_Type)); | |
| 30 REPORTER_ASSERT(r, 3 == layout.size(*context.fBVec3_Type)); | |
| 31 REPORTER_ASSERT(r, 4 == layout.size(*context.fBVec4_Type)); | |
| 32 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fFloat_Type)); | |
| 33 REPORTER_ASSERT(r, 8 == layout.alignment(*context.fVec2_Type)); | |
| 34 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec3_Type)); | |
| 35 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec4_Type)); | |
| 36 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fInt_Type)); | |
| 37 REPORTER_ASSERT(r, 8 == layout.alignment(*context.fIVec2_Type)); | |
| 38 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec3_Type)); | |
| 39 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec4_Type)); | |
| 40 REPORTER_ASSERT(r, 1 == layout.alignment(*context.fBool_Type)); | |
| 41 REPORTER_ASSERT(r, 2 == layout.alignment(*context.fBVec2_Type)); | |
| 42 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec3_Type)); | |
| 43 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec4_Type)); | |
| 44 | |
| 45 // struct 1 | |
| 46 std::vector<SkSL::Type::Field> fields1; | |
| 47 fields1.emplace_back(SkSL::Modifiers(), "a", context.fVec3_Type.get()); | |
| 48 SkSL::Type s1("s1", fields1); | |
| 49 REPORTER_ASSERT(r, 16 == layout.size(s1)); | |
| 50 REPORTER_ASSERT(r, 16 == layout.alignment(s1)); | |
| 51 | |
| 52 fields1.emplace_back(SkSL::Modifiers(), "b", context.fFloat_Type.get()); | |
| 53 SkSL::Type s2("s2", fields1); | |
| 54 REPORTER_ASSERT(r, 16 == layout.size(s2)); | |
| 55 REPORTER_ASSERT(r, 16 == layout.alignment(s2)); | |
| 56 | |
| 57 fields1.emplace_back(SkSL::Modifiers(), "c", context.fBool_Type.get()); | |
| 58 SkSL::Type s3("s3", fields1); | |
| 59 REPORTER_ASSERT(r, 32 == layout.size(s3)); | |
| 60 REPORTER_ASSERT(r, 16 == layout.alignment(s3)); | |
| 61 | |
| 62 // struct 2 | |
| 63 std::vector<SkSL::Type::Field> fields2; | |
| 64 fields2.emplace_back(SkSL::Modifiers(), "a", context.fInt_Type.get()); | |
| 65 SkSL::Type s4("s4", fields2); | |
| 66 REPORTER_ASSERT(r, 16 == layout.size(s4)); | |
| 67 REPORTER_ASSERT(r, 16 == layout.alignment(s4)); | |
| 68 | |
| 69 fields2.emplace_back(SkSL::Modifiers(), "b", context.fVec3_Type.get()); | |
| 70 SkSL::Type s5("s5", fields2); | |
| 71 REPORTER_ASSERT(r, 32 == layout.size(s5)); | |
| 72 REPORTER_ASSERT(r, 16 == layout.alignment(s5)); | |
| 73 | |
| 74 // arrays | |
| 75 SkSL::Type array1("float[4]", SkSL::Type::kArray_Kind, *context.fFloat_Type, 4); | |
| 76 REPORTER_ASSERT(r, 64 == layout.size(array1)); | |
| 77 REPORTER_ASSERT(r, 16 == layout.alignment(array1)); | |
| 78 REPORTER_ASSERT(r, 16 == layout.stride(array1)); | |
| 79 | |
| 80 SkSL::Type array2("vec4[4]", SkSL::Type::kArray_Kind, *context.fVec4_Type, 4 ); | |
| 81 REPORTER_ASSERT(r, 64 == layout.size(array2)); | |
| 82 REPORTER_ASSERT(r, 16 == layout.alignment(array2)); | |
| 83 REPORTER_ASSERT(r, 16 == layout.stride(array2)); | |
| 84 } | |
| 85 | |
| 86 DEF_TEST(SkSLMemoryLayout430Test, r) { | |
| 87 SkSL::Context context; | |
| 88 SkSL::MemoryLayout layout(SkSL::MemoryLayout::k430_Standard); | |
| 89 | |
| 90 // basic types | |
| 91 REPORTER_ASSERT(r, 4 == layout.size(*context.fFloat_Type)); | |
| 92 REPORTER_ASSERT(r, 8 == layout.size(*context.fVec2_Type)); | |
| 93 REPORTER_ASSERT(r, 12 == layout.size(*context.fVec3_Type)); | |
| 94 REPORTER_ASSERT(r, 16 == layout.size(*context.fVec4_Type)); | |
| 95 REPORTER_ASSERT(r, 4 == layout.size(*context.fInt_Type)); | |
| 96 REPORTER_ASSERT(r, 8 == layout.size(*context.fIVec2_Type)); | |
| 97 REPORTER_ASSERT(r, 12 == layout.size(*context.fIVec3_Type)); | |
| 98 REPORTER_ASSERT(r, 16 == layout.size(*context.fIVec4_Type)); | |
| 99 REPORTER_ASSERT(r, 1 == layout.size(*context.fBool_Type)); | |
| 100 REPORTER_ASSERT(r, 2 == layout.size(*context.fBVec2_Type)); | |
| 101 REPORTER_ASSERT(r, 3 == layout.size(*context.fBVec3_Type)); | |
| 102 REPORTER_ASSERT(r, 4 == layout.size(*context.fBVec4_Type)); | |
| 103 REPORTER_ASSERT(r, 32 == layout.size(*context.fMat2x4_Type)); | |
|
egdaniel
2016/11/15 16:59:28
I think I would just have 2x2, 3x3, and 4x4 since
| |
| 104 REPORTER_ASSERT(r, 48 == layout.size(*context.fMat3x3_Type)); | |
| 105 REPORTER_ASSERT(r, 32 == layout.size(*context.fMat4x2_Type)); | |
| 106 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fFloat_Type)); | |
| 107 REPORTER_ASSERT(r, 8 == layout.alignment(*context.fVec2_Type)); | |
| 108 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec3_Type)); | |
| 109 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fVec4_Type)); | |
| 110 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fInt_Type)); | |
| 111 REPORTER_ASSERT(r, 8 == layout.alignment(*context.fIVec2_Type)); | |
| 112 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec3_Type)); | |
| 113 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fIVec4_Type)); | |
| 114 REPORTER_ASSERT(r, 1 == layout.alignment(*context.fBool_Type)); | |
| 115 REPORTER_ASSERT(r, 2 == layout.alignment(*context.fBVec2_Type)); | |
| 116 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec3_Type)); | |
| 117 REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBVec4_Type)); | |
| 118 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fMat2x4_Type)); | |
| 119 REPORTER_ASSERT(r, 16 == layout.alignment(*context.fMat3x3_Type)); | |
| 120 REPORTER_ASSERT(r, 8 == layout.alignment(*context.fMat4x2_Type)); | |
| 121 | |
| 122 // struct 1 | |
| 123 std::vector<SkSL::Type::Field> fields1; | |
| 124 fields1.emplace_back(SkSL::Modifiers(), "a", context.fVec3_Type.get()); | |
| 125 SkSL::Type s1("s1", fields1); | |
| 126 REPORTER_ASSERT(r, 16 == layout.size(s1)); | |
| 127 REPORTER_ASSERT(r, 16 == layout.alignment(s1)); | |
| 128 | |
| 129 fields1.emplace_back(SkSL::Modifiers(), "b", context.fFloat_Type.get()); | |
| 130 SkSL::Type s2("s2", fields1); | |
| 131 REPORTER_ASSERT(r, 16 == layout.size(s2)); | |
| 132 REPORTER_ASSERT(r, 16 == layout.alignment(s2)); | |
| 133 | |
| 134 fields1.emplace_back(SkSL::Modifiers(), "c", context.fBool_Type.get()); | |
| 135 SkSL::Type s3("s3", fields1); | |
| 136 REPORTER_ASSERT(r, 32 == layout.size(s3)); | |
| 137 REPORTER_ASSERT(r, 16 == layout.alignment(s3)); | |
| 138 | |
| 139 // struct 2 | |
| 140 std::vector<SkSL::Type::Field> fields2; | |
| 141 fields2.emplace_back(SkSL::Modifiers(), "a", context.fInt_Type.get()); | |
| 142 SkSL::Type s4("s4", fields2); | |
| 143 REPORTER_ASSERT(r, 4 == layout.size(s4)); | |
| 144 REPORTER_ASSERT(r, 4 == layout.alignment(s4)); | |
| 145 | |
| 146 fields2.emplace_back(SkSL::Modifiers(), "b", context.fVec3_Type.get()); | |
| 147 SkSL::Type s5("s5", fields2); | |
| 148 REPORTER_ASSERT(r, 32 == layout.size(s5)); | |
| 149 REPORTER_ASSERT(r, 16 == layout.alignment(s5)); | |
| 150 | |
| 151 // arrays | |
| 152 SkSL::Type array1("float[4]", SkSL::Type::kArray_Kind, *context.fFloat_Type, 4); | |
| 153 REPORTER_ASSERT(r, 16 == layout.size(array1)); | |
| 154 REPORTER_ASSERT(r, 4 == layout.alignment(array1)); | |
| 155 REPORTER_ASSERT(r, 4 == layout.stride(array1)); | |
| 156 | |
| 157 SkSL::Type array2("vec4[4]", SkSL::Type::kArray_Kind, *context.fVec4_Type, 4 ); | |
| 158 REPORTER_ASSERT(r, 64 == layout.size(array2)); | |
| 159 REPORTER_ASSERT(r, 16 == layout.alignment(array2)); | |
| 160 REPORTER_ASSERT(r, 16 == layout.stride(array2)); | |
| 161 } | |
| 162 #endif | |
| OLD | NEW |