From 0dc00bf754efcb533d95432cef81650019484dfe Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Wed, 18 Mar 2015 14:55:25 -0400 Subject: [PATCH 1/3] fix glsl_test compile error with cmake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added #include to glsl_optimizer_tests.cpp to fix: tests/glsl_optimizer_tests.cpp:324:180: error: ‘system’ was not declared in this scope int res = system("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal metalTemp.metal -o metalTemp.o -std=ios-metal1.0 -Wno-parentheses-equality"); This was happening with cmake on both Linux (gcc) and OSX (clang), so perhaps it is something that is taken care of by Xcode. --- tests/glsl_optimizer_tests.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/glsl_optimizer_tests.cpp b/tests/glsl_optimizer_tests.cpp index 66153e74760..d7915be1bfa 100644 --- a/tests/glsl_optimizer_tests.cpp +++ b/tests/glsl_optimizer_tests.cpp @@ -1,8 +1,10 @@ +#include #include #include #include #include "../src/glsl/glsl_optimizer.h" + #define GL_GLEXT_PROTOTYPES 1 #if __linux__ From e480701dc39d88eff2aaa5ae03ae1941793a80a1 Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Wed, 18 Mar 2015 15:00:50 -0400 Subject: [PATCH 2/3] fix multiple definition of `_mesa_error_no_memory` link error removed the empty definition in standalone_scaffolding.h (but kept the declaration) and added specific definitions to the executables that need it (glslopt and glsl_test) This multiple definition was occurring in Linux and OSX with cmake. The changes build properly on Linux-cmake, OSX-cmake, and OSX-xcode. The tests pass on both OSX-builds. The Linux-cmake tests fail, but they fail before this commit. I do not have access to MSVC. --- contrib/glslopt/Main.cpp | 6 ++++++ src/glsl/standalone_scaffolding.cpp | 5 +---- tests/glsl_optimizer_tests.cpp | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/contrib/glslopt/Main.cpp b/contrib/glslopt/Main.cpp index 4f38dfe0dce..1a3a058d10b 100644 --- a/contrib/glslopt/Main.cpp +++ b/contrib/glslopt/Main.cpp @@ -4,6 +4,12 @@ #include #include "glsl_optimizer.h" +extern "C" void +_mesa_error_no_memory(const char *caller) +{ + fprintf(stderr, "Mesa error: out of memory in %s", caller); +} + static glslopt_ctx* gContext = 0; static int printhelp(const char* msg) diff --git a/src/glsl/standalone_scaffolding.cpp b/src/glsl/standalone_scaffolding.cpp index 6e7381193dd..596bd38ed20 100644 --- a/src/glsl/standalone_scaffolding.cpp +++ b/src/glsl/standalone_scaffolding.cpp @@ -50,10 +50,7 @@ _mesa_shader_debug(struct gl_context *, GLenum, GLuint *id, } extern "C" void -_mesa_error_no_memory(const char *caller) -{ -} - +_mesa_error_no_memory(const char *caller); struct gl_shader * _mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type) diff --git a/tests/glsl_optimizer_tests.cpp b/tests/glsl_optimizer_tests.cpp index d7915be1bfa..05681165148 100644 --- a/tests/glsl_optimizer_tests.cpp +++ b/tests/glsl_optimizer_tests.cpp @@ -1,9 +1,16 @@ +#include #include #include #include #include #include "../src/glsl/glsl_optimizer.h" +extern "C" void +_mesa_error_no_memory(const char *caller) +{ + fprintf(stderr, "Mesa error: out of memory in %s", caller); +} + #define GL_GLEXT_PROTOTYPES 1 From 9bffe9de3d58912edc1766b7d3da8780540c3d91 Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Thu, 19 Mar 2015 03:10:53 -0400 Subject: [PATCH 3/3] 44: fix optimizer hangs on gcc builds For some reason gcc (versions 4.6 and 4.8) optimizes out the "Trim out variables" loop in `ir_array_reference_visitor::get_split_list`, even we don't want it too. If that loop disappears, then the variables are never considered split and not removed from the list, so the optimization continues indefinitely. Placing a memory fence in the loop prevents it from being optimized out; this is done just with gcc. --- src/glsl/opt_array_splitting.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/glsl/opt_array_splitting.cpp b/src/glsl/opt_array_splitting.cpp index cfd1ee32d25..e0ecc63b72d 100644 --- a/src/glsl/opt_array_splitting.cpp +++ b/src/glsl/opt_array_splitting.cpp @@ -228,6 +228,11 @@ ir_array_reference_visitor::get_split_list(exec_list *instructions, /* Trim out variables we found that we can't split. */ foreach_in_list_safe(variable_entry, entry, &variable_list) { +#ifdef __GNUC__ + // without this memory fence (or something like it), + // gcc will optimize out this loop. See issue #44 + __asm__("":::"memory"); +#endif if (debug) { printf("array %s@%p: decl %d, split %d\n", entry->var->name, (void *) entry->var, entry->declaration,