Mesa (master): mesa: Delay s_texcombine.c memory allocation until it's used .

Eric Anholt anholt at kemper.freedesktop.org
Sat Oct 1 23:31:46 PDT 2011


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

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Sep 22 12:52:43 2011 -0700

mesa: Delay s_texcombine.c memory allocation until it's used.

Generally we're using fragment programs in all our drivers, so wasting
4MB for code that's never called is pretty lame.  Reduces i965 memory
allocation for a short shader program from 21,932,128B to 17,737,816B.

---

 src/mesa/swrast/s_context.c    |   11 -----------
 src/mesa/swrast/s_texcombine.c |   20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index a4acac2..5287671 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -780,17 +780,6 @@ _swrast_CreateContext( struct gl_context *ctx )
    swrast->PointSpan.facing = 0;
    swrast->PointSpan.array = swrast->SpanArrays;
 
-   /* TexelBuffer is also global and normally shared by all SWspan instances;
-    * when running with multiple threads, create one per thread.
-    */
-   swrast->TexelBuffer = (GLfloat *) MALLOC(ctx->Const.MaxTextureImageUnits * maxThreads *
-                                           MAX_WIDTH * 4 * sizeof(GLfloat));
-   if (!swrast->TexelBuffer) {
-      FREE(swrast->SpanArrays);
-      FREE(swrast);
-      return GL_FALSE;
-   }
-
    init_program_native_limits(&ctx->Const.VertexProgram);
    init_program_native_limits(&ctx->Const.GeometryProgram);
    init_program_native_limits(&ctx->Const.FragmentProgram);
diff --git a/src/mesa/swrast/s_texcombine.c b/src/mesa/swrast/s_texcombine.c
index 6944edf..de15772 100644
--- a/src/mesa/swrast/s_texcombine.c
+++ b/src/mesa/swrast/s_texcombine.c
@@ -93,6 +93,26 @@ texture_combine( struct gl_context *ctx, GLuint unit, GLuint n,
    float4_array ccolor[4], rgba;
    GLuint i, term;
 
+   if (!swrast->TexelBuffer) {
+#ifdef _OPENMP
+      const GLint maxThreads = omp_get_max_threads();
+#else
+      const GLint maxThreads = 1;
+#endif
+
+      /* TexelBuffer is also global and normally shared by all SWspan
+       * instances; when running with multiple threads, create one per
+       * thread.
+       */
+      swrast->TexelBuffer =
+	 (GLfloat *) MALLOC(ctx->Const.MaxTextureImageUnits * maxThreads *
+			    MAX_WIDTH * 4 * sizeof(GLfloat));
+      if (!swrast->TexelBuffer) {
+	 _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture_combine");
+	 return;
+      }
+   }
+
    /* alloc temp pixel buffers */
    rgba = (float4_array) malloc(4 * n * sizeof(GLfloat));
    if (!rgba) {



More information about the mesa-commit mailing list