Use non-conformant transcendentals for Chromium
Chromium's blink_web_tests fail when using the new Vulkan and OpenGL
conformant implementation of exp2(), due to comparing results with
"golden" images produced by the previous implementation. Work around it
by selectively using the old broken version of exp2().
Bug: chromium:1299047
Change-Id: I8e60e6f415c747f715aec13b748fc82c2550f3d0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/63128
Reviewed-by: Alexis Hétu <sugoi@google.com>
Commit-Queue: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/ShaderCore.cpp b/src/Pipeline/ShaderCore.cpp
index 8245008..ed11d1a 100644
--- a/src/Pipeline/ShaderCore.cpp
+++ b/src/Pipeline/ShaderCore.cpp
@@ -19,6 +19,11 @@
#include <limits.h>
+// TODO(chromium:1299047)
+#ifndef SWIFTSHADER_LEGACY_TRANSCENDENTALS
+# define SWIFTSHADER_LEGACY_TRANSCENDENTALS false
+#endif
+
namespace sw {
Vector4s::Vector4s()
@@ -310,6 +315,23 @@
return As<Float4>((precision_loss & As<Int4>(-atan2_theta)) | (~precision_loss & As<Int4>(theta))); // FIXME: Vector select
}
+// TODO(chromium:1299047)
+Float4 Exp2_legacy(RValue<Float4> x0)
+{
+ Int4 i = RoundInt(x0 - Float4(0.5f));
+ Float4 ii = As<Float4>((i + Int4(127)) << 23);
+
+ Float4 f = x0 - Float4(i);
+ Float4 ff = As<Float4>(Int4(0x3AF61905));
+ ff = ff * f + As<Float4>(Int4(0x3C134806));
+ ff = ff * f + As<Float4>(Int4(0x3D64AA23));
+ ff = ff * f + As<Float4>(Int4(0x3E75EAD4));
+ ff = ff * f + As<Float4>(Int4(0x3F31727B));
+ ff = ff * f + Float4(1.0f);
+
+ return ii * ff;
+}
+
Float4 Exp2(RValue<Float4> x)
{
// This implementation is based on 2^(i + f) = 2^i * 2^f,
@@ -322,6 +344,11 @@
x0 = Min(x0, As<Float4>(Int4(0x4300FFFF))); // 128.999985
x0 = Max(x0, As<Float4>(Int4(0xC2FDFFFF))); // -126.999992
+ if(SWIFTSHADER_LEGACY_TRANSCENDENTALS) // TODO(chromium:1299047)
+ {
+ return Exp2_legacy(x0);
+ }
+
Float4 xi = Floor(x0);
Int4 i = Int4(xi);
Float4 ii = As<Float4>((i + Int4(127)) << 23); // Add single-precision bias, and shift into exponent.
diff --git a/src/Vulkan/BUILD.gn b/src/Vulkan/BUILD.gn
index 13b19ca..71f9779 100644
--- a/src/Vulkan/BUILD.gn
+++ b/src/Vulkan/BUILD.gn
@@ -56,6 +56,7 @@
defines += [
"SWIFTSHADER_ENABLE_ASTC", # TODO(b/150130101)
+ "SWIFTSHADER_LEGACY_TRANSCENDENTALS=true", # TODO(chromium:1299047)
]
}