Flutter Engine
The Flutter Engine
SkSLBuiltinTypes.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
9
11#include "src/sksl/spirv.h"
12
13namespace SkSL {
14
15/**
16 * Initializes the core SkSL types.
17 */
19 : fFloat(Type::MakeScalarType(
20 "float", "f", Type::NumberKind::kFloat, /*priority=*/10, /*bitWidth=*/32))
21 , fFloat2(Type::MakeVectorType("float2", "f2", *fFloat, /*columns=*/2))
22 , fFloat3(Type::MakeVectorType("float3", "f3", *fFloat, /*columns=*/3))
23 , fFloat4(Type::MakeVectorType("float4", "f4", *fFloat, /*columns=*/4))
24 , fHalf(Type::MakeScalarType(
25 "half", "h", Type::NumberKind::kFloat, /*priority=*/9, /*bitWidth=*/16))
26 , fHalf2(Type::MakeVectorType("half2", "h2", *fHalf, /*columns=*/2))
27 , fHalf3(Type::MakeVectorType("half3", "h3", *fHalf, /*columns=*/3))
28 , fHalf4(Type::MakeVectorType("half4", "h4", *fHalf, /*columns=*/4))
29 , fInt(Type::MakeScalarType(
30 "int", "i", Type::NumberKind::kSigned, /*priority=*/7, /*bitWidth=*/32))
31 , fInt2(Type::MakeVectorType("int2", "i2", *fInt, /*columns=*/2))
32 , fInt3(Type::MakeVectorType("int3", "i3", *fInt, /*columns=*/3))
33 , fInt4(Type::MakeVectorType("int4", "i4", *fInt, /*columns=*/4))
34 , fUInt(Type::MakeScalarType(
35 "uint", "I", Type::NumberKind::kUnsigned, /*priority=*/6, /*bitWidth=*/32))
36 , fUInt2(Type::MakeVectorType("uint2", "I2", *fUInt, /*columns=*/2))
37 , fUInt3(Type::MakeVectorType("uint3", "I3", *fUInt, /*columns=*/3))
38 , fUInt4(Type::MakeVectorType("uint4", "I4", *fUInt, /*columns=*/4))
39 , fShort(Type::MakeScalarType(
40 "short", "s", Type::NumberKind::kSigned, /*priority=*/4, /*bitWidth=*/16))
41 , fShort2(Type::MakeVectorType("short2", "s2", *fShort, /*columns=*/2))
42 , fShort3(Type::MakeVectorType("short3", "s3", *fShort, /*columns=*/3))
43 , fShort4(Type::MakeVectorType("short4", "s4", *fShort, /*columns=*/4))
44 , fUShort(Type::MakeScalarType(
45 "ushort", "S", Type::NumberKind::kUnsigned, /*priority=*/3, /*bitWidth=*/16))
46 , fUShort2(Type::MakeVectorType("ushort2", "S2", *fUShort, /*columns=*/2))
47 , fUShort3(Type::MakeVectorType("ushort3", "S3", *fUShort, /*columns=*/3))
48 , fUShort4(Type::MakeVectorType("ushort4", "S4", *fUShort, /*columns=*/4))
49 , fBool(Type::MakeScalarType(
50 "bool", "b", Type::NumberKind::kBoolean, /*priority=*/0, /*bitWidth=*/1))
51 , fBool2(Type::MakeVectorType("bool2", "b2", *fBool, /*columns=*/2))
52 , fBool3(Type::MakeVectorType("bool3", "b3", *fBool, /*columns=*/3))
53 , fBool4(Type::MakeVectorType("bool4", "b4", *fBool, /*columns=*/4))
54 , fInvalid(Type::MakeSpecialType("<INVALID>", "O", Type::TypeKind::kOther))
55 , fPoison(Type::MakeSpecialType(Compiler::POISON_TAG, "P", Type::TypeKind::kOther))
56 , fVoid(Type::MakeSpecialType("void", "v", Type::TypeKind::kVoid))
57 , fFloatLiteral(Type::MakeLiteralType("$floatLiteral", *fFloat, /*priority=*/8))
58 , fIntLiteral(Type::MakeLiteralType("$intLiteral", *fInt, /*priority=*/5))
59 , fFloat2x2(Type::MakeMatrixType("float2x2", "f22", *fFloat, /*columns=*/2, /*rows=*/2))
60 , fFloat2x3(Type::MakeMatrixType("float2x3", "f23", *fFloat, /*columns=*/2, /*rows=*/3))
61 , fFloat2x4(Type::MakeMatrixType("float2x4", "f24", *fFloat, /*columns=*/2, /*rows=*/4))
62 , fFloat3x2(Type::MakeMatrixType("float3x2", "f32", *fFloat, /*columns=*/3, /*rows=*/2))
63 , fFloat3x3(Type::MakeMatrixType("float3x3", "f33", *fFloat, /*columns=*/3, /*rows=*/3))
64 , fFloat3x4(Type::MakeMatrixType("float3x4", "f34", *fFloat, /*columns=*/3, /*rows=*/4))
65 , fFloat4x2(Type::MakeMatrixType("float4x2", "f42", *fFloat, /*columns=*/4, /*rows=*/2))
66 , fFloat4x3(Type::MakeMatrixType("float4x3", "f43", *fFloat, /*columns=*/4, /*rows=*/3))
67 , fFloat4x4(Type::MakeMatrixType("float4x4", "f44", *fFloat, /*columns=*/4, /*rows=*/4))
68 , fHalf2x2(Type::MakeMatrixType("half2x2", "h22", *fHalf, /*columns=*/2, /*rows=*/2))
69 , fHalf2x3(Type::MakeMatrixType("half2x3", "h23", *fHalf, /*columns=*/2, /*rows=*/3))
70 , fHalf2x4(Type::MakeMatrixType("half2x4", "h24", *fHalf, /*columns=*/2, /*rows=*/4))
71 , fHalf3x2(Type::MakeMatrixType("half3x2", "h32", *fHalf, /*columns=*/3, /*rows=*/2))
72 , fHalf3x3(Type::MakeMatrixType("half3x3", "h33", *fHalf, /*columns=*/3, /*rows=*/3))
73 , fHalf3x4(Type::MakeMatrixType("half3x4", "h34", *fHalf, /*columns=*/3, /*rows=*/4))
74 , fHalf4x2(Type::MakeMatrixType("half4x2", "h42", *fHalf, /*columns=*/4, /*rows=*/2))
75 , fHalf4x3(Type::MakeMatrixType("half4x3", "h43", *fHalf, /*columns=*/4, /*rows=*/3))
76 , fHalf4x4(Type::MakeMatrixType("half4x4", "h44", *fHalf, /*columns=*/4, /*rows=*/4))
77 , fVec2(Type::MakeAliasType("vec2", *fFloat2))
78 , fVec3(Type::MakeAliasType("vec3", *fFloat3))
79 , fVec4(Type::MakeAliasType("vec4", *fFloat4))
80 , fIVec2(Type::MakeAliasType("ivec2", *fInt2))
81 , fIVec3(Type::MakeAliasType("ivec3", *fInt3))
82 , fIVec4(Type::MakeAliasType("ivec4", *fInt4))
83 , fUVec2(Type::MakeAliasType("uvec2", *fUInt2))
84 , fUVec3(Type::MakeAliasType("uvec3", *fUInt3))
85 , fUVec4(Type::MakeAliasType("uvec4", *fUInt4))
86 , fBVec2(Type::MakeAliasType("bvec2", *fBool2))
87 , fBVec3(Type::MakeAliasType("bvec3", *fBool3))
88 , fBVec4(Type::MakeAliasType("bvec4", *fBool4))
89 , fMat2(Type::MakeAliasType("mat2", *fFloat2x2))
90 , fMat3(Type::MakeAliasType("mat3", *fFloat3x3))
91 , fMat4(Type::MakeAliasType("mat4", *fFloat4x4))
92 , fMat2x2(Type::MakeAliasType("mat2x2", *fFloat2x2))
93 , fMat2x3(Type::MakeAliasType("mat2x3", *fFloat2x3))
94 , fMat2x4(Type::MakeAliasType("mat2x4", *fFloat2x4))
95 , fMat3x2(Type::MakeAliasType("mat3x2", *fFloat3x2))
96 , fMat3x3(Type::MakeAliasType("mat3x3", *fFloat3x3))
97 , fMat3x4(Type::MakeAliasType("mat3x4", *fFloat3x4))
98 , fMat4x2(Type::MakeAliasType("mat4x2", *fFloat4x2))
99 , fMat4x3(Type::MakeAliasType("mat4x3", *fFloat4x3))
100 , fMat4x4(Type::MakeAliasType("mat4x4", *fFloat4x4))
101 , fTexture2D_sample(Type::MakeTextureType("$texture2D_sample",
102 SpvDim2D,
103 /*isDepth=*/false,
104 /*isArrayedTexture=*/false,
105 /*isMultisampled=*/false,
106 Type::TextureAccess::kSample))
107 , fTextureExternalOES(Type::MakeTextureType("textureExternalOES",
108 SpvDim2D,
109 /*isDepth=*/false,
110 /*isArrayedTexture=*/false,
111 /*isMultisampled=*/false,
112 Type::TextureAccess::kSample))
113 , fTexture2DRect(Type::MakeTextureType("texture2DRect",
115 /*isDepth=*/false,
116 /*isArrayedTexture=*/false,
117 /*isMultisampled=*/false,
118 Type::TextureAccess::kSample))
119 , fTexture2D(Type::MakeTextureType("texture2D",
120 SpvDim2D,
121 /*isDepth=*/false,
122 /*isArrayedTexture=*/false,
123 /*isMultisampled=*/false,
124 Type::TextureAccess::kReadWrite))
125 , fReadOnlyTexture2D(Type::MakeTextureType("readonlyTexture2D",
126 SpvDim2D,
127 /*isDepth=*/false,
128 /*isArrayedTexture=*/false,
129 /*isMultisampled=*/false,
130 Type::TextureAccess::kRead))
131 , fWriteOnlyTexture2D(Type::MakeTextureType("writeonlyTexture2D",
132 SpvDim2D,
133 /*isDepth=*/false,
134 /*isArrayedTexture=*/false,
135 /*isMultisampled=*/false,
136 Type::TextureAccess::kWrite))
137 , fGenTexture2D(Type::MakeGenericType("$genTexture2D",
138 {fReadOnlyTexture2D.get(),
140 fTexture2D.get()},
141 fTexture2D.get()))
142 , fReadableTexture2D(Type::MakeGenericType("$readableTexture2D",
143 {fReadOnlyTexture2D.get(),
144 fInvalid.get(),
145 fTexture2D.get()},
146 fTexture2D.get()))
147 , fWritableTexture2D(Type::MakeGenericType("$writableTexture2D",
148 {fInvalid.get(),
149 fWriteOnlyTexture2D.get(),
150 fTexture2D.get()},
151 fTexture2D.get()))
152 , fSampler2D(Type::MakeSamplerType("sampler2D", *fTexture2D_sample))
153 , fSamplerExternalOES(Type::MakeSamplerType("samplerExternalOES", *fTextureExternalOES))
154 , fSampler2DRect(Type::MakeSamplerType("sampler2DRect", *fTexture2DRect))
155
156 , fSampler(Type::MakeSpecialType("sampler", "ss", Type::TypeKind::kSeparateSampler))
157
158 , fSubpassInput(Type::MakeTextureType("subpassInput",
160 /*isDepth=*/false,
161 /*isArrayedTexture=*/false,
162 /*isMultisampled=*/false,
164 , fSubpassInputMS(Type::MakeTextureType("subpassInputMS",
166 /*isDepth=*/false,
167 /*isArrayedTexture=*/false,
168 /*isMultisampled=*/true,
170 , fGenType(Type::MakeGenericType("$genType", {fFloat.get(), fFloat2.get(), fFloat3.get(),
171 fFloat4.get()}, fFloat.get()))
172 , fGenHType(Type::MakeGenericType("$genHType", {fHalf.get(), fHalf2.get(), fHalf3.get(),
173 fHalf4.get()}, fHalf.get()))
174 , fGenIType(Type::MakeGenericType("$genIType", {fInt.get(), fInt2.get(), fInt3.get(),
175 fInt4.get()}, fInt.get()))
176 , fGenUType(Type::MakeGenericType("$genUType", {fUInt.get(), fUInt2.get(), fUInt3.get(),
177 fUInt4.get()}, fUInt.get()))
178 , fGenBType(Type::MakeGenericType("$genBType", {fBool.get(), fBool2.get(), fBool3.get(),
179 fBool4.get()}, fBool.get()))
180 , fMat(Type::MakeGenericType("$mat", {fFloat2x2.get(), fFloat2x3.get(), fFloat2x4.get(),
181 fFloat3x2.get(), fFloat3x3.get(), fFloat3x4.get(),
182 fFloat4x2.get(), fFloat4x3.get(), fFloat4x4.get()},
183 fFloat.get()))
184 , fHMat(Type::MakeGenericType("$hmat", {fHalf2x2.get(), fHalf2x3.get(), fHalf2x4.get(),
185 fHalf3x2.get(), fHalf3x3.get(), fHalf3x4.get(),
186 fHalf4x2.get(), fHalf4x3.get(), fHalf4x4.get()},
187 fHalf.get()))
188 , fSquareMat(Type::MakeGenericType("$squareMat", {fInvalid.get(), fFloat2x2.get(),
189 fFloat3x3.get(), fFloat4x4.get()},
190 fFloat.get()))
191 , fSquareHMat(Type::MakeGenericType("$squareHMat", {fInvalid.get(), fHalf2x2.get(),
192 fHalf3x3.get(), fHalf4x4.get()},
193 fHalf.get()))
194 , fVec(Type::MakeGenericType("$vec", {fInvalid.get(), fFloat2.get(), fFloat3.get(),
195 fFloat4.get()}, fFloat.get()))
196 , fHVec(Type::MakeGenericType("$hvec", {fInvalid.get(), fHalf2.get(), fHalf3.get(),
197 fHalf4.get()}, fHalf.get()))
198 , fIVec(Type::MakeGenericType("$ivec", {fInvalid.get(), fInt2.get(), fInt3.get(),
199 fInt4.get()}, fInt.get()))
200 , fUVec(Type::MakeGenericType("$uvec", {fInvalid.get(), fUInt2.get(), fUInt3.get(),
201 fUInt4.get()}, fUInt.get()))
202 , fSVec(Type::MakeGenericType("$svec", {fInvalid.get(), fShort2.get(), fShort3.get(),
203 fShort4.get()}, fShort.get()))
204 , fUSVec(Type::MakeGenericType("$usvec", {fInvalid.get(), fUShort2.get(), fUShort3.get(),
205 fUShort4.get()}, fUShort.get()))
206 , fBVec(Type::MakeGenericType("$bvec", {fInvalid.get(), fBool2.get(), fBool3.get(),
207 fBool4.get()}, fBool.get()))
208 , fSkCaps(Type::MakeSpecialType("$sk_Caps", "O", Type::TypeKind::kOther))
209 , fColorFilter(Type::MakeSpecialType("colorFilter", "CF", Type::TypeKind::kColorFilter))
210 , fShader(Type::MakeSpecialType("shader", "SH", Type::TypeKind::kShader))
211 , fBlender(Type::MakeSpecialType("blender", "B", Type::TypeKind::kBlender))
212 , fAtomicUInt(Type::MakeAtomicType("atomicUint", "au")) {}
213
214} // namespace SkSL
const std::unique_ptr< Type > fTexture2D
const std::unique_ptr< Type > fWriteOnlyTexture2D
const std::unique_ptr< Type > fReadOnlyTexture2D
static std::unique_ptr< Type > MakeTextureType(const char *name, SpvDim_ dimensions, bool isDepth, bool isArrayedTexture, bool isMultisampled, TextureAccess textureAccess)
static std::unique_ptr< Type > MakeSpecialType(const char *name, const char *abbrev, Type::TypeKind typeKind)
static std::unique_ptr< Type > MakeGenericType(const char *name, SkSpan< const Type *const > types, const Type *slotType)
static std::unique_ptr< Type > MakeAtomicType(std::string_view name, const char *abbrev)
static std::unique_ptr< Type > MakeSamplerType(const char *name, const Type &textureType)
@ SpvDim2D
Definition: spirv.h:143
@ SpvDimSubpassData
Definition: spirv.h:148
@ SpvDimRect
Definition: spirv.h:146