Commit a4e6f074 by Qiankun Miao Committed by Commit Bot

Work around abs() issue in Intel Mac drivers

abs(i) where i is an integer returns unexpected result in Intel Mac. This works around the issue by emulating abs(i) manually. BUG=chromium:642227 TEST=deqp/functional/gles3/shadercommonfunction.html Change-Id: I2a41e0f4bcb0766109d651e663283b1760468017 Reviewed-on: https://chromium-review.googlesource.com/377628 Commit-Queue: Zhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent c2c5fc48
...@@ -49,7 +49,7 @@ typedef unsigned int GLenum; ...@@ -49,7 +49,7 @@ typedef unsigned int GLenum;
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 156 #define ANGLE_SH_VERSION 157
typedef enum { typedef enum {
SH_GLES2_SPEC, SH_GLES2_SPEC,
...@@ -210,6 +210,10 @@ typedef enum { ...@@ -210,6 +210,10 @@ typedef enum {
// This flag works around an issue in translating GLSL function texelFetchOffset on // This flag works around an issue in translating GLSL function texelFetchOffset on
// INTEL drivers. It works by translating texelFetchOffset into texelFetch. // INTEL drivers. It works by translating texelFetchOffset into texelFetch.
SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = 0x4000000, SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH = 0x4000000,
// This flag works around bug in Intel Mac drivers related to abs(i) where
// i is an integer.
SH_EMULATE_ABS_INT_FUNCTION = 0x8000000,
} ShCompileOptions; } ShCompileOptions;
// Defines alternate strategies for implementing array index clamping. // Defines alternate strategies for implementing array index clamping.
......
...@@ -11,6 +11,16 @@ ...@@ -11,6 +11,16 @@
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/VersionGLSL.h" #include "compiler/translator/VersionGLSL.h"
void InitBuiltInAbsFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu,
sh::GLenum shaderType)
{
if (shaderType == GL_VERTEX_SHADER)
{
const TType *int1 = TCache::getType(EbtInt);
emu->addEmulatedFunction(EOpAbs, int1, "int webgl_abs_emu(int x) { return x * sign(x); }");
}
}
void InitBuiltInFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu, sh::GLenum shaderType) void InitBuiltInFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu, sh::GLenum shaderType)
{ {
// we use macros here instead of function definitions to work around more GLSL // we use macros here instead of function definitions to work around more GLSL
......
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
class BuiltInFunctionEmulator; class BuiltInFunctionEmulator;
// //
// This works around bug in Intel Mac drivers.
//
void InitBuiltInAbsFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu,
sh::GLenum shaderType);
//
// This is only a workaround for OpenGL driver bugs, and isn't needed in general. // This is only a workaround for OpenGL driver bugs, and isn't needed in general.
// //
void InitBuiltInFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu, sh::GLenum shaderType); void InitBuiltInFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu, sh::GLenum shaderType);
......
...@@ -22,6 +22,10 @@ TranslatorGLSL::TranslatorGLSL(sh::GLenum type, ...@@ -22,6 +22,10 @@ TranslatorGLSL::TranslatorGLSL(sh::GLenum type,
void TranslatorGLSL::initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu, int compileOptions) void TranslatorGLSL::initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu, int compileOptions)
{ {
if (compileOptions & SH_EMULATE_ABS_INT_FUNCTION)
{
InitBuiltInAbsFunctionEmulatorForGLSLWorkarounds(emu, getShaderType());
}
if (compileOptions & SH_EMULATE_BUILT_IN_FUNCTIONS) if (compileOptions & SH_EMULATE_BUILT_IN_FUNCTIONS)
{ {
InitBuiltInFunctionEmulatorForGLSLWorkarounds(emu, getShaderType()); InitBuiltInFunctionEmulatorForGLSLWorkarounds(emu, getShaderType());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment