aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoff Lang <geofflang@chromium.org>2024-04-29 14:35:42 -0400
committerAngle LUCI CQ <angle-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-04-29 22:47:55 +0000
commitb839e05ba7e3775b3e501a15d2414e676b87191d (patch)
tree894fd37abd4c4c8683ec7c421fa881b63105a2b4
parent1064b38d8d7d2079d11ae35aeaf5b46e7e810fb5 (diff)
downloadangle-b839e05ba7e3775b3e501a15d2414e676b87191d.tar.gz
GLSL: Hardcode emulated atan functions
These emulated atan functions are generated for every compiled shader, the string generation is particularly costly for small shaders (>30% of total compile time). Instead just hardcode the emualted functions, there are only 4. Bug: angleproject:8434 Change-Id: I3f8b7cc9709ca132fae19953c23d02e54538d4e7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5498516 Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Geoff Lang <geofflang@chromium.org>
-rw-r--r--src/compiler/translator/glsl/BuiltInFunctionEmulatorGLSL.cpp49
1 files changed, 22 insertions, 27 deletions
diff --git a/src/compiler/translator/glsl/BuiltInFunctionEmulatorGLSL.cpp b/src/compiler/translator/glsl/BuiltInFunctionEmulatorGLSL.cpp
index 622566d542..8835dc311f 100644
--- a/src/compiler/translator/glsl/BuiltInFunctionEmulatorGLSL.cpp
+++ b/src/compiler/translator/glsl/BuiltInFunctionEmulatorGLSL.cpp
@@ -80,33 +80,28 @@ void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *
" else if (x < 0.0 && y < 0.0) return atan(y / x) - 3.14159265;\n"
" else return 1.57079632 * sign(y);\n"
"}\n");
- static const std::array<TSymbolUniqueId, 4> ids = {
- BuiltInId::atan_Float1_Float1,
- BuiltInId::atan_Float2_Float2,
- BuiltInId::atan_Float3_Float3,
- BuiltInId::atan_Float4_Float4,
- };
- for (int dim = 2; dim <= 4; ++dim)
- {
- std::stringstream ss = sh::InitializeStream<std::stringstream>();
- ss << "emu_precision vec" << dim << " atan_emu(emu_precision vec" << dim
- << " y, emu_precision vec" << dim << " x)\n"
- << "{\n"
- " return vec"
- << dim << "(";
- for (int i = 0; i < dim; ++i)
- {
- ss << "atan_emu(y[" << i << "], x[" << i << "])";
- if (i < dim - 1)
- {
- ss << ", ";
- }
- }
- ss << ");\n"
- "}\n";
- emu->addEmulatedFunctionWithDependency(BuiltInId::atan_Float1_Float1, ids[dim - 1],
- ss.str().c_str());
- }
+
+ emu->addEmulatedFunctionWithDependency(
+ BuiltInId::atan_Float1_Float1, BuiltInId::atan_Float2_Float2,
+ "emu_precision vec2 atan_emu(emu_precision vec2 y, emu_precision vec2 x)\n"
+ "{\n"
+ " return vec2(atan_emu(y[0], x[0]), atan_emu(y[1], x[1]));\n"
+ "}\n");
+
+ emu->addEmulatedFunctionWithDependency(
+ BuiltInId::atan_Float1_Float1, BuiltInId::atan_Float3_Float3,
+ "emu_precision vec3 atan_emu(emu_precision vec3 y, emu_precision vec3 x)\n"
+ "{\n"
+ " return vec3(atan_emu(y[0], x[0]), atan_emu(y[1], x[1]), atan_emu(y[2], x[2]));\n"
+ "}\n");
+
+ emu->addEmulatedFunctionWithDependency(
+ BuiltInId::atan_Float1_Float1, BuiltInId::atan_Float4_Float4,
+ "emu_precision vec4 atan_emu(emu_precision vec4 y, emu_precision vec4 x)\n"
+ "{\n"
+ " return vec4(atan_emu(y[0], x[0]), atan_emu(y[1], x[1]), atan_emu(y[2], x[2]), "
+ "atan_emu(y[3], x[3]))\n;"
+ "}\n");
}
// Emulate built-in functions missing from GLSL 1.30 and higher