Hash :
da9fb093
Author :
Date :
2016-12-09T17:32:29
Work around atan(y, x) bug on NVIDIA atan(y, x) is not always returning expected results on NVIDIA OpenGL drivers between versions 367 and 375. Work around this by emulating atan(y, x) using the regular atan(x) function. A fix to the driver is expected in a future release. It is most convenient to implement the vector atan(y, x) functions by using the scalar atan(y, x) function. Support for simple dependencies between emulated functions is added to BuiltInFunctionEmulator. In the current implementation one function is allowed to have at most one other function as its dependency. BUG=chromium:672380 TEST=angle_end2end_tests Change-Id: I9eba8b0b7979c7c7eaed353b264932e41830beb1 Reviewed-on: https://chromium-review.googlesource.com/419016 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
//
// 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(TIntermNode *root, ShCompileOptions compileOptions)
{
TInfoSinkBase &sink = getInfoSink().obj;
int shaderVer = getShaderVersion();
if (shaderVer > 100)
{
sink << "#version " << shaderVer << " es\n";
}
// Write built-in extension behaviors.
writeExtensionBehavior();
// 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(), shaderVer);
root->traverse(&emulatePrecision);
emulatePrecision.updateTree();
emulatePrecision.writeEmulationHelpers(sink, shaderVer, SH_ESSL_OUTPUT);
}
RecordConstantPrecision(root, getTemporaryIndex());
// 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 webgl_emu_precision highp\n"
<< "#else\n"
<< "#define webgl_emu_precision mediump\n"
<< "#endif\n\n";
}
else
{
sink << "#define webgl_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";
}
// Write translated shader.
TOutputESSL outputESSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(),
getSymbolTable(), getShaderType(), shaderVer, precisionEmulation,
compileOptions);
root->traverse(&outputESSL);
}
bool TranslatorESSL::shouldFlattenPragmaStdglInvariantAll()
{
// Not necessary when translating to ESSL.
return false;
}
void TranslatorESSL::writeExtensionBehavior()
{
TInfoSinkBase &sink = getInfoSink().obj;
const TExtensionBehavior &extBehavior = getExtensionBehavior();
for (TExtensionBehavior::const_iterator iter = extBehavior.begin(); iter != extBehavior.end();
++iter)
{
if (iter->second != EBhUndefined)
{
if (getResources().NV_shader_framebuffer_fetch &&
iter->first == "GL_EXT_shader_framebuffer_fetch")
{
sink << "#extension GL_NV_shader_framebuffer_fetch : "
<< getBehaviorString(iter->second) << "\n";
}
else if (getResources().NV_draw_buffers && iter->first == "GL_EXT_draw_buffers")
{
sink << "#extension GL_NV_draw_buffers : " << getBehaviorString(iter->second)
<< "\n";
}
else
{
sink << "#extension " << iter->first << " : " << getBehaviorString(iter->second)
<< "\n";
}
}
}
}
} // namespace sh