Debian Codegraph @

src/core/SkSLTypeShared.cpp

raw
1 /*
2 * Copyright 2022 Google LLC
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 "src/core/SkSLTypeShared.h"
9
10 const char* SkSLTypeString(SkSLType t) {
11 switch (t) {
12 case SkSLType::kVoid: return "void";
13 case SkSLType::kBool: return "bool";
14 case SkSLType::kBool2: return "bool2";
15 case SkSLType::kBool3: return "bool3";
16 case SkSLType::kBool4: return "bool4";
17 case SkSLType::kShort: return "short";
18 case SkSLType::kShort2: return "short2";
19 case SkSLType::kShort3: return "short3";
20 case SkSLType::kShort4: return "short4";
21 case SkSLType::kUShort: return "ushort";
22 case SkSLType::kUShort2: return "ushort2";
23 case SkSLType::kUShort3: return "ushort3";
24 case SkSLType::kUShort4: return "ushort4";
25 case SkSLType::kFloat: return "float";
26 case SkSLType::kFloat2: return "float2";
27 case SkSLType::kFloat3: return "float3";
28 case SkSLType::kFloat4: return "float4";
29 case SkSLType::kFloat2x2: return "float2x2";
30 case SkSLType::kFloat3x3: return "float3x3";
31 case SkSLType::kFloat4x4: return "float4x4";
32 case SkSLType::kHalf: return "half";
33 case SkSLType::kHalf2: return "half2";
34 case SkSLType::kHalf3: return "half3";
35 case SkSLType::kHalf4: return "half4";
36 case SkSLType::kHalf2x2: return "half2x2";
37 case SkSLType::kHalf3x3: return "half3x3";
38 case SkSLType::kHalf4x4: return "half4x4";
39 case SkSLType::kInt: return "int";
40 case SkSLType::kInt2: return "int2";
41 case SkSLType::kInt3: return "int3";
42 case SkSLType::kInt4: return "int4";
43 case SkSLType::kUInt: return "uint";
44 case SkSLType::kUInt2: return "uint2";
45 case SkSLType::kUInt3: return "uint3";
46 case SkSLType::kUInt4: return "uint4";
47 case SkSLType::kTexture2DSampler: return "sampler2D";
48 case SkSLType::kTextureExternalSampler: return "samplerExternalOES";
49 case SkSLType::kTexture2DRectSampler: return "sampler2DRect";
50 case SkSLType::kTexture2D: return "texture2D";
51 case SkSLType::kSampler: return "sampler";
52 case SkSLType::kInput: return "subpassInput";
53 }
54 SkUNREACHABLE;
55 }
56
57 /** Is the shading language type full precision? */
58 bool SkSLTypeIsFullPrecisionNumericType(SkSLType type) {
59 switch (type) {
60 // Half-precision types:
61 case SkSLType::kShort:
62 case SkSLType::kShort2:
63 case SkSLType::kShort3:
64 case SkSLType::kShort4:
65 case SkSLType::kUShort:
66 case SkSLType::kUShort2:
67 case SkSLType::kUShort3:
68 case SkSLType::kUShort4:
69 case SkSLType::kHalf:
70 case SkSLType::kHalf2:
71 case SkSLType::kHalf3:
72 case SkSLType::kHalf4:
73 case SkSLType::kHalf2x2:
74 case SkSLType::kHalf3x3:
75 case SkSLType::kHalf4x4:
76 // Non-numeric types:
77 case SkSLType::kVoid:
78 case SkSLType::kTexture2DSampler:
79 case SkSLType::kTextureExternalSampler:
80 case SkSLType::kTexture2DRectSampler:
81 case SkSLType::kTexture2D:
82 case SkSLType::kSampler:
83 case SkSLType::kInput:
84 case SkSLType::kBool:
85 case SkSLType::kBool2:
86 case SkSLType::kBool3:
87 case SkSLType::kBool4:
88 return false;
89
90 // Full-precision numeric types:
91 case SkSLType::kInt:
92 case SkSLType::kInt2:
93 case SkSLType::kInt3:
94 case SkSLType::kInt4:
95 case SkSLType::kUInt:
96 case SkSLType::kUInt2:
97 case SkSLType::kUInt3:
98 case SkSLType::kUInt4:
99 case SkSLType::kFloat:
100 case SkSLType::kFloat2:
101 case SkSLType::kFloat3:
102 case SkSLType::kFloat4:
103 case SkSLType::kFloat2x2:
104 case SkSLType::kFloat3x3:
105 case SkSLType::kFloat4x4:
106 return true;
107 }
108 SkUNREACHABLE;
109 }
110
111 int SkSLTypeMatrixSize(SkSLType type) {
112 switch (type) {
113 case SkSLType::kFloat2x2:
114 case SkSLType::kHalf2x2:
115 return 2;
116
117 case SkSLType::kFloat3x3:
118 case SkSLType::kHalf3x3:
119 return 3;
120
121 case SkSLType::kFloat4x4:
122 case SkSLType::kHalf4x4:
123 return 4;
124
125 case SkSLType::kFloat:
126 case SkSLType::kHalf:
127 case SkSLType::kBool:
128 case SkSLType::kShort:
129 case SkSLType::kUShort:
130 case SkSLType::kInt:
131 case SkSLType::kUInt:
132 case SkSLType::kFloat2:
133 case SkSLType::kHalf2:
134 case SkSLType::kBool2:
135 case SkSLType::kShort2:
136 case SkSLType::kUShort2:
137 case SkSLType::kInt2:
138 case SkSLType::kUInt2:
139 case SkSLType::kFloat3:
140 case SkSLType::kHalf3:
141 case SkSLType::kBool3:
142 case SkSLType::kShort3:
143 case SkSLType::kUShort3:
144 case SkSLType::kInt3:
145 case SkSLType::kUInt3:
146 case SkSLType::kFloat4:
147 case SkSLType::kHalf4:
148 case SkSLType::kBool4:
149 case SkSLType::kShort4:
150 case SkSLType::kUShort4:
151 case SkSLType::kInt4:
152 case SkSLType::kUInt4:
153 case SkSLType::kVoid:
154 case SkSLType::kTexture2DSampler:
155 case SkSLType::kTextureExternalSampler:
156 case SkSLType::kTexture2DRectSampler:
157 case SkSLType::kTexture2D:
158 case SkSLType::kSampler:
159 case SkSLType::kInput:
160 return -1;
161 }
162 SkUNREACHABLE;
163 }
164
165 bool SkSLTypeIsCombinedSamplerType(SkSLType type) {
166 switch (type) {
167 case SkSLType::kTexture2DRectSampler:
168 case SkSLType::kTexture2DSampler:
169 case SkSLType::kTextureExternalSampler:
170 return true;
171
172 case SkSLType::kVoid:
173 case SkSLType::kFloat:
174 case SkSLType::kFloat2:
175 case SkSLType::kFloat3:
176 case SkSLType::kFloat4:
177 case SkSLType::kFloat2x2:
178 case SkSLType::kFloat3x3:
179 case SkSLType::kFloat4x4:
180 case SkSLType::kHalf:
181 case SkSLType::kHalf2:
182 case SkSLType::kHalf3:
183 case SkSLType::kHalf4:
184 case SkSLType::kHalf2x2:
185 case SkSLType::kHalf3x3:
186 case SkSLType::kHalf4x4:
187 case SkSLType::kInt:
188 case SkSLType::kInt2:
189 case SkSLType::kInt3:
190 case SkSLType::kInt4:
191 case SkSLType::kUInt:
192 case SkSLType::kUInt2:
193 case SkSLType::kUInt3:
194 case SkSLType::kUInt4:
195 case SkSLType::kBool:
196 case SkSLType::kBool2:
197 case SkSLType::kBool3:
198 case SkSLType::kBool4:
199 case SkSLType::kShort:
200 case SkSLType::kShort2:
201 case SkSLType::kShort3:
202 case SkSLType::kShort4:
203 case SkSLType::kUShort:
204 case SkSLType::kUShort2:
205 case SkSLType::kUShort3:
206 case SkSLType::kUShort4:
207 case SkSLType::kTexture2D:
208 case SkSLType::kSampler:
209 case SkSLType::kInput:
210 return false;
211 }
212 SkUNREACHABLE;
213 }