aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/swrast/s_texcombine.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/swrast/s_texcombine.c')
-rw-r--r--mesalib/src/mesa/swrast/s_texcombine.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/mesalib/src/mesa/swrast/s_texcombine.c b/mesalib/src/mesa/swrast/s_texcombine.c
index 7e07f4f8a..32d7c0944 100644
--- a/mesalib/src/mesa/swrast/s_texcombine.c
+++ b/mesalib/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
@@ -611,8 +619,12 @@ _swrast_texture_span( struct gl_context *ctx, SWspan *span )
* thread.
*/
swrast->TexelBuffer =
- malloc(ctx->Const.FragmentProgram.MaxTextureImageUnits * maxThreads *
+ malloc(ctx->Const.Program[MESA_SHADER_FRAGMENT].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;