xref: /aosp_15_r20/external/angle/src/compiler/translator/tree_ops/InitializeVariables.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_TREEOPS_INITIALIZEVARIABLES_H_
8 #define COMPILER_TRANSLATOR_TREEOPS_INITIALIZEVARIABLES_H_
9 
10 #include <GLSLANG/ShaderLang.h>
11 
12 #include "compiler/translator/ExtensionBehavior.h"
13 #include "compiler/translator/IntermNode.h"
14 
15 namespace sh
16 {
17 class TCompiler;
18 class TSymbolTable;
19 
20 typedef std::vector<sh::ShaderVariable> InitVariableList;
21 
22 // For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of
23 // a large number of initializers where it can make sense, such as for initializing large arrays.
24 
25 // Populate a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
26 // may be an array, struct or any combination of these, as long as it contains only basic types.
27 void CreateInitCode(const TIntermTyped *initializedSymbol,
28                     bool canUseLoopsToInitialize,
29                     bool highPrecisionSupported,
30                     TIntermSequence *initCode,
31                     TSymbolTable *symbolTable);
32 
33 // Initialize all uninitialized local variables, so that undefined behavior is avoided.
34 [[nodiscard]] bool InitializeUninitializedLocals(TCompiler *compiler,
35                                                  TIntermBlock *root,
36                                                  int shaderVersion,
37                                                  bool canUseLoopsToInitialize,
38                                                  bool highPrecisionSupported,
39                                                  TSymbolTable *symbolTable);
40 
41 // This function can initialize all the types that CreateInitCode is able to initialize. All
42 // variables must be globals which can be found in the symbol table. For now it is used for the
43 // following two scenarios:
44 //   1. Initializing gl_Position;
45 //   2. Initializing output variables referred to in the shader source.
46 // Note: The type of each lvalue in an initializer is retrieved from the symbol table. gl_FragData
47 // requires special handling because the number of indices which can be initialized is determined by
48 // enabled extensions.
49 [[nodiscard]] bool InitializeVariables(TCompiler *compiler,
50                                        TIntermBlock *root,
51                                        const InitVariableList &vars,
52                                        TSymbolTable *symbolTable,
53                                        int shaderVersion,
54                                        const TExtensionBehavior &extensionBehavior,
55                                        bool canUseLoopsToInitialize,
56                                        bool highPrecisionSupported);
57 
58 }  // namespace sh
59 
60 #endif  // COMPILER_TRANSLATOR_TREEOPS_INITIALIZEVARIABLES_H_
61