From 80147d11c88807434f3fec540670ff0b73590095 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Tue, 30 Apr 2019 16:21:24 -0400 Subject: [PATCH] Add support for dynamically allocate initial stack for Angle By updating YYLTYPE_IS_TRIVIAL to true, YYSTACK_RELOCATE can be enabled, so we can dynamically allocate stack size based on needs. BUG=angleproject:3028 Change-Id: I1b9cc0768cd0c6955589695e703595c56d43f24a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1593954 Commit-Queue: Yi Xu Reviewed-by: Geoff Lang --- src/compiler/translator/glslang.y | 1 + src/compiler/translator/glslang_tab.cpp | 1 + src/tests/gl_tests/GLSLTest.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/compiler/translator/glslang.y b/src/compiler/translator/glslang.y index 5d113e39a..fb3882818 100644 --- a/src/compiler/translator/glslang.y +++ b/src/compiler/translator/glslang.y @@ -58,6 +58,7 @@ using namespace sh; %code requires { #define YYLTYPE TSourceLoc #define YYLTYPE_IS_DECLARED 1 +#define YYLTYPE_IS_TRIVIAL 1 } %union { diff --git a/src/compiler/translator/glslang_tab.cpp b/src/compiler/translator/glslang_tab.cpp index a60203b85..e0926567a 100644 --- a/src/compiler/translator/glslang_tab.cpp +++ b/src/compiler/translator/glslang_tab.cpp @@ -129,6 +129,7 @@ extern int yydebug; #define YYLTYPE TSourceLoc #define YYLTYPE_IS_DECLARED 1 +#define YYLTYPE_IS_TRIVIAL 1 diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp index 1444d4624..7c5c62de6 100644 --- a/src/tests/gl_tests/GLSLTest.cpp +++ b/src/tests/gl_tests/GLSLTest.cpp @@ -508,6 +508,22 @@ class GLSLTest_ES31 : public GLSLTest void SetUp() override { ANGLETest::SetUp(); } }; +std::string BuillBigInitialStackShader(int length) +{ + std::string result; + result += "void main() { \n"; + for (int i = 0; i < length; i++) + { + result += " if (true) { \n"; + } + result += " int temp; \n"; + for (int i = 0; i <= length; i++) + { + result += "} \n"; + } + return result; +} + TEST_P(GLSLTest, NamelessScopedStructs) { constexpr char kFS[] = R"(precision mediump float; @@ -5518,6 +5534,15 @@ TEST_P(GLSLTest, FragData) EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); } +// Test angle can handle big initial stack size with dynamic stack allocation. +TEST_P(GLSLTest, MemoryExhaustedTest) +{ + ANGLE_SKIP_TEST_IF(IsD3D11_FL93()); + GLuint program = + CompileProgram(essl1_shaders::vs::Simple(), BuillBigInitialStackShader(36).c_str()); + EXPECT_NE(0u, program); +} + // Use this to select which configurations (e.g. which renderer, which GLES major version) these // tests should be run against. ANGLE_INSTANTIATE_TEST(GLSLTest,