Mesa (10.0): swrast: fix delayed texel buffer allocation regression for OpenMP

Carl Worth cworth at kemper.freedesktop.org
Thu Jan 9 20:57:13 UTC 2014


Module: Mesa
Branch: 10.0
Commit: 2b205f2864e14914c712aa607353e7e541cd250f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2b205f2864e14914c712aa607353e7e541cd250f

Author: Andreas Fänger <a.faenger at e-sign.com>
Date:   Tue Jan  7 03:10:00 2014 -0700

swrast: fix delayed texel buffer allocation regression for OpenMP

Commit 9119269ca14ed42b51c7d8e2e662500311b29fa3 moved the texel
buffer allocation to _swrast_texture_span(), however, when compiled
with OpenMP support this code already runs multi-threaded so a
critical section is required to prevent multiple allocations and
rendering errors.

Cc: "10.0" <mesa-stable at lists.freedesktop.org>
Reviewed-by: Brian Paul <brianp at vmware.com>
(cherry picked from commit 2a0fb946e147f5482c93702fbf46ffdf5208f57c)

---

 src/mesa/swrast/s_texcombine.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c
index 7e07f4f..297491e 100644
--- a/src/mesa/swrast/s_texcombine.c
+++ b/src/mesa/swrast/s_texcombine.c
@@ -602,6 +602,14 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span )
    if (!swrast->TexelBuffer) {
 #ifdef _OPENMP
       const GLint maxThreads = omp_get_max_threads();
+
+      /* TexelBuffer memory allocation needs to be done in a critical section
+       * as this code runs in a parallel loop.
+       * When entering the section, first check if TexelBuffer has been
+       * initialized already by another thread while this thread was waiting.
+       */
+      #pragma omp critical
+      if (!swrast->TexelBuffer) {
 #else
       const GLint maxThreads = 1;
 #endif
@@ -613,6 +621,10 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span )
       swrast->TexelBuffer =
 	 malloc(ctx->Const.FragmentProgram.MaxTextureImageUnits * maxThreads *
 			    SWRAST_MAX_WIDTH * 4 * sizeof(GLfloat));
+#ifdef _OPENMP
+      } /* critical section */
+#endif
+
       if (!swrast->TexelBuffer) {
 	 _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
 	 return;




More information about the mesa-commit mailing list