Hash :
2c7f34c8
Author :
Date :
2017-10-09T17:18:02
Initialize uninitialized GLSL arrays in a for loop Previously, creating nodes for initializing each single array element could result in memory bloat during translation when dealing with large arrays. The resulting shader could also end up very long. Initialize most arrays using a simple for loop instead. The loop is compatible with ESSL 1.00 Appendix A limitations. An exception is made for fragment outputs, so that they are not indexed by non-constant values. On some platforms using the a loop to initialize variables can cause problems, so we also have a compiler flag for turning this behavior off. The flag was already added earlier for a staggered rollout of this functionality. BUG=chromium:735497 TEST=angle_unittests, angle_end2end_tests, WebGL conformance tests Change-Id: Iec727821d8137db56b440ddbe007879b1b55f61f Reviewed-on: https://chromium-review.googlesource.com/707195 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
#define COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_
#include <GLSLANG/ShaderLang.h>
#include "compiler/translator/ExtensionBehavior.h"
#include "compiler/translator/IntermNode.h"
namespace sh
{
class TSymbolTable;
typedef std::vector<sh::ShaderVariable> InitVariableList;
// For all of the functions below: If canUseLoopsToInitialize is set, for loops are used instead of
// a large number of initializers where it can make sense, such as for initializing large arrays.
// Return a sequence of assignment operations to initialize "initializedSymbol". initializedSymbol
// may be an array, struct or any combination of these, as long as it contains only basic types.
TIntermSequence *CreateInitCode(const TIntermTyped *initializedSymbol,
bool canUseLoopsToInitialize,
TSymbolTable *symbolTable);
// Initialize all uninitialized local variables, so that undefined behavior is avoided.
void InitializeUninitializedLocals(TIntermBlock *root,
int shaderVersion,
bool canUseLoopsToInitialize,
TSymbolTable *symbolTable);
// This function can initialize all the types that CreateInitCode is able to initialize. All
// variables must be globals which can be found in the symbol table. For now it is used for the
// following two scenarios:
// 1. Initializing gl_Position;
// 2. Initializing output variables referred to in the shader source.
// Note: The type of each lvalue in an initializer is retrieved from the symbol table. gl_FragData
// requires special handling because the number of indices which can be initialized is determined by
// enabled extensions.
void InitializeVariables(TIntermBlock *root,
const InitVariableList &vars,
TSymbolTable *symbolTable,
int shaderVersion,
const TExtensionBehavior &extensionBehavior,
bool canUseLoopsToInitialize);
} // namespace sh
#endif // COMPILER_TRANSLATOR_INITIALIZEVARIABLES_H_