Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrSPIRVVaryingHandler.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
9
10/** Returns the number of locations take up by a given SkSLType. We assume that all
11 scalar values are 32 bits. */
13 // If a new GrSL type is added, this function will need to be updated.
14 static_assert(kSkSLTypeCount == 41);
15
16 switch(type) {
17 case SkSLType::kVoid:
18 return 0;
19 case SkSLType::kFloat: // fall through
20 case SkSLType::kHalf:
21 return 1;
22 case SkSLType::kFloat2: // fall through
24 return 1;
27 return 1;
30 return 1;
31 case SkSLType::kInt2:
35 return 1;
36 case SkSLType::kInt3:
40 return 1;
41 case SkSLType::kInt4:
45 return 1;
48 return 2;
51 return 3;
54 return 4;
56 return 0;
58 return 0;
60 return 0;
61 case SkSLType::kBool:
65 return 1;
66 case SkSLType::kInt: // fall through
68 return 1;
69 case SkSLType::kUInt: // fall through
71 return 1;
73 return 0;
75 return 0;
77 return 0;
78 }
79 SK_ABORT("Unexpected type");
80}
81
83 int locationIndex = 0;
84 for (GrShaderVar& var : vars.items()) {
85 SkString location;
86 location.appendf("location = %d", locationIndex);
87 var.addLayoutQualifier(location.c_str());
88
89 int elementSize = sksltype_to_location_size(var.getType());
90 SkASSERT(elementSize > 0);
91 int numElements = var.isArray() ? var.getArrayCount() : 1;
92 SkASSERT(numElements > 0);
93 locationIndex += elementSize * numElements;
94 }
95 // TODO: determine the layout limits for SPIR-V, and enforce them via asserts here.
96}
97
static int sksltype_to_location_size(SkSLType type)
static void finalize_helper(GrSPIRVVaryingHandler::VarArray &vars)
#define SK_ABORT(message,...)
Definition SkAssert.h:70
#define SkASSERT(cond)
Definition SkAssert.h:116
static const int kSkSLTypeCount
SkSLType
@ kTextureExternalSampler
@ kTexture2DSampler
@ kTexture2DRectSampler
const char * c_str() const
Definition SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550