Commit 37385e11 by Olli Etuaho Committed by Commit Bot

Emulate tanh on HLSL

This ensures mathematically correct results on large inputs. BUG=chromium:795269 BUG=angleproject:1093 TEST=dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh* Change-Id: Id5ba05a3284e51a34f196b419abef0f4a41551e0 Reviewed-on: https://chromium-review.googlesource.com/832463Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent d4529f30
......@@ -1472,8 +1472,6 @@ bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
outputTriplet(out, visit, "cosh(", "", ")");
break;
case EOpTanh:
outputTriplet(out, visit, "tanh(", "", ")");
break;
case EOpAsinh:
case EOpAcosh:
case EOpAtanh:
......
......@@ -1378,5 +1378,48 @@
"borrow = uint4(x < y);",
"return x - y;"
]
},
{
"comment":[
"We emulate tanh just to avoid overflow on large arguments."
],
"op":"tanh",
"return_type":"float",
"args":[
"float x"
],
"body":[
"return (abs(x) > 15.0) ? sign(x) : tanh(x);"
]
},
{
"op":"tanh",
"return_type":"float2",
"args":[
"float2 x"
],
"body":[
"return (abs(x) > 15.0) ? sign(x) : tanh(x);"
]
},
{
"op":"tanh",
"return_type":"float3",
"args":[
"float3 x"
],
"body":[
"return (abs(x) > 15.0) ? sign(x) : tanh(x);"
]
},
{
"op":"tanh",
"return_type":"float4",
"args":[
"float4 x"
],
"body":[
"return (abs(x) > 15.0) ? sign(x) : tanh(x);"
]
}
]
......@@ -840,6 +840,27 @@ constexpr FunctionPair g_hlslFunctions[] = {
" borrow = uint4(x < y);\n"
" return x - y;\n"
"}\n"},
// We emulate tanh just to avoid overflow on large arguments.
{{EOpTanh, ParamType::Float1},
"float tanh_emu(float x)\n"
"{\n"
" return (abs(x) > 15.0) ? sign(x) : tanh(x);\n"
"}\n"},
{{EOpTanh, ParamType::Float2},
"float2 tanh_emu(float2 x)\n"
"{\n"
" return (abs(x) > 15.0) ? sign(x) : tanh(x);\n"
"}\n"},
{{EOpTanh, ParamType::Float3},
"float3 tanh_emu(float3 x)\n"
"{\n"
" return (abs(x) > 15.0) ? sign(x) : tanh(x);\n"
"}\n"},
{{EOpTanh, ParamType::Float4},
"float4 tanh_emu(float4 x)\n"
"{\n"
" return (abs(x) > 15.0) ? sign(x) : tanh(x);\n"
"}\n"},
};
} // anonymous namespace
......
......@@ -108,14 +108,6 @@
// Windows only failure
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.scalar = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec2 = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec3 = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_vertex.vec4 = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.scalar = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec2 = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec3 = FAIL
1093 WIN : dEQP-GLES3.functional.shaders.builtin_functions.precision.tanh.highp_fragment.vec4 = FAIL
1092 WIN : dEQP-GLES3.functional.shaders.texture_functions.textureoffset.sampler3d_fixed_fragment = FAIL
1092 WIN : dEQP-GLES3.functional.shaders.texture_functions.textureoffset.sampler3d_float_fragment = FAIL
1092 WIN : dEQP-GLES3.functional.shaders.texture_functions.textureprojoffset.sampler3d_fixed_fragment = FAIL
......
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