OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SKIASL_TYPE | 8 #ifndef SKIASL_TYPE |
9 #define SKIASL_TYPE | 9 #define SKIASL_TYPE |
10 | 10 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 bool isMultisampled() const { | 231 bool isMultisampled() const { |
232 ASSERT(fTypeKind == kSampler_Kind); | 232 ASSERT(fTypeKind == kSampler_Kind); |
233 return fIsMultisampled; | 233 return fIsMultisampled; |
234 } | 234 } |
235 | 235 |
236 bool isSampled() const { | 236 bool isSampled() const { |
237 ASSERT(fTypeKind == kSampler_Kind); | 237 ASSERT(fTypeKind == kSampler_Kind); |
238 return fIsSampled; | 238 return fIsSampled; |
239 } | 239 } |
240 | 240 |
241 static size_t vector_alignment(size_t componentSize, int columns) { | |
242 return componentSize * (columns + columns % 2); | |
243 } | |
244 | |
245 /** | |
246 * Returns the type's required alignment (when putting this type into a stru
ct, the offset must | |
247 * be a multiple of the alignment). | |
248 */ | |
249 size_t alignment() const { | |
250 // See OpenGL Spec 7.6.2.2 Standard Uniform Block Layout | |
251 switch (fTypeKind) { | |
252 case kScalar_Kind: | |
253 return this->size(); | |
254 case kVector_Kind: | |
255 return vector_alignment(fComponentType->size(), fColumns); | |
256 case kMatrix_Kind: | |
257 return (vector_alignment(fComponentType->size(), fRows) + 15) &
~15; | |
258 case kArray_Kind: | |
259 // round up to next multiple of 16 | |
260 return (fComponentType->alignment() + 15) & ~15; | |
261 case kStruct_Kind: { | |
262 size_t result = 16; | |
263 for (size_t i = 0; i < fFields.size(); i++) { | |
264 size_t alignment = fFields[i].fType->alignment(); | |
265 if (alignment > result) { | |
266 result = alignment; | |
267 } | |
268 } | |
269 } | |
270 default: | |
271 ABORT(("cannot determine size of type " + fName).c_str()); | |
272 } | |
273 } | |
274 | |
275 /** | |
276 * For matrices and arrays, returns the number of bytes from the start of on
e entry (row, in | |
277 * the case of matrices) to the start of the next. | |
278 */ | |
279 size_t stride() const { | |
280 switch (fTypeKind) { | |
281 case kMatrix_Kind: // fall through | |
282 case kArray_Kind: | |
283 return this->alignment(); | |
284 default: | |
285 ABORT("type does not have a stride"); | |
286 } | |
287 } | |
288 | |
289 /** | |
290 * Returns the size of this type in bytes. | |
291 */ | |
292 size_t size() const { | |
293 switch (fTypeKind) { | |
294 case kScalar_Kind: | |
295 // FIXME need to take precision into account, once we figure out
how we want to | |
296 // handle it... | |
297 return 4; | |
298 case kVector_Kind: | |
299 return fColumns * fComponentType->size(); | |
300 case kMatrix_Kind: | |
301 return vector_alignment(fComponentType->size(), fRows) * fColumn
s; | |
302 case kArray_Kind: | |
303 return fColumns * this->stride(); | |
304 case kStruct_Kind: { | |
305 size_t total = 0; | |
306 for (size_t i = 0; i < fFields.size(); i++) { | |
307 size_t alignment = fFields[i].fType->alignment(); | |
308 if (total % alignment != 0) { | |
309 total += alignment - total % alignment; | |
310 } | |
311 ASSERT(false); | |
312 ASSERT(total % alignment == 0); | |
313 total += fFields[i].fType->size(); | |
314 } | |
315 return total; | |
316 } | |
317 default: | |
318 ABORT(("cannot determine size of type " + fName).c_str()); | |
319 } | |
320 } | |
321 | |
322 /** | 241 /** |
323 * Returns the corresponding vector or matrix type with the specified number
of columns and | 242 * Returns the corresponding vector or matrix type with the specified number
of columns and |
324 * rows. | 243 * rows. |
325 */ | 244 */ |
326 const Type& toCompound(const Context& context, int columns, int rows) const; | 245 const Type& toCompound(const Context& context, int columns, int rows) const; |
327 | 246 |
328 private: | 247 private: |
329 typedef Symbol INHERITED; | 248 typedef Symbol INHERITED; |
330 | 249 |
331 const Kind fTypeKind; | 250 const Kind fTypeKind; |
332 const bool fIsNumber = false; | 251 const bool fIsNumber = false; |
333 const Type* fComponentType = nullptr; | 252 const Type* fComponentType = nullptr; |
334 const std::vector<const Type*> fCoercibleTypes; | 253 const std::vector<const Type*> fCoercibleTypes; |
335 const int fColumns = -1; | 254 const int fColumns = -1; |
336 const int fRows = -1; | 255 const int fRows = -1; |
337 const std::vector<Field> fFields; | 256 const std::vector<Field> fFields; |
338 const SpvDim_ fDimensions = SpvDim1D; | 257 const SpvDim_ fDimensions = SpvDim1D; |
339 const bool fIsDepth = false; | 258 const bool fIsDepth = false; |
340 const bool fIsArrayed = false; | 259 const bool fIsArrayed = false; |
341 const bool fIsMultisampled = false; | 260 const bool fIsMultisampled = false; |
342 const bool fIsSampled = false; | 261 const bool fIsSampled = false; |
343 }; | 262 }; |
344 | 263 |
345 } // namespace | 264 } // namespace |
346 | 265 |
347 #endif | 266 #endif |
OLD | NEW |