Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2013 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 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_ |
| 8 | #define COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_ |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 9 | |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 10 | #include <GLSLANG/ShaderLang.h> |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 11 | |
Martin Radev | e145def | 2017-06-22 12:49:12 +0300 | [diff] [blame] | 12 | #include "compiler/translator/ExtensionBehavior.h" |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 13 | #include "compiler/translator/IntermNode.h" |
| 14 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 15 | namespace sh |
| 16 | { |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 17 | class TSymbolTable; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 18 | |
Zhenyao Mo | 7211191 | 2016-07-20 17:45:56 -0700 | [diff] [blame] | 19 | typedef std::vector<sh::ShaderVariable> InitVariableList; |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 20 | |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 21 | // For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of |
| 22 | // a large number of initializers where it can make sense, such as for initializing large arrays. |
| 23 | |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 24 | // Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol |
| 25 | // may be an array, struct or any combination of these, as long as it contains only basic types. |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 26 | TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol, |
| 27 | bool canUseLoopsToInitialize, |
Olli Etuaho | 87cc90d | 2017-12-12 15:28:06 +0200 | [diff] [blame^] | 28 | bool highPrecisionSupported, |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 29 | TSymbolTable *symbolTable); |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 30 | |
| 31 | // Initialize all uninitialized local variables, so that undefined behavior is avoided. |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 32 | void InitializeUninitializedLocals(TIntermBlock *root, |
| 33 | int shaderVersion, |
| 34 | bool canUseLoopsToInitialize, |
Olli Etuaho | 87cc90d | 2017-12-12 15:28:06 +0200 | [diff] [blame^] | 35 | bool highPrecisionSupported, |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 36 | TSymbolTable *symbolTable); |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 37 | |
Martin Radev | e145def | 2017-06-22 12:49:12 +0300 | [diff] [blame] | 38 | // This function can initialize all the types that CreateInitCode is able to initialize. All |
| 39 | // variables must be globals which can be found in the symbol table. For now it is used for the |
| 40 | // following two scenarios: |
| 41 | // 1. Initializing gl_Position; |
| 42 | // 2. Initializing output variables referred to in the shader source. |
| 43 | // Note: The type of each lvalue in an initializer is retrieved from the symbol table. gl_FragData |
| 44 | // requires special handling because the number of indices which can be initialized is determined by |
Olli Etuaho | daaff1c | 2017-07-05 18:03:26 +0300 | [diff] [blame] | 45 | // enabled extensions. |
Olli Etuaho | 9cbc07c | 2017-05-10 18:22:01 +0300 | [diff] [blame] | 46 | void InitializeVariables(TIntermBlock *root, |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 47 | const InitVariableList &vars, |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 48 | TSymbolTable *symbolTable, |
Martin Radev | e145def | 2017-06-22 12:49:12 +0300 | [diff] [blame] | 49 | int shaderVersion, |
Olli Etuaho | 2c7f34c | 2017-10-09 17:18:02 +0300 | [diff] [blame] | 50 | const TExtensionBehavior &extensionBehavior, |
Olli Etuaho | 87cc90d | 2017-12-12 15:28:06 +0200 | [diff] [blame^] | 51 | bool canUseLoopsToInitialize, |
| 52 | bool highPrecisionSupported); |
Olli Etuaho | 9733cee | 2017-05-11 19:14:35 +0300 | [diff] [blame] | 53 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 54 | } // namespace sh |
Zhenyao Mo | 4a667fe | 2014-02-11 12:35:01 -0800 | [diff] [blame] | 55 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 56 | #endif // COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_ |