1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* 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, 4 == layout.size(*context.fFloat_Type));
REPORTER_ASSERT(r, 8 == layout.size(*context.fFloat2_Type));
REPORTER_ASSERT(r, 12 == layout.size(*context.fFloat3_Type));
REPORTER_ASSERT(r, 16 == layout.size(*context.fFloat4_Type));
REPORTER_ASSERT(r, 4 == layout.size(*context.fInt_Type));
REPORTER_ASSERT(r, 8 == layout.size(*context.fInt2_Type));
REPORTER_ASSERT(r, 12 == layout.size(*context.fInt3_Type));
REPORTER_ASSERT(r, 16 == layout.size(*context.fInt4_Type));
REPORTER_ASSERT(r, 1 == layout.size(*context.fBool_Type));
REPORTER_ASSERT(r, 2 == layout.size(*context.fBool2_Type));
REPORTER_ASSERT(r, 3 == layout.size(*context.fBool3_Type));
REPORTER_ASSERT(r, 4 == layout.size(*context.fBool4_Type));
REPORTER_ASSERT(r, 32 == layout.size(*context.fFloat2x2_Type));
REPORTER_ASSERT(r, 32 == layout.size(*context.fFloat2x4_Type));
REPORTER_ASSERT(r, 48 == layout.size(*context.fFloat3x3_Type));
REPORTER_ASSERT(r, 64 == layout.size(*context.fFloat4x2_Type));
REPORTER_ASSERT(r, 64 == layout.size(*context.fFloat4x4_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fFloat_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fFloat2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat3_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat4_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fInt_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fInt2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fInt3_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fInt4_Type));
REPORTER_ASSERT(r, 1 == layout.alignment(*context.fBool_Type));
REPORTER_ASSERT(r, 2 == layout.alignment(*context.fBool2_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBool3_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBool4_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat2x2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat2x4_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat3x3_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat4x2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat4x4_Type));
// struct 1
std::vector<SkSL::Type::Field> fields1;
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("a"), context.fFloat3_Type.get());
SkSL::Type s1(SkSL::Position(), SkSL::String("s1"), fields1);
REPORTER_ASSERT(r, 16 == layout.size(s1));
REPORTER_ASSERT(r, 16 == layout.alignment(s1));
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("b"), context.fFloat_Type.get());
SkSL::Type s2(SkSL::Position(), SkSL::String("s2"), fields1);
REPORTER_ASSERT(r, 16 == layout.size(s2));
REPORTER_ASSERT(r, 16 == layout.alignment(s2));
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("c"), context.fBool_Type.get());
SkSL::Type s3(SkSL::Position(), SkSL::String("s3"), fields1);
REPORTER_ASSERT(r, 32 == layout.size(s3));
REPORTER_ASSERT(r, 16 == layout.alignment(s3));
// struct 2
std::vector<SkSL::Type::Field> fields2;
fields2.emplace_back(SkSL::Modifiers(), SkSL::String("a"), context.fInt_Type.get());
SkSL::Type s4(SkSL::Position(), SkSL::String("s4"), fields2);
REPORTER_ASSERT(r, 16 == layout.size(s4));
REPORTER_ASSERT(r, 16 == layout.alignment(s4));
fields2.emplace_back(SkSL::Modifiers(), SkSL::String("b"), context.fFloat3_Type.get());
SkSL::Type s5(SkSL::Position(), SkSL::String("s5"), fields2);
REPORTER_ASSERT(r, 32 == layout.size(s5));
REPORTER_ASSERT(r, 16 == layout.alignment(s5));
// arrays
SkSL::Type array1(SkSL::String("float[4]"), SkSL::Type::kArray_Kind, *context.fFloat_Type, 4);
REPORTER_ASSERT(r, 64 == layout.size(array1));
REPORTER_ASSERT(r, 16 == layout.alignment(array1));
REPORTER_ASSERT(r, 16 == layout.stride(array1));
SkSL::Type array2(SkSL::String("float4[4]"), SkSL::Type::kArray_Kind, *context.fFloat4_Type, 4);
REPORTER_ASSERT(r, 64 == layout.size(array2));
REPORTER_ASSERT(r, 16 == layout.alignment(array2));
REPORTER_ASSERT(r, 16 == layout.stride(array2));
}
DEF_TEST(SkSLMemoryLayout430Test, r) {
SkSL::Context context;
SkSL::MemoryLayout layout(SkSL::MemoryLayout::k430_Standard);
// basic types
REPORTER_ASSERT(r, 4 == layout.size(*context.fFloat_Type));
REPORTER_ASSERT(r, 8 == layout.size(*context.fFloat2_Type));
REPORTER_ASSERT(r, 12 == layout.size(*context.fFloat3_Type));
REPORTER_ASSERT(r, 16 == layout.size(*context.fFloat4_Type));
REPORTER_ASSERT(r, 4 == layout.size(*context.fInt_Type));
REPORTER_ASSERT(r, 8 == layout.size(*context.fInt2_Type));
REPORTER_ASSERT(r, 12 == layout.size(*context.fInt3_Type));
REPORTER_ASSERT(r, 16 == layout.size(*context.fInt4_Type));
REPORTER_ASSERT(r, 1 == layout.size(*context.fBool_Type));
REPORTER_ASSERT(r, 2 == layout.size(*context.fBool2_Type));
REPORTER_ASSERT(r, 3 == layout.size(*context.fBool3_Type));
REPORTER_ASSERT(r, 4 == layout.size(*context.fBool4_Type));
REPORTER_ASSERT(r, 16 == layout.size(*context.fFloat2x2_Type));
REPORTER_ASSERT(r, 32 == layout.size(*context.fFloat2x4_Type));
REPORTER_ASSERT(r, 48 == layout.size(*context.fFloat3x3_Type));
REPORTER_ASSERT(r, 32 == layout.size(*context.fFloat4x2_Type));
REPORTER_ASSERT(r, 64 == layout.size(*context.fFloat4x4_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fFloat_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fFloat2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat3_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat4_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fInt_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fInt2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fInt3_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fInt4_Type));
REPORTER_ASSERT(r, 1 == layout.alignment(*context.fBool_Type));
REPORTER_ASSERT(r, 2 == layout.alignment(*context.fBool2_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBool3_Type));
REPORTER_ASSERT(r, 4 == layout.alignment(*context.fBool4_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fFloat2x2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat2x4_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat3x3_Type));
REPORTER_ASSERT(r, 8 == layout.alignment(*context.fFloat4x2_Type));
REPORTER_ASSERT(r, 16 == layout.alignment(*context.fFloat4x4_Type));
// struct 1
std::vector<SkSL::Type::Field> fields1;
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("a"), context.fFloat3_Type.get());
SkSL::Type s1(SkSL::Position(), SkSL::String("s1"), fields1);
REPORTER_ASSERT(r, 16 == layout.size(s1));
REPORTER_ASSERT(r, 16 == layout.alignment(s1));
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("b"), context.fFloat_Type.get());
SkSL::Type s2(SkSL::Position(), SkSL::String("s2"), fields1);
REPORTER_ASSERT(r, 16 == layout.size(s2));
REPORTER_ASSERT(r, 16 == layout.alignment(s2));
fields1.emplace_back(SkSL::Modifiers(), SkSL::String("c"), context.fBool_Type.get());
SkSL::Type s3(SkSL::Position(), SkSL::String("s3"), fields1);
REPORTER_ASSERT(r, 32 == layout.size(s3));
REPORTER_ASSERT(r, 16 == layout.alignment(s3));
// struct 2
std::vector<SkSL::Type::Field> fields2;
fields2.emplace_back(SkSL::Modifiers(), SkSL::String("a"), context.fInt_Type.get());
SkSL::Type s4(SkSL::Position(), SkSL::String("s4"), fields2);
REPORTER_ASSERT(r, 4 == layout.size(s4));
REPORTER_ASSERT(r, 4 == layout.alignment(s4));
fields2.emplace_back(SkSL::Modifiers(), SkSL::String("b"), context.fFloat3_Type.get());
SkSL::Type s5(SkSL::Position(), SkSL::String("s5"), fields2);
REPORTER_ASSERT(r, 32 == layout.size(s5));
REPORTER_ASSERT(r, 16 == layout.alignment(s5));
// arrays
SkSL::Type array1(SkSL::String("float[4]"), SkSL::Type::kArray_Kind, *context.fFloat_Type, 4);
REPORTER_ASSERT(r, 16 == layout.size(array1));
REPORTER_ASSERT(r, 4 == layout.alignment(array1));
REPORTER_ASSERT(r, 4 == layout.stride(array1));
SkSL::Type array2(SkSL::String("float4[4]"), SkSL::Type::kArray_Kind, *context.fFloat4_Type, 4);
REPORTER_ASSERT(r, 64 == layout.size(array2));
REPORTER_ASSERT(r, 16 == layout.alignment(array2));
REPORTER_ASSERT(r, 16 == layout.stride(array2));
}
#endif
|