Hash :
68981eb5
Author :
Date :
2018-01-23T17:46:12
Track parameter qualifiers of functions in call nodes We now add a reference to TFunction to all TIntermAggregate nodes where it is possible, including built-in ops. We also make sure that internal TFunctions added in traversers have correct parameter qualifiers. This makes TLValueTrackingTraverser much simpler. Instead of storing traversed functions or looking up builtin functions from the symbol table, determining which function parameters are out parameters can now be done simply by looking it up from the function symbol associated with the aggregate node. Symbol instances are no longer deleted when a symbol table level goes out of scope, and TFunction destructor no longer clears the parameters. They're all either statically allocated or pool allocated, so this does not result in leaks. TEST=angle_unittests BUG=angleproject:2267 Change-Id: I57e5570da5b5a69a98a8778da3c2dc82b6284738 Reviewed-on: https://chromium-review.googlesource.com/881324 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
//
// 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.
//
#include "compiler/translator/TranslatorESSL.h"
#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
#include "compiler/translator/EmulatePrecision.h"
#include "compiler/translator/RecordConstantPrecision.h"
#include "compiler/translator/OutputESSL.h"
#include "angle_gl.h"
namespace sh
{
TranslatorESSL::TranslatorESSL(sh::GLenum type, ShShaderSpec spec)
: TCompiler(type, spec, SH_ESSL_OUTPUT)
{
}
void TranslatorESSL::initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu,
ShCompileOptions compileOptions)
{
if (compileOptions & SH_EMULATE_ATAN2_FLOAT_FUNCTION)
{
InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(emu);
}
}
void TranslatorESSL::translate(TIntermBlock *root,
ShCompileOptions compileOptions,
PerformanceDiagnostics * /*perfDiagnostics*/)
{
TInfoSinkBase &sink = getInfoSink().obj;
int shaderVer = getShaderVersion();
if (shaderVer > 100)
{
sink << "#version " << shaderVer << " es\n";
}
// Write built-in extension behaviors.
writeExtensionBehavior(compileOptions);
// Write pragmas after extensions because some drivers consider pragmas
// like non-preprocessor tokens.
writePragma(compileOptions);
bool precisionEmulation =
getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (precisionEmulation)
{
EmulatePrecision emulatePrecision(&getSymbolTable());
root->traverse(&emulatePrecision);
emulatePrecision.updateTree();
emulatePrecision.writeEmulationHelpers(sink, shaderVer, SH_ESSL_OUTPUT);
}
RecordConstantPrecision(root, &getSymbolTable());
// Write emulated built-in functions if needed.
if (!getBuiltInFunctionEmulator().isOutputEmpty())
{
sink << "// BEGIN: Generated code for built-in function emulation\n\n";
if (getShaderType() == GL_FRAGMENT_SHADER)
{
sink << "#if defined(GL_FRAGMENT_PRECISION_HIGH)\n"
<< "#define emu_precision highp\n"
<< "#else\n"
<< "#define emu_precision mediump\n"
<< "#endif\n\n";
}
else
{
sink << "#define emu_precision highp\n";
}
getBuiltInFunctionEmulator().outputEmulatedFunctions(sink);
sink << "// END: Generated code for built-in function emulation\n\n";
}
// Write array bounds clamping emulation if needed.
getArrayBoundsClamper().OutputClampingFunctionDefinition(sink);
if (getShaderType() == GL_COMPUTE_SHADER && isComputeShaderLocalSizeDeclared())
{
const sh::WorkGroupSize &localSize = getComputeShaderLocalSize();
sink << "layout (local_size_x=" << localSize[0] << ", local_size_y=" << localSize[1]
<< ", local_size_z=" << localSize[2] << ") in;\n";
}
if (getShaderType() == GL_GEOMETRY_SHADER_EXT)
{
WriteGeometryShaderLayoutQualifiers(
sink, getGeometryShaderInputPrimitiveType(), getGeometryShaderInvocations(),
getGeometryShaderOutputPrimitiveType(), getGeometryShaderMaxVertices());
}
// Write translated shader.
TOutputESSL outputESSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(),
&getSymbolTable(), getShaderType(), shaderVer, precisionEmulation,
compileOptions);
root->traverse(&outputESSL);
}
bool TranslatorESSL::shouldFlattenPragmaStdglInvariantAll()
{
// If following the spec to the letter, we should not flatten this pragma.
// However, the spec's wording means that the pragma applies only to outputs.
// This contradicts the spirit of using the pragma,
// because if the pragma is used in a vertex shader,
// the only way to be able to link it to a fragment shader
// is to manually qualify each of fragment shader's inputs as invariant.
// Which defeats the purpose of this pragma - temporarily make all varyings
// invariant for debugging.
// Thus, we should be non-conformant to spec's letter here and flatten.
return true;
}
void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions)
{
TInfoSinkBase &sink = getInfoSink().obj;
const TExtensionBehavior &extBehavior = getExtensionBehavior();
const bool isMultiviewExtEmulated =
(compileOptions & (SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER)) != 0u;
for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); iter != extBehavior.end();
++iter)
{
if (iter->second != EBhUndefined)
{
const bool isMultiview = (iter->first == TExtension::OVR_multiview);
if (getResources().NV_shader_framebuffer_fetch &&
iter->first == TExtension::EXT_shader_framebuffer_fetch)
{
sink << "#extension GL_NV_shader_framebuffer_fetch : "
<< GetBehaviorString(iter->second) << "\n";
}
else if (getResources().NV_draw_buffers && iter->first == TExtension::EXT_draw_buffers)
{
sink << "#extension GL_NV_draw_buffers : " << GetBehaviorString(iter->second)
<< "\n";
}
else if (isMultiview && isMultiviewExtEmulated)
{
if (getShaderType() == GL_VERTEX_SHADER &&
(compileOptions & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER) != 0u)
{
// Emit the NV_viewport_array2 extension in a vertex shader if the
// SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER option is set and the
// OVR_multiview(2) extension is requested.
sink << "#extension GL_NV_viewport_array2 : require\n";
}
}
else if (iter->first == TExtension::EXT_geometry_shader)
{
sink << "#ifdef GL_EXT_geometry_shader\n"
<< "#extension GL_EXT_geometry_shader : " << GetBehaviorString(iter->second)
<< "\n"
<< "#elif defined GL_OES_geometry_shader\n"
<< "#extension GL_OES_geometry_shader : " << GetBehaviorString(iter->second)
<< "\n";
if (iter->second == EBhRequire)
{
sink << "#else\n"
<< "#error \"No geometry shader extensions available.\" // Only generate "
"this if the extension is \"required\"\n";
}
sink << "#endif\n";
}
else
{
sink << "#extension " << GetExtensionNameString(iter->first) << " : "
<< GetBehaviorString(iter->second) << "\n";
}
}
}
}
} // namespace sh