1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2013 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // ShaderVars.h:
7*8975f5c5SAndroid Build Coastguard Worker // Types to represent GL variables (varyings, uniforms, etc)
8*8975f5c5SAndroid Build Coastguard Worker //
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker #ifndef GLSLANG_SHADERVARS_H_
11*8975f5c5SAndroid Build Coastguard Worker #define GLSLANG_SHADERVARS_H_
12*8975f5c5SAndroid Build Coastguard Worker
13*8975f5c5SAndroid Build Coastguard Worker #include <algorithm>
14*8975f5c5SAndroid Build Coastguard Worker #include <array>
15*8975f5c5SAndroid Build Coastguard Worker #include <cstdint>
16*8975f5c5SAndroid Build Coastguard Worker #include <string>
17*8975f5c5SAndroid Build Coastguard Worker #include <vector>
18*8975f5c5SAndroid Build Coastguard Worker
19*8975f5c5SAndroid Build Coastguard Worker namespace sh
20*8975f5c5SAndroid Build Coastguard Worker {
21*8975f5c5SAndroid Build Coastguard Worker // GLenum alias
22*8975f5c5SAndroid Build Coastguard Worker typedef unsigned int GLenum;
23*8975f5c5SAndroid Build Coastguard Worker
24*8975f5c5SAndroid Build Coastguard Worker // Varying interpolation qualifier, see section 4.3.9 of the ESSL 3.00.4 spec
25*8975f5c5SAndroid Build Coastguard Worker enum InterpolationType
26*8975f5c5SAndroid Build Coastguard Worker {
27*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_SMOOTH,
28*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_FLAT,
29*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_NOPERSPECTIVE,
30*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_CENTROID,
31*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_SAMPLE,
32*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_NOPERSPECTIVE_CENTROID,
33*8975f5c5SAndroid Build Coastguard Worker INTERPOLATION_NOPERSPECTIVE_SAMPLE
34*8975f5c5SAndroid Build Coastguard Worker };
35*8975f5c5SAndroid Build Coastguard Worker
36*8975f5c5SAndroid Build Coastguard Worker const char *InterpolationTypeToString(InterpolationType type);
37*8975f5c5SAndroid Build Coastguard Worker
38*8975f5c5SAndroid Build Coastguard Worker // Validate link & SSO consistency of interpolation qualifiers
39*8975f5c5SAndroid Build Coastguard Worker bool InterpolationTypesMatch(InterpolationType a, InterpolationType b);
40*8975f5c5SAndroid Build Coastguard Worker
41*8975f5c5SAndroid Build Coastguard Worker // Uniform block layout qualifier, see section 4.3.8.3 of the ESSL 3.00.4 spec
42*8975f5c5SAndroid Build Coastguard Worker enum BlockLayoutType
43*8975f5c5SAndroid Build Coastguard Worker {
44*8975f5c5SAndroid Build Coastguard Worker BLOCKLAYOUT_STANDARD,
45*8975f5c5SAndroid Build Coastguard Worker BLOCKLAYOUT_STD140 = BLOCKLAYOUT_STANDARD,
46*8975f5c5SAndroid Build Coastguard Worker BLOCKLAYOUT_STD430, // Shader storage block layout qualifier
47*8975f5c5SAndroid Build Coastguard Worker BLOCKLAYOUT_PACKED,
48*8975f5c5SAndroid Build Coastguard Worker BLOCKLAYOUT_SHARED
49*8975f5c5SAndroid Build Coastguard Worker };
50*8975f5c5SAndroid Build Coastguard Worker
51*8975f5c5SAndroid Build Coastguard Worker const char *BlockLayoutTypeToString(BlockLayoutType type);
52*8975f5c5SAndroid Build Coastguard Worker
53*8975f5c5SAndroid Build Coastguard Worker // Interface Blocks, see section 4.3.9 of the ESSL 3.10 spec
54*8975f5c5SAndroid Build Coastguard Worker enum class BlockType
55*8975f5c5SAndroid Build Coastguard Worker {
56*8975f5c5SAndroid Build Coastguard Worker kBlockUniform,
57*8975f5c5SAndroid Build Coastguard Worker kBlockBuffer,
58*8975f5c5SAndroid Build Coastguard Worker kPixelLocalExt, // GL_EXT_shader_pixel_local_storage.
59*8975f5c5SAndroid Build Coastguard Worker };
60*8975f5c5SAndroid Build Coastguard Worker
61*8975f5c5SAndroid Build Coastguard Worker const char *BlockTypeToString(BlockType type);
62*8975f5c5SAndroid Build Coastguard Worker
63*8975f5c5SAndroid Build Coastguard Worker // Base class for all variables defined in shaders, including Varyings, Uniforms, etc
64*8975f5c5SAndroid Build Coastguard Worker // Note: we must override the copy constructor and assignment operator so we can
65*8975f5c5SAndroid Build Coastguard Worker // work around excessive GCC binary bloating:
66*8975f5c5SAndroid Build Coastguard Worker // See https://code.google.com/p/angleproject/issues/detail?id=697
67*8975f5c5SAndroid Build Coastguard Worker struct ShaderVariable
68*8975f5c5SAndroid Build Coastguard Worker {
69*8975f5c5SAndroid Build Coastguard Worker ShaderVariable();
70*8975f5c5SAndroid Build Coastguard Worker ShaderVariable(GLenum typeIn);
71*8975f5c5SAndroid Build Coastguard Worker ShaderVariable(GLenum typeIn, unsigned int arraySizeIn);
72*8975f5c5SAndroid Build Coastguard Worker ~ShaderVariable();
73*8975f5c5SAndroid Build Coastguard Worker ShaderVariable(const ShaderVariable &other);
74*8975f5c5SAndroid Build Coastguard Worker ShaderVariable &operator=(const ShaderVariable &other);
75*8975f5c5SAndroid Build Coastguard Worker bool operator==(const ShaderVariable &other) const;
76*8975f5c5SAndroid Build Coastguard Worker bool operator!=(const ShaderVariable &other) const { return !operator==(other); }
77*8975f5c5SAndroid Build Coastguard Worker
isArrayOfArraysShaderVariable78*8975f5c5SAndroid Build Coastguard Worker bool isArrayOfArrays() const { return arraySizes.size() >= 2u; }
isArrayShaderVariable79*8975f5c5SAndroid Build Coastguard Worker bool isArray() const { return !arraySizes.empty(); }
80*8975f5c5SAndroid Build Coastguard Worker unsigned int getArraySizeProduct() const;
81*8975f5c5SAndroid Build Coastguard Worker // Return the inner array size product.
82*8975f5c5SAndroid Build Coastguard Worker // For example, if there's a variable declared as size 3 array of size 4 array of size 5 array
83*8975f5c5SAndroid Build Coastguard Worker // of int:
84*8975f5c5SAndroid Build Coastguard Worker // int a[3][4][5];
85*8975f5c5SAndroid Build Coastguard Worker // then getInnerArraySizeProduct of a would be 4*5.
86*8975f5c5SAndroid Build Coastguard Worker unsigned int getInnerArraySizeProduct() const;
87*8975f5c5SAndroid Build Coastguard Worker
88*8975f5c5SAndroid Build Coastguard Worker // Array size 0 means not an array when passed to or returned from these functions.
89*8975f5c5SAndroid Build Coastguard Worker // Note that setArraySize() is deprecated and should not be used inside ANGLE.
getOutermostArraySizeShaderVariable90*8975f5c5SAndroid Build Coastguard Worker unsigned int getOutermostArraySize() const { return isArray() ? arraySizes.back() : 0; }
91*8975f5c5SAndroid Build Coastguard Worker void setArraySize(unsigned int size);
92*8975f5c5SAndroid Build Coastguard Worker
93*8975f5c5SAndroid Build Coastguard Worker // Turn this ShaderVariable from an array into a specific element in that array. Will update
94*8975f5c5SAndroid Build Coastguard Worker // flattenedOffsetInParentArrays.
95*8975f5c5SAndroid Build Coastguard Worker void indexIntoArray(unsigned int arrayIndex);
96*8975f5c5SAndroid Build Coastguard Worker
97*8975f5c5SAndroid Build Coastguard Worker // Get the nth nested array size from the top. Caller is responsible for range checking
98*8975f5c5SAndroid Build Coastguard Worker // arrayNestingIndex.
99*8975f5c5SAndroid Build Coastguard Worker unsigned int getNestedArraySize(unsigned int arrayNestingIndex) const;
100*8975f5c5SAndroid Build Coastguard Worker
101*8975f5c5SAndroid Build Coastguard Worker // This function should only be used with variables that are of a basic type or an array of a
102*8975f5c5SAndroid Build Coastguard Worker // basic type. Shader interface variables that are enumerated according to rules in GLES 3.1
103*8975f5c5SAndroid Build Coastguard Worker // spec section 7.3.1.1 page 77 are fine. For those variables the return value should match the
104*8975f5c5SAndroid Build Coastguard Worker // ARRAY_SIZE value that can be queried through the API.
105*8975f5c5SAndroid Build Coastguard Worker unsigned int getBasicTypeElementCount() const;
106*8975f5c5SAndroid Build Coastguard Worker
107*8975f5c5SAndroid Build Coastguard Worker unsigned int getExternalSize() const;
108*8975f5c5SAndroid Build Coastguard Worker
isStructShaderVariable109*8975f5c5SAndroid Build Coastguard Worker bool isStruct() const { return !fields.empty(); }
getStructNameShaderVariable110*8975f5c5SAndroid Build Coastguard Worker const std::string &getStructName() const { return structOrBlockName; }
setStructNameShaderVariable111*8975f5c5SAndroid Build Coastguard Worker void setStructName(const std::string &newName) { structOrBlockName = newName; }
112*8975f5c5SAndroid Build Coastguard Worker
113*8975f5c5SAndroid Build Coastguard Worker // All of the shader's variables are described using nested data
114*8975f5c5SAndroid Build Coastguard Worker // structures. This is needed in order to disambiguate similar looking
115*8975f5c5SAndroid Build Coastguard Worker // types, such as two structs containing the same fields, but in
116*8975f5c5SAndroid Build Coastguard Worker // different orders. "findInfoByMappedName" provides an easy query for
117*8975f5c5SAndroid Build Coastguard Worker // users to dive into the data structure and fetch the unique variable
118*8975f5c5SAndroid Build Coastguard Worker // instance corresponding to a dereferencing chain of the top-level
119*8975f5c5SAndroid Build Coastguard Worker // variable.
120*8975f5c5SAndroid Build Coastguard Worker // Given a mapped name like 'a[0].b.c[0]', return the ShaderVariable
121*8975f5c5SAndroid Build Coastguard Worker // that defines 'c' in |leafVar|, and the original name 'A[0].B.C[0]'
122*8975f5c5SAndroid Build Coastguard Worker // in |originalName|, based on the assumption that |this| defines 'a'.
123*8975f5c5SAndroid Build Coastguard Worker // If no match is found, return false.
124*8975f5c5SAndroid Build Coastguard Worker bool findInfoByMappedName(const std::string &mappedFullName,
125*8975f5c5SAndroid Build Coastguard Worker const ShaderVariable **leafVar,
126*8975f5c5SAndroid Build Coastguard Worker std::string *originalFullName) const;
127*8975f5c5SAndroid Build Coastguard Worker
128*8975f5c5SAndroid Build Coastguard Worker // Find the child field which matches 'fullName' == var.name + "." + field.name.
129*8975f5c5SAndroid Build Coastguard Worker // Return nullptr if not found.
130*8975f5c5SAndroid Build Coastguard Worker const sh::ShaderVariable *findField(const std::string &fullName, uint32_t *fieldIndexOut) const;
131*8975f5c5SAndroid Build Coastguard Worker
132*8975f5c5SAndroid Build Coastguard Worker bool isBuiltIn() const;
133*8975f5c5SAndroid Build Coastguard Worker bool isEmulatedBuiltIn() const;
134*8975f5c5SAndroid Build Coastguard Worker
135*8975f5c5SAndroid Build Coastguard Worker // Offset of this variable in parent arrays. In case the parent is an array of arrays, the
136*8975f5c5SAndroid Build Coastguard Worker // offset is outerArrayElement * innerArraySize + innerArrayElement.
137*8975f5c5SAndroid Build Coastguard Worker // For example, if there's a variable declared as size 3 array of size 4 array of int:
138*8975f5c5SAndroid Build Coastguard Worker // int a[3][4];
139*8975f5c5SAndroid Build Coastguard Worker // then the flattenedOffsetInParentArrays of a[2] would be 2.
140*8975f5c5SAndroid Build Coastguard Worker // and flattenedOffsetInParentArrays of a[2][1] would be 2*4 + 1 = 9.
parentArrayIndexShaderVariable141*8975f5c5SAndroid Build Coastguard Worker int parentArrayIndex() const
142*8975f5c5SAndroid Build Coastguard Worker {
143*8975f5c5SAndroid Build Coastguard Worker return hasParentArrayIndex() ? flattenedOffsetInParentArrays : 0;
144*8975f5c5SAndroid Build Coastguard Worker }
145*8975f5c5SAndroid Build Coastguard Worker
getFlattenedOffsetInParentArraysShaderVariable146*8975f5c5SAndroid Build Coastguard Worker int getFlattenedOffsetInParentArrays() const { return flattenedOffsetInParentArrays; }
setParentArrayIndexShaderVariable147*8975f5c5SAndroid Build Coastguard Worker void setParentArrayIndex(int indexIn) { flattenedOffsetInParentArrays = indexIn; }
148*8975f5c5SAndroid Build Coastguard Worker
hasParentArrayIndexShaderVariable149*8975f5c5SAndroid Build Coastguard Worker bool hasParentArrayIndex() const { return flattenedOffsetInParentArrays != -1; }
150*8975f5c5SAndroid Build Coastguard Worker
151*8975f5c5SAndroid Build Coastguard Worker void resetEffectiveLocation();
152*8975f5c5SAndroid Build Coastguard Worker void updateEffectiveLocation(const sh::ShaderVariable &parent);
153*8975f5c5SAndroid Build Coastguard Worker
154*8975f5c5SAndroid Build Coastguard Worker // Decide whether two uniforms are the same at shader link time,
155*8975f5c5SAndroid Build Coastguard Worker // assuming they are from consecutive shader stages.
156*8975f5c5SAndroid Build Coastguard Worker // GLSL ES Spec 3.00.3, section 4.3.5.
157*8975f5c5SAndroid Build Coastguard Worker // GLSL ES Spec 3.10.4, section 4.4.5
158*8975f5c5SAndroid Build Coastguard Worker bool isSameUniformAtLinkTime(const ShaderVariable &other) const;
159*8975f5c5SAndroid Build Coastguard Worker
160*8975f5c5SAndroid Build Coastguard Worker // InterfaceBlockField
161*8975f5c5SAndroid Build Coastguard Worker // Decide whether two InterfaceBlock fields are the same at shader
162*8975f5c5SAndroid Build Coastguard Worker // link time, assuming they are from consecutive shader stages.
163*8975f5c5SAndroid Build Coastguard Worker // See GLSL ES Spec 3.00.3, sec 4.3.7.
164*8975f5c5SAndroid Build Coastguard Worker bool isSameInterfaceBlockFieldAtLinkTime(const ShaderVariable &other) const;
165*8975f5c5SAndroid Build Coastguard Worker
166*8975f5c5SAndroid Build Coastguard Worker // Decide whether two varyings are the same at shader link time,
167*8975f5c5SAndroid Build Coastguard Worker // assuming they are from consecutive shader stages.
168*8975f5c5SAndroid Build Coastguard Worker // Invariance needs to match only in ESSL1. Relevant spec sections:
169*8975f5c5SAndroid Build Coastguard Worker // GLSL ES 3.00.4, sections 4.6.1 and 4.3.9.
170*8975f5c5SAndroid Build Coastguard Worker // GLSL ES 1.00.17, section 4.6.4.
171*8975f5c5SAndroid Build Coastguard Worker bool isSameVaryingAtLinkTime(const ShaderVariable &other, int shaderVersion) const;
172*8975f5c5SAndroid Build Coastguard Worker // Deprecated version of isSameVaryingAtLinkTime, which assumes ESSL1.
173*8975f5c5SAndroid Build Coastguard Worker bool isSameVaryingAtLinkTime(const ShaderVariable &other) const;
174*8975f5c5SAndroid Build Coastguard Worker
175*8975f5c5SAndroid Build Coastguard Worker // Shader I/O blocks may match by block name or instance, based on whether both stages have an
176*8975f5c5SAndroid Build Coastguard Worker // instance name or not.
177*8975f5c5SAndroid Build Coastguard Worker bool isSameNameAtLinkTime(const ShaderVariable &other) const;
178*8975f5c5SAndroid Build Coastguard Worker
179*8975f5c5SAndroid Build Coastguard Worker // NOTE: When adding new members, the following functions also need to be updated:
180*8975f5c5SAndroid Build Coastguard Worker // gl::WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var)
181*8975f5c5SAndroid Build Coastguard Worker // gl::LoadShaderVar(BinaryInputStream *stream, sh::ShaderVariable *var)
182*8975f5c5SAndroid Build Coastguard Worker
183*8975f5c5SAndroid Build Coastguard Worker GLenum type;
184*8975f5c5SAndroid Build Coastguard Worker GLenum precision;
185*8975f5c5SAndroid Build Coastguard Worker std::string name;
186*8975f5c5SAndroid Build Coastguard Worker std::string mappedName;
187*8975f5c5SAndroid Build Coastguard Worker
188*8975f5c5SAndroid Build Coastguard Worker // Used to make an array type. Outermost array size is stored at the end of the vector.
189*8975f5c5SAndroid Build Coastguard Worker std::vector<unsigned int> arraySizes;
190*8975f5c5SAndroid Build Coastguard Worker
191*8975f5c5SAndroid Build Coastguard Worker // Static use means that the variable is accessed somewhere in the shader source.
192*8975f5c5SAndroid Build Coastguard Worker bool staticUse;
193*8975f5c5SAndroid Build Coastguard Worker // A variable is active unless the compiler determined that it is not accessed by the shader.
194*8975f5c5SAndroid Build Coastguard Worker // All active variables are statically used, but not all statically used variables are
195*8975f5c5SAndroid Build Coastguard Worker // necessarily active. GLES 3.0.5 section 2.12.6. GLES 3.1 section 7.3.1.
196*8975f5c5SAndroid Build Coastguard Worker bool active;
197*8975f5c5SAndroid Build Coastguard Worker std::vector<ShaderVariable> fields;
198*8975f5c5SAndroid Build Coastguard Worker // structOrBlockName is used for:
199*8975f5c5SAndroid Build Coastguard Worker // - varyings of struct type, in which case it contains the struct name.
200*8975f5c5SAndroid Build Coastguard Worker // - shader I/O blocks, in which case it contains the block name.
201*8975f5c5SAndroid Build Coastguard Worker std::string structOrBlockName;
202*8975f5c5SAndroid Build Coastguard Worker std::string mappedStructOrBlockName;
203*8975f5c5SAndroid Build Coastguard Worker
204*8975f5c5SAndroid Build Coastguard Worker // Only applies to interface block fields. Kept here for simplicity.
205*8975f5c5SAndroid Build Coastguard Worker bool isRowMajorLayout;
206*8975f5c5SAndroid Build Coastguard Worker
207*8975f5c5SAndroid Build Coastguard Worker // VariableWithLocation
208*8975f5c5SAndroid Build Coastguard Worker int location;
209*8975f5c5SAndroid Build Coastguard Worker
210*8975f5c5SAndroid Build Coastguard Worker // The location of inputs or outputs without location layout quailifer will be updated to '-1'.
211*8975f5c5SAndroid Build Coastguard Worker // GLES Spec 3.1, Section 7.3. PROGRAM OBJECTS
212*8975f5c5SAndroid Build Coastguard Worker // Not all active variables are assigned valid locations;
213*8975f5c5SAndroid Build Coastguard Worker // the following variables will have an effective location of -1:
214*8975f5c5SAndroid Build Coastguard Worker bool hasImplicitLocation;
215*8975f5c5SAndroid Build Coastguard Worker
216*8975f5c5SAndroid Build Coastguard Worker // Uniform
217*8975f5c5SAndroid Build Coastguard Worker int binding;
218*8975f5c5SAndroid Build Coastguard Worker GLenum imageUnitFormat;
219*8975f5c5SAndroid Build Coastguard Worker int offset;
220*8975f5c5SAndroid Build Coastguard Worker bool rasterOrdered;
221*8975f5c5SAndroid Build Coastguard Worker bool readonly;
222*8975f5c5SAndroid Build Coastguard Worker bool writeonly;
223*8975f5c5SAndroid Build Coastguard Worker
224*8975f5c5SAndroid Build Coastguard Worker // From EXT_shader_framebuffer_fetch / KHR_blend_equation_advanced
225*8975f5c5SAndroid Build Coastguard Worker bool isFragmentInOut;
226*8975f5c5SAndroid Build Coastguard Worker
227*8975f5c5SAndroid Build Coastguard Worker // OutputVariable
228*8975f5c5SAndroid Build Coastguard Worker // From EXT_blend_func_extended.
229*8975f5c5SAndroid Build Coastguard Worker int index;
230*8975f5c5SAndroid Build Coastguard Worker
231*8975f5c5SAndroid Build Coastguard Worker // From EXT_YUV_target
232*8975f5c5SAndroid Build Coastguard Worker bool yuv;
233*8975f5c5SAndroid Build Coastguard Worker
234*8975f5c5SAndroid Build Coastguard Worker // Varying
235*8975f5c5SAndroid Build Coastguard Worker InterpolationType interpolation;
236*8975f5c5SAndroid Build Coastguard Worker bool isInvariant;
237*8975f5c5SAndroid Build Coastguard Worker bool isShaderIOBlock;
238*8975f5c5SAndroid Build Coastguard Worker bool isPatch;
239*8975f5c5SAndroid Build Coastguard Worker
240*8975f5c5SAndroid Build Coastguard Worker // If the variable is a sampler that has ever been statically used with texelFetch
241*8975f5c5SAndroid Build Coastguard Worker bool texelFetchStaticUse;
242*8975f5c5SAndroid Build Coastguard Worker
243*8975f5c5SAndroid Build Coastguard Worker // Id of the variable in the shader. Currently used by the SPIR-V output to communicate the
244*8975f5c5SAndroid Build Coastguard Worker // SPIR-V id of the variable. This value is only set for variables that the SPIR-V transformer
245*8975f5c5SAndroid Build Coastguard Worker // needs to know about, i.e. active variables, excluding non-zero array elements etc.
246*8975f5c5SAndroid Build Coastguard Worker uint32_t id;
247*8975f5c5SAndroid Build Coastguard Worker
248*8975f5c5SAndroid Build Coastguard Worker protected:
249*8975f5c5SAndroid Build Coastguard Worker bool isSameVariableAtLinkTime(const ShaderVariable &other,
250*8975f5c5SAndroid Build Coastguard Worker bool matchPrecision,
251*8975f5c5SAndroid Build Coastguard Worker bool matchName) const;
252*8975f5c5SAndroid Build Coastguard Worker
253*8975f5c5SAndroid Build Coastguard Worker // NOTE: When adding new members, the following functions also need to be updated:
254*8975f5c5SAndroid Build Coastguard Worker // gl::WriteShaderVar(BinaryOutputStream *stream, const sh::ShaderVariable &var)
255*8975f5c5SAndroid Build Coastguard Worker // gl::LoadShaderVar(BinaryInputStream *stream, sh::ShaderVariable *var)
256*8975f5c5SAndroid Build Coastguard Worker
257*8975f5c5SAndroid Build Coastguard Worker int flattenedOffsetInParentArrays;
258*8975f5c5SAndroid Build Coastguard Worker };
259*8975f5c5SAndroid Build Coastguard Worker
260*8975f5c5SAndroid Build Coastguard Worker // TODO: anglebug.com/42262544
261*8975f5c5SAndroid Build Coastguard Worker // For backwards compatibility for other codebases (e.g., chromium/src/gpu/command_buffer/service)
262*8975f5c5SAndroid Build Coastguard Worker using Uniform = ShaderVariable;
263*8975f5c5SAndroid Build Coastguard Worker using Attribute = ShaderVariable;
264*8975f5c5SAndroid Build Coastguard Worker using OutputVariable = ShaderVariable;
265*8975f5c5SAndroid Build Coastguard Worker using InterfaceBlockField = ShaderVariable;
266*8975f5c5SAndroid Build Coastguard Worker using Varying = ShaderVariable;
267*8975f5c5SAndroid Build Coastguard Worker
268*8975f5c5SAndroid Build Coastguard Worker struct InterfaceBlock
269*8975f5c5SAndroid Build Coastguard Worker {
270*8975f5c5SAndroid Build Coastguard Worker InterfaceBlock();
271*8975f5c5SAndroid Build Coastguard Worker ~InterfaceBlock();
272*8975f5c5SAndroid Build Coastguard Worker InterfaceBlock(const InterfaceBlock &other);
273*8975f5c5SAndroid Build Coastguard Worker InterfaceBlock &operator=(const InterfaceBlock &other);
274*8975f5c5SAndroid Build Coastguard Worker
275*8975f5c5SAndroid Build Coastguard Worker // Fields from blocks with non-empty instance names are prefixed with the block name.
276*8975f5c5SAndroid Build Coastguard Worker std::string fieldPrefix() const;
277*8975f5c5SAndroid Build Coastguard Worker std::string fieldMappedPrefix() const;
278*8975f5c5SAndroid Build Coastguard Worker
279*8975f5c5SAndroid Build Coastguard Worker // Decide whether two interface blocks are the same at shader link time.
280*8975f5c5SAndroid Build Coastguard Worker bool isSameInterfaceBlockAtLinkTime(const InterfaceBlock &other) const;
281*8975f5c5SAndroid Build Coastguard Worker
282*8975f5c5SAndroid Build Coastguard Worker bool isBuiltIn() const;
283*8975f5c5SAndroid Build Coastguard Worker
isArrayInterfaceBlock284*8975f5c5SAndroid Build Coastguard Worker bool isArray() const { return arraySize > 0; }
elementCountInterfaceBlock285*8975f5c5SAndroid Build Coastguard Worker unsigned int elementCount() const { return std::max(1u, arraySize); }
286*8975f5c5SAndroid Build Coastguard Worker
287*8975f5c5SAndroid Build Coastguard Worker std::string name;
288*8975f5c5SAndroid Build Coastguard Worker std::string mappedName;
289*8975f5c5SAndroid Build Coastguard Worker std::string instanceName;
290*8975f5c5SAndroid Build Coastguard Worker unsigned int arraySize;
291*8975f5c5SAndroid Build Coastguard Worker BlockLayoutType layout;
292*8975f5c5SAndroid Build Coastguard Worker
293*8975f5c5SAndroid Build Coastguard Worker // Deprecated. Matrix packing should only be queried from individual fields of the block.
294*8975f5c5SAndroid Build Coastguard Worker // TODO(oetuaho): Remove this once it is no longer used in Chromium.
295*8975f5c5SAndroid Build Coastguard Worker bool isRowMajorLayout;
296*8975f5c5SAndroid Build Coastguard Worker
297*8975f5c5SAndroid Build Coastguard Worker int binding;
298*8975f5c5SAndroid Build Coastguard Worker bool staticUse;
299*8975f5c5SAndroid Build Coastguard Worker bool active;
300*8975f5c5SAndroid Build Coastguard Worker // Only applied to SSBOs, |isReadOnly| tells if the readonly qualifier is specified.
301*8975f5c5SAndroid Build Coastguard Worker bool isReadOnly;
302*8975f5c5SAndroid Build Coastguard Worker BlockType blockType;
303*8975f5c5SAndroid Build Coastguard Worker std::vector<ShaderVariable> fields;
304*8975f5c5SAndroid Build Coastguard Worker
305*8975f5c5SAndroid Build Coastguard Worker // Id of the interface block in the shader. Similar to |ShaderVariable::id|.
306*8975f5c5SAndroid Build Coastguard Worker uint32_t id;
307*8975f5c5SAndroid Build Coastguard Worker };
308*8975f5c5SAndroid Build Coastguard Worker
309*8975f5c5SAndroid Build Coastguard Worker struct WorkGroupSize
310*8975f5c5SAndroid Build Coastguard Worker {
311*8975f5c5SAndroid Build Coastguard Worker // Must have a trivial default constructor since it is used in YYSTYPE.
312*8975f5c5SAndroid Build Coastguard Worker inline WorkGroupSize() = default;
313*8975f5c5SAndroid Build Coastguard Worker inline explicit constexpr WorkGroupSize(int initialSize);
314*8975f5c5SAndroid Build Coastguard Worker
315*8975f5c5SAndroid Build Coastguard Worker void fill(int fillValue);
316*8975f5c5SAndroid Build Coastguard Worker void setLocalSize(int localSizeX, int localSizeY, int localSizeZ);
317*8975f5c5SAndroid Build Coastguard Worker
318*8975f5c5SAndroid Build Coastguard Worker int &operator[](size_t index);
319*8975f5c5SAndroid Build Coastguard Worker int operator[](size_t index) const;
320*8975f5c5SAndroid Build Coastguard Worker size_t size() const;
321*8975f5c5SAndroid Build Coastguard Worker
322*8975f5c5SAndroid Build Coastguard Worker // Checks whether two work group size declarations match.
323*8975f5c5SAndroid Build Coastguard Worker // Two work group size declarations are the same if the explicitly specified elements are the
324*8975f5c5SAndroid Build Coastguard Worker // same or if one of them is specified as one and the other one is not specified
325*8975f5c5SAndroid Build Coastguard Worker bool isWorkGroupSizeMatching(const WorkGroupSize &right) const;
326*8975f5c5SAndroid Build Coastguard Worker
327*8975f5c5SAndroid Build Coastguard Worker // Checks whether any of the values are set.
328*8975f5c5SAndroid Build Coastguard Worker bool isAnyValueSet() const;
329*8975f5c5SAndroid Build Coastguard Worker
330*8975f5c5SAndroid Build Coastguard Worker // Checks whether all of the values are set.
331*8975f5c5SAndroid Build Coastguard Worker bool isDeclared() const;
332*8975f5c5SAndroid Build Coastguard Worker
333*8975f5c5SAndroid Build Coastguard Worker // Checks whether either all of the values are set, or none of them are.
334*8975f5c5SAndroid Build Coastguard Worker bool isLocalSizeValid() const;
335*8975f5c5SAndroid Build Coastguard Worker
336*8975f5c5SAndroid Build Coastguard Worker int localSizeQualifiers[3];
337*8975f5c5SAndroid Build Coastguard Worker };
338*8975f5c5SAndroid Build Coastguard Worker
WorkGroupSize(int initialSize)339*8975f5c5SAndroid Build Coastguard Worker inline constexpr WorkGroupSize::WorkGroupSize(int initialSize)
340*8975f5c5SAndroid Build Coastguard Worker : localSizeQualifiers{initialSize, initialSize, initialSize}
341*8975f5c5SAndroid Build Coastguard Worker {}
342*8975f5c5SAndroid Build Coastguard Worker
343*8975f5c5SAndroid Build Coastguard Worker } // namespace sh
344*8975f5c5SAndroid Build Coastguard Worker
345*8975f5c5SAndroid Build Coastguard Worker #endif // GLSLANG_SHADERVARS_H_
346