blob: 536d0ccfb501ce28eec05e8487d7ee301bbfe705 [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 Etuaho9733cee2017-05-11 19:14:35 +030021// Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
22// may be an array, struct or any combination of these, as long as it contains only basic types.
Olli Etuahodaaff1c2017-07-05 18:03:26 +030023TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol);
Olli Etuaho9733cee2017-05-11 19:14:35 +030024
25// Initialize all uninitialized local variables, so that undefined behavior is avoided.
26void InitializeUninitializedLocals(TIntermBlock *root, int shaderVersion);
27
Martin Radeve145def2017-06-22 12:49:12 +030028// This function can initialize all the types that CreateInitCode is able to initialize. All
29// variables must be globals which can be found in the symbol table. For now it is used for the
30// following two scenarios:
31// 1. Initializing gl_Position;
32// 2. Initializing output variables referred to in the shader source.
33// Note: The type of each lvalue in an initializer is retrieved from the symbol table. gl_FragData
34// requires special handling because the number of indices which can be initialized is determined by
Olli Etuahodaaff1c2017-07-05 18:03:26 +030035// enabled extensions.
Olli Etuaho9cbc07c2017-05-10 18:22:01 +030036void InitializeVariables(TIntermBlock *root,
Zhenyao Mod7490962016-11-09 15:49:51 -080037 const InitVariableList &vars,
Martin Radeve145def2017-06-22 12:49:12 +030038 const TSymbolTable &symbolTable,
39 int shaderVersion,
Martin Radeve145def2017-06-22 12:49:12 +030040 const TExtensionBehavior &extensionBehavior);
Olli Etuaho9733cee2017-05-11 19:14:35 +030041
Jamie Madill45bcc782016-11-07 13:58:48 -050042} // namespace sh
Zhenyao Mo4a667fe2014-02-11 12:35:01 -080043
Geoff Lang0a73dd82014-11-19 16:18:08 -050044#endif // COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_