Mesa (master): glsl: use -O1 optimization for builtin_functions.cpp with MinGW

Brian Paul brianp at kemper.freedesktop.org
Fri Mar 31 19:40:33 UTC 2017


Module: Mesa
Branch: master
Commit: 2936f5c37eba10d68ac27cd7b77a633a127a1688
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2936f5c37eba10d68ac27cd7b77a633a127a1688

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Mar 30 21:14:08 2017 -0600

glsl: use -O1 optimization for builtin_functions.cpp with MinGW

Some versions of MinGW-w64 such as 5.3.1 and 6.2.0 produce bad code
with -O2 or -O3 causing a random driver crash when running programs
that use GLSL.  Most Mesa demos in the glsl/ directory trigger the
bug, but not the fragcoord.c test.

Use a #pragma to force -O1 for this file for later MinGW versions.
Luckily, this is basically one-time setup code.  I suspect the bug
is related to the sheer size of this file.

This should let us move to newer versions of MinGW-w64 for Mesa.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

---

 src/compiler/glsl/builtin_functions.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 683217d7a3..b2fcdf37e0 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -53,6 +53,26 @@
  *    name and parameters.
  */
 
+
+/**
+ * Unfortunately, some versions of MinGW produce bad code if this file
+ * is compiled with -O2 or -O3.  The resulting driver will crash in random
+ * places if the app uses GLSL.
+ * The work-around is to disable optimizations for just this file.  Luckily,
+ * this code is basically just executed once.
+ *
+ * MinGW 4.6.3 (in Ubuntu 13.10) does not have this bug.
+ * MinGW 5.3.1 (in Ubuntu 16.04) definitely has this bug.
+ * MinGW 6.2.0 (in Ubuntu 16.10) definitely has this bug.
+ * MinGW x.y.z - don't know.  Assume versions after 4.6.x are buggy
+ */
+
+#if defined(__MINGW32__) && ((__GNUC__ * 100) + __GNUC_MINOR >= 407)
+#warning "disabling optimizations for this file to work around compiler bug"
+#pragma GCC optimize("O1")
+#endif
+
+
 #include <stdarg.h>
 #include <stdio.h>
 #include "main/core.h" /* for struct gl_shader */




More information about the mesa-commit mailing list