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

Side by Side Diff: src/sksl/ir/SkSLType.cpp

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fixed CMake build Created 4 years, 5 months 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 unified diff | Download patch
« no previous file with comments | « src/sksl/ir/SkSLType.h ('k') | src/sksl/ir/SkSLTypeReference.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "SkSLType.h"
9
10 namespace SkSL {
11
12 bool Type::determineCoercionCost(std::shared_ptr<Type> other, int* outCost) cons t {
13 if (this == other.get()) {
14 *outCost = 0;
15 return true;
16 }
17 if (this->kind() == kVector_Kind && other->kind() == kVector_Kind) {
18 if (this->columns() == other->columns()) {
19 return this->componentType()->determineCoercionCost(other->component Type(), outCost);
20 }
21 return false;
22 }
23 if (this->kind() == kMatrix_Kind) {
24 if (this->columns() == other->columns() &&
25 this->rows() == other->rows()) {
26 return this->componentType()->determineCoercionCost(other->component Type(), outCost);
27 }
28 return false;
29 }
30 for (size_t i = 0; i < fCoercibleTypes.size(); i++) {
31 if (fCoercibleTypes[i] == other) {
32 *outCost = (int) i + 1;
33 return true;
34 }
35 }
36 return false;
37 }
38
39 std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
40 ASSERT(this->kind() == Type::kScalar_Kind);
41 if (columns == 1 && rows == 1) {
42 return std::shared_ptr<Type>(this);
43 }
44 if (*this == *kFloat_Type) {
45 switch (rows) {
46 case 1:
47 switch (columns) {
48 case 2: return kVec2_Type;
49 case 3: return kVec3_Type;
50 case 4: return kVec4_Type;
51 default: ABORT("unsupported vector column count (%d)", colum ns);
52 }
53 case 2:
54 switch (columns) {
55 case 2: return kMat2x2_Type;
56 case 3: return kMat3x2_Type;
57 case 4: return kMat4x2_Type;
58 default: ABORT("unsupported matrix column count (%d)", colum ns);
59 }
60 case 3:
61 switch (columns) {
62 case 2: return kMat2x3_Type;
63 case 3: return kMat3x3_Type;
64 case 4: return kMat4x3_Type;
65 default: ABORT("unsupported matrix column count (%d)", colum ns);
66 }
67 case 4:
68 switch (columns) {
69 case 2: return kMat2x4_Type;
70 case 3: return kMat3x4_Type;
71 case 4: return kMat4x4_Type;
72 default: ABORT("unsupported matrix column count (%d)", colum ns);
73 }
74 default: ABORT("unsupported row count (%d)", rows);
75 }
76 } else if (*this == *kDouble_Type) {
77 switch (rows) {
78 case 1:
79 switch (columns) {
80 case 2: return kDVec2_Type;
81 case 3: return kDVec3_Type;
82 case 4: return kDVec4_Type;
83 default: ABORT("unsupported vector column count (%d)", colum ns);
84 }
85 case 2:
86 switch (columns) {
87 case 2: return kDMat2x2_Type;
88 case 3: return kDMat3x2_Type;
89 case 4: return kDMat4x2_Type;
90 default: ABORT("unsupported matrix column count (%d)", colum ns);
91 }
92 case 3:
93 switch (columns) {
94 case 2: return kDMat2x3_Type;
95 case 3: return kDMat3x3_Type;
96 case 4: return kDMat4x3_Type;
97 default: ABORT("unsupported matrix column count (%d)", colum ns);
98 }
99 case 4:
100 switch (columns) {
101 case 2: return kDMat2x4_Type;
102 case 3: return kDMat3x4_Type;
103 case 4: return kDMat4x4_Type;
104 default: ABORT("unsupported matrix column count (%d)", colum ns);
105 }
106 default: ABORT("unsupported row count (%d)", rows);
107 }
108 } else if (*this == *kInt_Type) {
109 switch (rows) {
110 case 1:
111 switch (columns) {
112 case 2: return kIVec2_Type;
113 case 3: return kIVec3_Type;
114 case 4: return kIVec4_Type;
115 default: ABORT("unsupported vector column count (%d)", colum ns);
116 }
117 default: ABORT("unsupported row count (%d)", rows);
118 }
119 } else if (*this == *kUInt_Type) {
120 switch (rows) {
121 case 1:
122 switch (columns) {
123 case 2: return kUVec2_Type;
124 case 3: return kUVec3_Type;
125 case 4: return kUVec4_Type;
126 default: ABORT("unsupported vector column count (%d)", colum ns);
127 }
128 default: ABORT("unsupported row count (%d)", rows);
129 }
130 }
131 ABORT("unsupported scalar_to_compound type %s", this->description().c_str()) ;
132 }
133
134 const std::shared_ptr<Type> kVoid_Type(new Type("void"));
135
136 const std::shared_ptr<Type> kDouble_Type(new Type("double", true));
137 const std::shared_ptr<Type> kDVec2_Type(new Type("dvec2", kDouble_Type, 2));
138 const std::shared_ptr<Type> kDVec3_Type(new Type("dvec3", kDouble_Type, 3));
139 const std::shared_ptr<Type> kDVec4_Type(new Type("dvec4", kDouble_Type, 4));
140
141 const std::shared_ptr<Type> kFloat_Type(new Type("float", true, { kDouble_Type } ));
142 const std::shared_ptr<Type> kVec2_Type(new Type("vec2", kFloat_Type, 2));
143 const std::shared_ptr<Type> kVec3_Type(new Type("vec3", kFloat_Type, 3));
144 const std::shared_ptr<Type> kVec4_Type(new Type("vec4", kFloat_Type, 4));
145
146 const std::shared_ptr<Type> kUInt_Type(new Type("uint", true, { kFloat_Type, kDo uble_Type }));
147 const std::shared_ptr<Type> kUVec2_Type(new Type("uvec2", kUInt_Type, 2));
148 const std::shared_ptr<Type> kUVec3_Type(new Type("uvec3", kUInt_Type, 3));
149 const std::shared_ptr<Type> kUVec4_Type(new Type("uvec4", kUInt_Type, 4));
150
151 const std::shared_ptr<Type> kInt_Type(new Type("int", true, { kUInt_Type, kFloat _Type,
152 kDouble_Type }));
153 const std::shared_ptr<Type> kIVec2_Type(new Type("ivec2", kInt_Type, 2));
154 const std::shared_ptr<Type> kIVec3_Type(new Type("ivec3", kInt_Type, 3));
155 const std::shared_ptr<Type> kIVec4_Type(new Type("ivec4", kInt_Type, 4));
156
157 const std::shared_ptr<Type> kBool_Type(new Type("bool", false));
158 const std::shared_ptr<Type> kBVec2_Type(new Type("bvec2", kBool_Type, 2));
159 const std::shared_ptr<Type> kBVec3_Type(new Type("bvec3", kBool_Type, 3));
160 const std::shared_ptr<Type> kBVec4_Type(new Type("bvec4", kBool_Type, 4));
161
162 const std::shared_ptr<Type> kMat2x2_Type(new Type("mat2", kFloat_Type, 2, 2));
163 const std::shared_ptr<Type> kMat2x3_Type(new Type("mat2x3", kFloat_Type, 2, 3));
164 const std::shared_ptr<Type> kMat2x4_Type(new Type("mat2x4", kFloat_Type, 2, 4));
165 const std::shared_ptr<Type> kMat3x2_Type(new Type("mat3x2", kFloat_Type, 3, 2));
166 const std::shared_ptr<Type> kMat3x3_Type(new Type("mat3", kFloat_Type, 3, 3));
167 const std::shared_ptr<Type> kMat3x4_Type(new Type("mat3x4", kFloat_Type, 3, 4));
168 const std::shared_ptr<Type> kMat4x2_Type(new Type("mat4x2", kFloat_Type, 4, 2));
169 const std::shared_ptr<Type> kMat4x3_Type(new Type("mat4x3", kFloat_Type, 4, 3));
170 const std::shared_ptr<Type> kMat4x4_Type(new Type("mat4", kFloat_Type, 4, 4));
171
172 const std::shared_ptr<Type> kDMat2x2_Type(new Type("dmat2", kFloat_Type, 2, 2) );
173 const std::shared_ptr<Type> kDMat2x3_Type(new Type("dmat2x3", kFloat_Type, 2, 3) );
174 const std::shared_ptr<Type> kDMat2x4_Type(new Type("dmat2x4", kFloat_Type, 2, 4) );
175 const std::shared_ptr<Type> kDMat3x2_Type(new Type("dmat3x2", kFloat_Type, 3, 2) );
176 const std::shared_ptr<Type> kDMat3x3_Type(new Type("dmat3", kFloat_Type, 3, 3) );
177 const std::shared_ptr<Type> kDMat3x4_Type(new Type("dmat3x4", kFloat_Type, 3, 4) );
178 const std::shared_ptr<Type> kDMat4x2_Type(new Type("dmat4x2", kFloat_Type, 4, 2) );
179 const std::shared_ptr<Type> kDMat4x3_Type(new Type("dmat4x3", kFloat_Type, 4, 3) );
180 const std::shared_ptr<Type> kDMat4x4_Type(new Type("dmat4", kFloat_Type, 4, 4) );
181
182 const std::shared_ptr<Type> kSampler1D_Type(new Type("sampler1D", SpvDim1D, fals e, false, false, true));
183 const std::shared_ptr<Type> kSampler2D_Type(new Type("sampler2D", SpvDim2D, fals e, false, false, true));
184 const std::shared_ptr<Type> kSampler3D_Type(new Type("sampler3D", SpvDim3D, fals e, false, false, true));
185 const std::shared_ptr<Type> kSamplerCube_Type(new Type("samplerCube"));
186 const std::shared_ptr<Type> kSampler2DRect_Type(new Type("sampler2DRect"));
187 const std::shared_ptr<Type> kSampler1DArray_Type(new Type("sampler1DArray"));
188 const std::shared_ptr<Type> kSampler2DArray_Type(new Type("sampler2DArray"));
189 const std::shared_ptr<Type> kSamplerCubeArray_Type(new Type("samplerCubeArray")) ;
190 const std::shared_ptr<Type> kSamplerBuffer_Type(new Type("samplerBuffer"));
191 const std::shared_ptr<Type> kSampler2DMS_Type(new Type("sampler2DMS"));
192 const std::shared_ptr<Type> kSampler2DMSArray_Type(new Type("sampler2DMSArray")) ;
193 const std::shared_ptr<Type> kSampler1DShadow_Type(new Type("sampler1DShadow"));
194 const std::shared_ptr<Type> kSampler2DShadow_Type(new Type("sampler2DShadow"));
195 const std::shared_ptr<Type> kSamplerCubeShadow_Type(new Type("samplerCubeShadow" ));
196 const std::shared_ptr<Type> kSampler2DRectShadow_Type(new Type("sampler2DRectSha dow"));
197 const std::shared_ptr<Type> kSampler1DArrayShadow_Type(new Type("sampler1DArrayS hadow"));
198 const std::shared_ptr<Type> kSampler2DArrayShadow_Type(new Type("sampler2DArrayS hadow"));
199 const std::shared_ptr<Type> kSamplerCubeArrayShadow_Type(new Type("samplerCubeAr rayShadow"));
200
201 static std::vector<std::shared_ptr<Type>> type(std::shared_ptr<Type> t) {
202 return { t, t, t, t };
203 }
204
205 // FIXME figure out what we're supposed to do with the gsampler et al. types
206 const std::shared_ptr<Type> kGSampler1D_Type(new Type("$gsampler1D", type(kSampl er1D_Type)));
207 const std::shared_ptr<Type> kGSampler2D_Type(new Type("$gsampler2D", type(kSampl er2D_Type)));
208 const std::shared_ptr<Type> kGSampler3D_Type(new Type("$gsampler3D", type(kSampl er3D_Type)));
209 const std::shared_ptr<Type> kGSamplerCube_Type(new Type("$gsamplerCube", type(kS amplerCube_Type)));
210 const std::shared_ptr<Type> kGSampler2DRect_Type(new Type("$gsampler2DRect",
211 type(kSampler2DRect_Type)));
212 const std::shared_ptr<Type> kGSampler1DArray_Type(new Type("$gsampler1DArray",
213 type(kSampler1DArray_Type)));
214 const std::shared_ptr<Type> kGSampler2DArray_Type(new Type("$gsampler2DArray",
215 type(kSampler2DArray_Type)));
216 const std::shared_ptr<Type> kGSamplerCubeArray_Type(new Type("$gsamplerCubeArray ",
217 type(kSamplerCubeArray_Type) ));
218 const std::shared_ptr<Type> kGSamplerBuffer_Type(new Type("$gsamplerBuffer",
219 type(kSamplerBuffer_Type)));
220 const std::shared_ptr<Type> kGSampler2DMS_Type(new Type("$gsampler2DMS",
221 type(kSampler2DMS_Type)));
222 const std::shared_ptr<Type> kGSampler2DMSArray_Type(new Type("$gsampler2DMSArray ",
223 type(kSampler2DMSArray_Type) ));
224 const std::shared_ptr<Type> kGSampler2DArrayShadow_Type(new Type("$gsampler2DArr ayShadow",
225 type(kSampler2DArrayShad ow_Type)));
226 const std::shared_ptr<Type> kGSamplerCubeArrayShadow_Type(new Type("$gsamplerCub eArrayShadow",
227 type(kSamplerCubeArray Shadow_Type)));
228
229 const std::shared_ptr<Type> kGenType_Type(new Type("$genType", { kFloat_Type, kV ec2_Type,
230 kVec3_Type, kVe c4_Type }));
231 const std::shared_ptr<Type> kGenDType_Type(new Type("$genDType", { kDouble_Type, kDVec2_Type,
232 kDVec3_Type, kDVec4_Type }));
233 const std::shared_ptr<Type> kGenIType_Type(new Type("$genIType", { kInt_Type, kI Vec2_Type,
234 kIVec3_Type, kIVec4_Type }));
235 const std::shared_ptr<Type> kGenUType_Type(new Type("$genUType", { kUInt_Type, k UVec2_Type,
236 kUVec3_Type, kUVec4_Type }));
237 const std::shared_ptr<Type> kGenBType_Type(new Type("$genBType", { kBool_Type, k BVec2_Type,
238 kBVec3_Type, kBVec4_Type }));
239
240 const std::shared_ptr<Type> kMat_Type(new Type("$mat"));
241
242 const std::shared_ptr<Type> kVec_Type(new Type("$vec", { kVec2_Type, kVec2_Type, kVec3_Type,
243 kVec4_Type }));
244
245 const std::shared_ptr<Type> kGVec_Type(new Type("$gvec"));
246 const std::shared_ptr<Type> kGVec2_Type(new Type("$gvec2"));
247 const std::shared_ptr<Type> kGVec3_Type(new Type("$gvec3"));
248 const std::shared_ptr<Type> kGVec4_Type(new Type("$gvec4", type(kVec4_Type)));
249 const std::shared_ptr<Type> kDVec_Type(new Type("$dvec"));
250 const std::shared_ptr<Type> kIVec_Type(new Type("$ivec"));
251 const std::shared_ptr<Type> kUVec_Type(new Type("$uvec"));
252
253 const std::shared_ptr<Type> kBVec_Type(new Type("$bvec", { kBVec2_Type, kBVec2_T ype,
254 kBVec3_Type, kBVec4_T ype }));
255
256 const std::shared_ptr<Type> kInvalid_Type(new Type("<INVALID>"));
257
258 } // namespace
OLDNEW
« no previous file with comments | « src/sksl/ir/SkSLType.h ('k') | src/sksl/ir/SkSLTypeReference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698