• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/sksl/SkSLBuiltinTypes.h"
9 
10 #include "include/private/SkSLModifiers.h"
11 #include "src/sksl/SkSLCompiler.h"
12 #include "src/sksl/ir/SkSLExpression.h"
13 #include "src/sksl/spirv.h"
14 
15 namespace SkSL {
16 
17 /**
18  * Initializes the core SkSL types.
19  */
BuiltinTypes()20 BuiltinTypes::BuiltinTypes()
21         : fFloat(Type::MakeScalarType(
22                   "float", "f", Type::NumberKind::kFloat, /*priority=*/10, /*bitWidth=*/32))
23         , fFloat2(Type::MakeVectorType("float2", "f2", *fFloat, /*columns=*/2))
24         , fFloat3(Type::MakeVectorType("float3", "f3", *fFloat, /*columns=*/3))
25         , fFloat4(Type::MakeVectorType("float4", "f4", *fFloat, /*columns=*/4))
26         , fHalf(Type::MakeScalarType(
27                   "half", "h", Type::NumberKind::kFloat, /*priority=*/9, /*bitWidth=*/16))
28         , fHalf2(Type::MakeVectorType("half2", "h2", *fHalf, /*columns=*/2))
29         , fHalf3(Type::MakeVectorType("half3", "h3", *fHalf, /*columns=*/3))
30         , fHalf4(Type::MakeVectorType("half4", "h4", *fHalf, /*columns=*/4))
31         , fInt(Type::MakeScalarType(
32                   "int", "i", Type::NumberKind::kSigned, /*priority=*/7, /*bitWidth=*/32))
33         , fInt2(Type::MakeVectorType("int2", "i2", *fInt, /*columns=*/2))
34         , fInt3(Type::MakeVectorType("int3", "i3", *fInt, /*columns=*/3))
35         , fInt4(Type::MakeVectorType("int4", "i4", *fInt, /*columns=*/4))
36         , fUInt(Type::MakeScalarType(
37                   "uint", "I", Type::NumberKind::kUnsigned, /*priority=*/6, /*bitWidth=*/32))
38         , fUInt2(Type::MakeVectorType("uint2", "I2", *fUInt, /*columns=*/2))
39         , fUInt3(Type::MakeVectorType("uint3", "I3", *fUInt, /*columns=*/3))
40         , fUInt4(Type::MakeVectorType("uint4", "I4", *fUInt, /*columns=*/4))
41         , fShort(Type::MakeScalarType(
42                   "short", "s", Type::NumberKind::kSigned, /*priority=*/4, /*bitWidth=*/16))
43         , fShort2(Type::MakeVectorType("short2", "s2", *fShort, /*columns=*/2))
44         , fShort3(Type::MakeVectorType("short3", "s3", *fShort, /*columns=*/3))
45         , fShort4(Type::MakeVectorType("short4", "s4", *fShort, /*columns=*/4))
46         , fUShort(Type::MakeScalarType(
47                   "ushort", "S", Type::NumberKind::kUnsigned, /*priority=*/3, /*bitWidth=*/16))
48         , fUShort2(Type::MakeVectorType("ushort2", "S2", *fUShort, /*columns=*/2))
49         , fUShort3(Type::MakeVectorType("ushort3", "S3", *fUShort, /*columns=*/3))
50         , fUShort4(Type::MakeVectorType("ushort4", "S4", *fUShort, /*columns=*/4))
51         , fBool(Type::MakeScalarType(
52                   "bool", "b", Type::NumberKind::kBoolean, /*priority=*/0, /*bitWidth=*/1))
53         , fBool2(Type::MakeVectorType("bool2", "b2", *fBool, /*columns=*/2))
54         , fBool3(Type::MakeVectorType("bool3", "b3", *fBool, /*columns=*/3))
55         , fBool4(Type::MakeVectorType("bool4", "b4", *fBool, /*columns=*/4))
56         , fInvalid(Type::MakeSpecialType("<INVALID>", "O", Type::TypeKind::kOther))
57         , fPoison(Type::MakeSpecialType(Compiler::POISON_TAG, "P", Type::TypeKind::kOther))
58         , fVoid(Type::MakeSpecialType("void", "v", Type::TypeKind::kVoid))
59         , fFloatLiteral(Type::MakeLiteralType("$floatLiteral", *fFloat, /*priority=*/8))
60         , fIntLiteral(Type::MakeLiteralType("$intLiteral", *fInt, /*priority=*/5))
61         , fFloat2x2(Type::MakeMatrixType("float2x2", "f22", *fFloat, /*columns=*/2, /*rows=*/2))
62         , fFloat2x3(Type::MakeMatrixType("float2x3", "f23", *fFloat, /*columns=*/2, /*rows=*/3))
63         , fFloat2x4(Type::MakeMatrixType("float2x4", "f24", *fFloat, /*columns=*/2, /*rows=*/4))
64         , fFloat3x2(Type::MakeMatrixType("float3x2", "f32", *fFloat, /*columns=*/3, /*rows=*/2))
65         , fFloat3x3(Type::MakeMatrixType("float3x3", "f33", *fFloat, /*columns=*/3, /*rows=*/3))
66         , fFloat3x4(Type::MakeMatrixType("float3x4", "f34", *fFloat, /*columns=*/3, /*rows=*/4))
67         , fFloat4x2(Type::MakeMatrixType("float4x2", "f42", *fFloat, /*columns=*/4, /*rows=*/2))
68         , fFloat4x3(Type::MakeMatrixType("float4x3", "f43", *fFloat, /*columns=*/4, /*rows=*/3))
69         , fFloat4x4(Type::MakeMatrixType("float4x4", "f44", *fFloat, /*columns=*/4, /*rows=*/4))
70         , fHalf2x2(Type::MakeMatrixType("half2x2", "h22", *fHalf, /*columns=*/2, /*rows=*/2))
71         , fHalf2x3(Type::MakeMatrixType("half2x3", "h23", *fHalf, /*columns=*/2, /*rows=*/3))
72         , fHalf2x4(Type::MakeMatrixType("half2x4", "h24", *fHalf, /*columns=*/2, /*rows=*/4))
73         , fHalf3x2(Type::MakeMatrixType("half3x2", "h32", *fHalf, /*columns=*/3, /*rows=*/2))
74         , fHalf3x3(Type::MakeMatrixType("half3x3", "h33", *fHalf, /*columns=*/3, /*rows=*/3))
75         , fHalf3x4(Type::MakeMatrixType("half3x4", "h34", *fHalf, /*columns=*/3, /*rows=*/4))
76         , fHalf4x2(Type::MakeMatrixType("half4x2", "h42", *fHalf, /*columns=*/4, /*rows=*/2))
77         , fHalf4x3(Type::MakeMatrixType("half4x3", "h43", *fHalf, /*columns=*/4, /*rows=*/3))
78         , fHalf4x4(Type::MakeMatrixType("half4x4", "h44", *fHalf, /*columns=*/4, /*rows=*/4))
79         , fTexture1D(Type::MakeTextureType("texture1D",
80                                            SpvDim1D,
81                                            /*isDepth=*/false,
82                                            /*isArrayedTexture=*/false,
83                                            /*isMultisampled=*/false,
84                                            /*isSampled=*/true))
85         , fTexture2D(Type::MakeTextureType("texture2D",
86                                            SpvDim2D,
87                                            /*isDepth=*/false,
88                                            /*isArrayedTexture=*/false,
89                                            /*isMultisampled=*/false,
90                                            /*isSampled=*/true))
91         , fTexture3D(Type::MakeTextureType("texture3D",
92                                            SpvDim3D,
93                                            /*isDepth=*/false,
94                                            /*isArrayedTexture=*/false,
95                                            /*isMultisampled=*/false,
96                                            /*isSampled=*/true))
97         , fTextureExternalOES(Type::MakeTextureType("textureExternalOES",
98                                                     SpvDim2D,
99                                                     /*isDepth=*/false,
100                                                     /*isArrayedTexture=*/false,
101                                                     /*isMultisampled=*/false,
102                                                     /*isSampled=*/true))
103         , fTexture2DRect(Type::MakeTextureType("texture2DRect",
104                                                SpvDimRect,
105                                                /*isDepth=*/false,
106                                                /*isArrayedTexture=*/false,
107                                                /*isMultisampled=*/false,
108                                                /*isSampled=*/true))
109         , fITexture2D(Type::MakeTextureType("itexture2D",
110                                             SpvDim2D,
111                                             /*isDepth=*/false,
112                                             /*isArrayedTexture=*/false,
113                                             /*isMultisampled=*/false,
114                                             /*isSampled=*/true))
115         , fSampler1D(Type::MakeSamplerType("sampler1D", *fTexture1D))
116         , fSampler2D(Type::MakeSamplerType("sampler2D", *fTexture2D))
117         , fSampler3D(Type::MakeSamplerType("sampler3D", *fTexture3D))
118         , fSamplerExternalOES(Type::MakeSamplerType("samplerExternalOES", *fTextureExternalOES))
119         , fSampler2DRect(Type::MakeSamplerType("sampler2DRect", *fTexture2DRect))
120 
121         , fISampler2D(Type::MakeSamplerType("isampler2D", *fITexture2D))
122 
123         , fSampler(Type::MakeSpecialType("sampler", "ss", Type::TypeKind::kSeparateSampler))
124 
125         , fSubpassInput(Type::MakeTextureType("subpassInput",
126                                               SpvDimSubpassData,
127                                               /*isDepth=*/false,
128                                               /*isArrayedTexture=*/false,
129                                               /*isMultisampled=*/false,
130                                               /*isSampled=*/false))
131         , fSubpassInputMS(Type::MakeTextureType("subpassInputMS",
132                                                 SpvDimSubpassData,
133                                                 /*isDepth=*/false,
134                                                 /*isArrayedTexture=*/false,
135                                                 /*isMultisampled=*/true,
136                                                 /*isSampled=*/false))
137 
138         , fGenType(Type::MakeGenericType("$genType", {fFloat.get(), fFloat2.get(), fFloat3.get(),
139                                                       fFloat4.get()}))
140         , fGenHType(Type::MakeGenericType("$genHType", {fHalf.get(), fHalf2.get(), fHalf3.get(),
141                                                         fHalf4.get()}))
142         , fGenIType(Type::MakeGenericType("$genIType", {fInt.get(), fInt2.get(), fInt3.get(),
143                                                         fInt4.get()}))
144         , fGenUType(Type::MakeGenericType("$genUType", {fUInt.get(), fUInt2.get(), fUInt3.get(),
145                                                         fUInt4.get()}))
146         , fGenBType(Type::MakeGenericType("$genBType", {fBool.get(), fBool2.get(), fBool3.get(),
147                                                         fBool4.get()}))
148         , fMat(Type::MakeGenericType("$mat", {fFloat2x2.get(), fFloat2x3.get(), fFloat2x4.get(),
149                                               fFloat3x2.get(), fFloat3x3.get(), fFloat3x4.get(),
150                                               fFloat4x2.get(), fFloat4x3.get(), fFloat4x4.get()}))
151         , fHMat(Type::MakeGenericType(
152                   "$hmat",
153                   {fHalf2x2.get(), fHalf2x3.get(), fHalf2x4.get(), fHalf3x2.get(), fHalf3x3.get(),
154                    fHalf3x4.get(), fHalf4x2.get(), fHalf4x3.get(), fHalf4x4.get()}))
155         , fSquareMat(Type::MakeGenericType("$squareMat", {fInvalid.get(), fFloat2x2.get(),
156                                                           fFloat3x3.get(), fFloat4x4.get()}))
157         , fSquareHMat(Type::MakeGenericType("$squareHMat", {fInvalid.get(), fHalf2x2.get(),
158                                                             fHalf3x3.get(), fHalf4x4.get()}))
159         , fVec(Type::MakeGenericType("$vec", {fInvalid.get(), fFloat2.get(), fFloat3.get(),
160                                               fFloat4.get()}))
161         , fHVec(Type::MakeGenericType("$hvec", {fInvalid.get(), fHalf2.get(), fHalf3.get(),
162                                                 fHalf4.get()}))
163         , fIVec(Type::MakeGenericType("$ivec", {fInvalid.get(), fInt2.get(), fInt3.get(),
164                                                 fInt4.get()}))
165         , fUVec(Type::MakeGenericType("$uvec", {fInvalid.get(), fUInt2.get(), fUInt3.get(),
166                                                 fUInt4.get()}))
167         , fSVec(Type::MakeGenericType("$svec", {fInvalid.get(), fShort2.get(), fShort3.get(),
168                                                 fShort4.get()}))
169         , fUSVec(Type::MakeGenericType("$usvec", {fInvalid.get(), fUShort2.get(), fUShort3.get(),
170                                                   fUShort4.get()}))
171         , fBVec(Type::MakeGenericType("$bvec", {fInvalid.get(), fBool2.get(), fBool3.get(),
172                                                 fBool4.get()}))
173         , fSkCaps(Type::MakeSpecialType("$sk_Caps", "O", Type::TypeKind::kOther))
174         , fColorFilter(Type::MakeSpecialType("colorFilter", "CF", Type::TypeKind::kColorFilter))
175         , fShader(Type::MakeSpecialType("shader", "SH", Type::TypeKind::kShader))
176         , fBlender(Type::MakeSpecialType("blender", "B", Type::TypeKind::kBlender)) {}
177 
178 }  // namespace SkSL
179