blob: f9a83f183d60485201f966d08cd49d2f5b031d81 [file] [log] [blame]
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08001//
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 Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
8#define COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
Zhenyao Mo4a667fe2014-02-11 12:35:01 -08009
Zhenyao Mo72111912016-07-20 17:45:56 -070010#include <GLSLANG/ShaderLang.h>
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080011
Martin Radeve145def2017-06-22 12:49:12 +030012#include "compiler/translator/ExtensionBehavior.h"
Olli Etuaho9733cee2017-05-11 19:14:35 +030013#include "compiler/translator/IntermNode.h"
14
Jamie Madill45bcc782016-11-07 13:58:48 -050015namespace sh
16{
Zhenyao Mod7490962016-11-09 15:49:51 -080017class TSymbolTable;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080018
Zhenyao Mo72111912016-07-20 17:45:56 -070019typedef std::vector<sh::ShaderVariable> InitVariableList;
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080020
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030021// 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 Etuaho9733cee2017-05-11 19:14:35 +030024// 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 Etuaho2c7f34c2017-10-09 17:18:02 +030026TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
27 bool canUseLoopsToInitialize,
Olli Etuaho87cc90d2017-12-12 15:28:06 +020028 bool highPrecisionSupported,
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030029 TSymbolTable *symbolTable);
Olli Etuaho9733cee2017-05-11 19:14:35 +030030
31// Initialize all uninitialized local variables, so that undefined behavior is avoided.
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030032void InitializeUninitializedLocals(TIntermBlock *root,
33 int shaderVersion,
34 bool canUseLoopsToInitialize,
Olli Etuaho87cc90d2017-12-12 15:28:06 +020035 bool highPrecisionSupported,
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030036 TSymbolTable *symbolTable);
Olli Etuaho9733cee2017-05-11 19:14:35 +030037
Martin Radeve145def2017-06-22 12:49:12 +030038// 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 Etuahodaaff1c2017-07-05 18:03:26 +030045// enabled extensions.
Olli Etuaho9cbc07c2017-05-10 18:22:01 +030046void InitializeVariables(TIntermBlock *root,
Zhenyao Mod7490962016-11-09 15:49:51 -080047 const InitVariableList &vars,
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030048 TSymbolTable *symbolTable,
Martin Radeve145def2017-06-22 12:49:12 +030049 int shaderVersion,
Olli Etuaho2c7f34c2017-10-09 17:18:02 +030050 const TExtensionBehavior &extensionBehavior,
Olli Etuaho87cc90d2017-12-12 15:28:06 +020051 bool canUseLoopsToInitialize,
52 bool highPrecisionSupported);
Olli Etuaho9733cee2017-05-11 19:14:35 +030053
Jamie Madill45bcc782016-11-07 13:58:48 -050054} // namespace sh
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080055
Geoff Lang0a73dd82014-11-19 16:18:08 -050056#endif // COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_