mesa: Branch 'glsl-compiler-1' - 15 commits

Brian Paul brianp at kemper.freedesktop.org
Tue Mar 13 22:32:57 UTC 2007


 docs/relnotes-6.5.3.html                      |   16 +++-
 src/mesa/main/pixel.c                         |   12 +--
 src/mesa/main/shaders.c                       |   13 ++--
 src/mesa/main/texstate.c                      |   20 ++----
 src/mesa/shader/prog_parameter.c              |    1 
 src/mesa/shader/shader_api.c                  |   84 ++++++++++++--------------
 src/mesa/shader/slang/library/slang_core.gc   |    2 
 src/mesa/shader/slang/library/slang_core_gc.h |    4 -
 src/mesa/shader/slang/slang_codegen.c         |   18 ++---
 src/mesa/shader/slang/slang_emit.c            |   27 +++++---
 src/mesa/shader/slang/slang_print.c           |   21 ++++--
 src/mesa/shader/slang/slang_simplify.c        |   28 +++++++-
 src/mesa/swrast/s_fragprog.c                  |    9 ++
 src/mesa/swrast/s_span.c                      |   32 ++++++---
 src/mesa/swrast/s_span.h                      |    2 
 15 files changed, 173 insertions(+), 116 deletions(-)

New commits:
diff-tree 98650bdf897ee8dc1bcf32e28832c1d54acd0d79 (from 5186529e57bfab6d70a94329e8265e64095b328e)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 16:32:48 2007 -0600

    fix a number of issues in _mesa_uniform()

diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index 271464e..b916e75 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -886,7 +886,7 @@ _mesa_uniform(GLcontext *ctx, GLint loca
               const GLvoid *values, GLenum type)
 {
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
-   GLfloat *uniformVal;
+   GLint elems, i, k;
 
    if (!shProg || !shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(program not linked)");
@@ -912,51 +912,49 @@ _mesa_uniform(GLcontext *ctx, GLint loca
       }
    }
 
-   uniformVal = shProg->Uniforms->ParameterValues[location];
+   switch (type) {
+   case GL_FLOAT:
+   case GL_INT:
+      elems = 1;
+      break;
+   case GL_FLOAT_VEC2:
+   case GL_INT_VEC2:
+      elems = 2;
+      break;
+   case GL_FLOAT_VEC3:
+   case GL_INT_VEC3:
+      elems = 3;
+      break;
+   case GL_FLOAT_VEC4:
+   case GL_INT_VEC4:
+      elems = 4;
+      break;
+   default:
+      _mesa_problem(ctx, "Invalid type in _mesa_uniform");
+      return;
+   }
 
-   /* XXX obey 'count' parameter! */
+   if (count * elems > shProg->Uniforms->Parameters[location].Size) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(count too large)");
+      return;
+   }
 
-   if (type == GL_INT ||
-       type == GL_INT_VEC2 ||
-       type == GL_INT_VEC3 ||
-       type == GL_INT_VEC4) {
-      const GLint *iValues = (const GLint *) values;
-      switch (type) {
-      case GL_INT_VEC4:
-         uniformVal[3] = (GLfloat) iValues[3];
-         /* fall-through */
-      case GL_INT_VEC3:
-         uniformVal[2] = (GLfloat) iValues[2];
-         /* fall-through */
-      case GL_INT_VEC2:
-         uniformVal[1] = (GLfloat) iValues[1];
-         /* fall-through */
-      case GL_INT:
-         uniformVal[0] = (GLfloat) iValues[0];
-         break;
-      default:
-         _mesa_problem(ctx, "Invalid type in _mesa_uniform");
-         return;
+   for (k = 0; k < count; k++) {
+      GLfloat *uniformVal = shProg->Uniforms->ParameterValues[location + k];
+      if (type == GL_INT ||
+          type == GL_INT_VEC2 ||
+          type == GL_INT_VEC3 ||
+          type == GL_INT_VEC4) {
+         const GLint *iValues = (const GLint *) values;
+         for (i = 0; i < elems; i++) {
+            uniformVal[i] = (GLfloat) iValues[i];
+         }
       }
-   }
-   else {
-      const GLfloat *fValues = (const GLfloat *) values;
-      switch (type) {
-      case GL_FLOAT_VEC4:
-         uniformVal[3] = fValues[3];
-         /* fall-through */
-      case GL_FLOAT_VEC3:
-         uniformVal[2] = fValues[2];
-         /* fall-through */
-      case GL_FLOAT_VEC2:
-         uniformVal[1] = fValues[1];
-         /* fall-through */
-      case GL_FLOAT:
-         uniformVal[0] = fValues[0];
-         break;
-      default:
-         _mesa_problem(ctx, "Invalid type in _mesa_uniform");
-         return;
+      else {
+         const GLfloat *fValues = (const GLfloat *) values;
+         for (i = 0; i < elems; i++) {
+            uniformVal[i] = fValues[i];
+         }
       }
    }
 
diff-tree 5186529e57bfab6d70a94329e8265e64095b328e (from fdf513e07ab5d157dab7b3c776bc75b064cdb2a9)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 16:31:30 2007 -0600

    remove bogus assertion

diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index 14b272c..4633015 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -88,7 +88,6 @@ _mesa_add_parameter(struct gl_program_pa
    const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */
 
    assert(size > 0);
-   assert(size <= 16);  /* XXX anything larger than a matrix??? */
 
    if (oldNum + sz4 > paramList->Size) {
       /* Need to grow the parameter list array (alloc some extra) */
diff-tree fdf513e07ab5d157dab7b3c776bc75b064cdb2a9 (from 8d9db3dd03b3ec423560b46831071405cb4f6f48)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 16:12:23 2007 -0600

    document some bug fixes, lots of new features

diff --git a/docs/relnotes-6.5.3.html b/docs/relnotes-6.5.3.html
index 86e23d6..5bde4e0 100644
--- a/docs/relnotes-6.5.3.html
+++ b/docs/relnotes-6.5.3.html
@@ -11,8 +11,7 @@
 <H1>Mesa 6.5.3 Release Notes / (in progress)</H1>
 
 <p>
-Mesa 6.5.3 is a 6.5 follow-on development release mostly consisting of
-bug fixes</a>.
+Mesa 6.5.3 is a 6.5 follow-on development release with many internal changes.
 </p>
 
 
@@ -24,6 +23,10 @@ TBD
 
 <h2>New features</h2>
 <ul>
+<li>OpenGL 2.0 support.
+<li>Entirely new Shading Language code generator.
+<li>Much faster software execution of vertex, fragment shaders.
+<li>New vertex buffer object infrastructure (replaces old array_cache code).
 <li>Updated glext.h file (version 39)
 <li>Updated glxext.h file (version 18)
 </ul>
@@ -33,12 +36,16 @@ TBD
 <li>Fog was errantly applied when a fragment shader was enabled (bug 9346)
 <li>glPush/PopClientAttrib didn't handle VBO bindings correctly (bug 9445)
 <li>With 32-bit Z buffer, the fragment Z of lines and points was sometimes wrong.
+<li>GL_POST_CONVOLUTION_ALPHA_BIAS/SCALE was broken.
+<li>GL_MAX_DRAWBUFFERS is now 4 (software rendering) so
+    "multiple render targets" are really supported.
 </ul>
 
 
 <h2>Internal code changes</h2>
 
 <ul>
+<li>Massive changes to the Shading Language compiler.
 <li>The _MaintainTnlProgram, _MaintainTexEnvProgram, _TexEnvProgram and
 _TnlProgram fields have been moved.
 <li>The ctx->FragmentProgram._Active field has been removed.
@@ -52,7 +59,6 @@ fixed-function program.
 <h2>To Do (someday) items</h2>
 <ul>
 <li>Switch to freeglut
-<li>Increase MAX_DRAWBUFFERS
 <li>Fix linux-glide target/driver.
 <li>Improved lambda and derivative calculation for frag progs.
 </ul>
@@ -64,8 +70,8 @@ fixed-function program.
 Driver			Status
 ----------------------	----------------------
 DRI drivers		varies with the driver
-XMesa/GLX (on Xlib)	implements OpenGL 1.5
-OSMesa (off-screen)	implements OpenGL 1.5
+XMesa/GLX (on Xlib)	implements OpenGL 2.0
+OSMesa (off-screen)	implements OpenGL 2.0
 Glide (3dfx Voodoo1/2)	implements OpenGL 1.3
 SVGA			implements OpenGL 1.3
 Wind River UGL		implements OpenGL 1.3
diff-tree 8d9db3dd03b3ec423560b46831071405cb4f6f48 (from fd08463dea8fd2e8d805d66488368830dbe53264)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 16:07:04 2007 -0600

    fix ctx->Pixel.PostConvolutionScale/Bias subscript bugs

diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c
index 4e47cdb..de5c7fc 100644
--- a/src/mesa/main/pixel.c
+++ b/src/mesa/main/pixel.c
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.2
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -1040,16 +1040,16 @@ _mesa_PixelTransferf( GLenum pname, GLfl
          ctx->Pixel.PostConvolutionBias[2] = param;
 	 break;
       case GL_POST_CONVOLUTION_ALPHA_SCALE:
-         if (ctx->Pixel.PostConvolutionScale[2] == param)
+         if (ctx->Pixel.PostConvolutionScale[3] == param)
 	    return;
 	 FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.PostConvolutionScale[2] = param;
+         ctx->Pixel.PostConvolutionScale[3] = param;
 	 break;
       case GL_POST_CONVOLUTION_ALPHA_BIAS:
-         if (ctx->Pixel.PostConvolutionBias[2] == param)
+         if (ctx->Pixel.PostConvolutionBias[3] == param)
 	    return;
 	 FLUSH_VERTICES(ctx, _NEW_PIXEL);
-         ctx->Pixel.PostConvolutionBias[2] = param;
+         ctx->Pixel.PostConvolutionBias[3] = param;
 	 break;
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" );
diff-tree fd08463dea8fd2e8d805d66488368830dbe53264 (from c7b2cce4186974adb86f14c4c62c43fc0332d6f4)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 15:58:40 2007 -0600

    Check for, simplify vec2/3/4(x).  Only do call adapting for constructors.

diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c
index 87b1178..21d004d 100644
--- a/src/mesa/shader/slang/slang_simplify.c
+++ b/src/mesa/shader/slang/slang_simplify.c
@@ -263,8 +263,6 @@ _slang_simplify(slang_operation *oper,
       /* vec2(flt, flt) constructor */
       if (oper->type == SLANG_OPER_CALL) {
          if (strcmp((char *) oper->a_id, "vec2") == 0) {
-            printf("SIMPLIFY vec2 constructor scope = %p\n",
-                   (void*) oper->locals);
             oper->literal[0] = oper->children[0].literal[0];
             oper->literal[1] = oper->children[1].literal[0];
             oper->literal[2] = oper->literal[1];
@@ -277,6 +275,26 @@ _slang_simplify(slang_operation *oper,
          }
       }
    }
+
+   if (oper->num_children == 1 && isFloat[0]) {
+      /* vec2/3/4(flt, flt) constructor */
+      if (oper->type == SLANG_OPER_CALL) {
+         const char *func = (const char *) oper->a_id;
+         if (strncmp(func, "vec", 3) == 0 && func[3] >= '2' && func[3] <= '4') {
+            oper->literal[0] =
+            oper->literal[1] =
+            oper->literal[2] =
+            oper->literal[3] = oper->children[0].literal[0];
+            oper->literal_size = func[3] - '0';
+            assert(oper->literal_size >= 2);
+            assert(oper->literal_size <= 4);
+            slang_operation_destruct(oper); /* XXX oper->locals goes NULL! */
+            oper->type = SLANG_OPER_LITERAL_FLOAT;
+            assert(oper->num_children == 0);
+            return;
+         }
+      }
+   }
 }
 
 
@@ -302,6 +320,10 @@ _slang_adapt_call(slang_operation *callO
    if (dbg) printf("Adapt %d args to %d parameters\n",
                    callOper->num_children, numParams);
 
+   /* Only try adapting for constructors */
+   if (fun->kind != SLANG_FUNC_CONSTRUCTOR)
+      return GL_FALSE;
+
    if (callOper->num_children != numParams) {
       /* number of arguments doesn't match number of parameters */
 
@@ -406,7 +428,7 @@ _slang_adapt_call(slang_operation *callO
          slang_operation *child = slang_operation_new(1);
 
          slang_operation_copy(child, &callOper->children[i]);
-         child->locals->outer_scope = callOper->locals;
+         child->locals->outer_scope = callOper->children[i].locals;
 
          callOper->children[i].type = SLANG_OPER_CALL;
          callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName);
diff-tree c7b2cce4186974adb86f14c4c62c43fc0332d6f4 (from 000b2899b92b800f962a52243aa1ca775dd353fa)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 15:57:09 2007 -0600

    improve literal printing

diff --git a/src/mesa/shader/slang/slang_print.c b/src/mesa/shader/slang/slang_print.c
index c377759..4be9041 100644
--- a/src/mesa/shader/slang/slang_print.c
+++ b/src/mesa/shader/slang/slang_print.c
@@ -387,22 +387,27 @@ slang_print_tree(const slang_operation *
 
    case SLANG_OPER_LITERAL_BOOL:
       spaces(indent);
-      /*printf("SLANG_OPER_LITERAL_BOOL\n");*/
-      printf("%s\n", op->literal[0] ? "TRUE" : "FALSE");
+      printf("LITERAL (");
+      for (i = 0; i < op->literal_size; i++)
+         printf("%s ", op->literal[0] ? "TRUE" : "FALSE");
+      printf(")\n");
+
       break;
 
    case SLANG_OPER_LITERAL_INT:
       spaces(indent);
-      /*printf("SLANG_OPER_LITERAL_INT\n");*/
-      printf("(%d %d %d %d)\n", (int) op->literal[0], (int) op->literal[1],
-             (int) op->literal[2], (int) op->literal[3]);
+      printf("LITERAL (");
+      for (i = 0; i < op->literal_size; i++)
+         printf("%d ", (int) op->literal[i]);
+      printf(")\n");
       break;
 
    case SLANG_OPER_LITERAL_FLOAT:
       spaces(indent);
-      /*printf("SLANG_OPER_LITERAL_FLOAT\n");*/
-      printf("(%f %f %f %f)\n", op->literal[0], op->literal[1], op->literal[2],
-             op->literal[3]);
+      printf("LITERAL (");
+      for (i = 0; i < op->literal_size; i++)
+         printf("%f ", op->literal[i]);
+      printf(")\n");
       break;
 
    case SLANG_OPER_IDENTIFIER:
diff-tree 000b2899b92b800f962a52243aa1ca775dd353fa (from a49a865cf53dad5734ca7019406e4ce89702a08f)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 15:55:54 2007 -0600

    disable some debug output

diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 71741fb..7353b98 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -1612,8 +1612,8 @@ _slang_emit_code(slang_ir_node *n, slang
    }
    success = GL_TRUE;
 
-   printf("*********** End generate code (%u inst):\n", prog->NumInstructions);
 #if 0
+   printf("*********** End emit code (%u inst):\n", prog->NumInstructions);
    _mesa_print_program(prog);
    _mesa_print_program_parameters(ctx,prog);
 #endif
diff-tree a49a865cf53dad5734ca7019406e4ce89702a08f (from 948c60badc52cf938766964dc90ce574f885b23d)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 15:55:41 2007 -0600

    better error msg for undefined function, disable some debug output

diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 5b5de07..45868c7 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1074,7 +1074,7 @@ _slang_gen_function_call(slang_assemble_
    slang_operation_construct(oper);
    slang_operation_copy(oper, inlined);
 #else
-   *oper = *inlined;
+   *oper = *inlined;  /* XXX slang_operation_copy() */
 #endif
 
 
@@ -1280,7 +1280,7 @@ _slang_gen_function_call_name(slang_asse
        */
       fun = _slang_first_function(A->space.funcs, name);
       if (!_slang_adapt_call(oper, fun, &A->space, A->atoms, A->log)) {
-         slang_info_log_error(A->log, "Undefined function '%s'", name);
+         slang_info_log_error(A->log, "Function '%s' not found (check argument types)", name);
          return NULL;
       }
       assert(fun);
@@ -2739,10 +2739,8 @@ _slang_codegen_function(slang_assemble_c
       return GL_TRUE;  /* not an error */
    }
 
-#if 1
-   printf("\n*********** codegen_function %s\n", (char *) fun->header.a_name);
-#endif
 #if 0
+   printf("\n*********** codegen_function %s\n", (char *) fun->header.a_name);
    slang_print_function(fun, 1);
 #endif
 
@@ -2754,6 +2752,11 @@ _slang_codegen_function(slang_assemble_c
    /* fold constant expressions, etc. */
    _slang_simplify(fun->body, &A->space, A->atoms);
 
+#if 0
+   printf("\n*********** simplified %s\n", (char *) fun->header.a_name);
+   slang_print_function(fun, 1);
+#endif
+
    /* Create an end-of-function label */
    A->curFuncEndLabel = _slang_label_new("__endOfFunc__main");
 
@@ -2787,7 +2790,7 @@ _slang_codegen_function(slang_assemble_c
    printf("************* IR for %s *******\n", (char*)fun->header.a_name);
    slang_print_ir(n, 0);
 #endif
-#if 1
+#if 0
    printf("************* End codegen function ************\n\n");
 #endif
 
diff-tree 948c60badc52cf938766964dc90ce574f885b23d (from d8070889d73479d9dbef27ccf1ed5d26fc8760e5)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 15:00:14 2007 -0600

    get rid of float_multiply, float_add, float_divide

diff --git a/src/mesa/shader/slang/library/slang_core.gc b/src/mesa/shader/slang/library/slang_core.gc
index a0abef0..927ca04 100644
--- a/src/mesa/shader/slang/library/slang_core.gc
+++ b/src/mesa/shader/slang/library/slang_core.gc
@@ -691,7 +691,7 @@ float __operator - (const float a, const
 
 float __operator * (const float a, const float b)
 {
-    __asm float_multiply __retVal, a, b;
+    __asm vec4_multiply __retVal.x, a, b;
 }
 
 float __operator / (const float a, const float b)
diff --git a/src/mesa/shader/slang/library/slang_core_gc.h b/src/mesa/shader/slang/library/slang_core_gc.h
index 6cb1330..0425666 100644
--- a/src/mesa/shader/slang/library/slang_core_gc.h
+++ b/src/mesa/shader/slang/library/slang_core_gc.h
@@ -188,8 +188,8 @@
 0,0,1,4,118,101,99,52,95,97,100,100,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,97,0,0,18,98,
 0,0,0,0,1,0,9,2,27,1,1,0,9,97,0,0,1,1,0,9,98,0,0,0,1,4,118,101,99,52,95,115,117,98,116,114,97,99,
 116,0,18,95,95,114,101,116,86,97,108,0,59,120,0,0,18,97,0,0,18,98,0,0,0,0,1,0,9,2,21,1,1,0,9,97,0,
-0,1,1,0,9,98,0,0,0,1,4,102,108,111,97,116,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,
-116,86,97,108,0,0,18,97,0,0,18,98,0,0,0,0,1,0,9,2,22,1,1,0,9,97,0,0,1,1,0,9,98,0,0,0,1,3,2,0,9,1,
+0,1,1,0,9,98,0,0,0,1,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,
+97,108,0,59,120,0,0,18,97,0,0,18,98,0,0,0,0,1,0,9,2,22,1,1,0,9,97,0,0,1,1,0,9,98,0,0,0,1,3,2,0,9,1,
 98,73,110,118,0,0,0,4,102,108,111,97,116,95,114,99,112,0,18,98,73,110,118,0,59,120,0,0,18,98,0,59,
 120,0,0,0,4,118,101,99,52,95,109,117,108,116,105,112,108,121,0,18,95,95,114,101,116,86,97,108,0,59,
 120,0,0,18,97,0,0,18,98,73,110,118,0,0,0,0,1,0,10,2,26,1,1,0,10,118,0,0,1,1,0,10,117,0,0,0,1,4,118,
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index e91e044..5b5de07 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -350,9 +350,6 @@ static slang_asm_info AsmInfo[] = {
    { "vec4_ddx", IR_DDX, 1, 1 },
    { "vec4_ddy", IR_DDY, 1, 1 },
    /* float binary op */
-   { "float_add", IR_ADD, 1, 2 },
-   { "float_multiply", IR_MUL, 1, 2 },
-   { "float_divide", IR_DIV, 1, 2 },
    { "float_power", IR_POW, 1, 2 },
    /* texture / sampler */
    { "vec4_tex1d", IR_TEX, 1, 2 },
diff-tree d8070889d73479d9dbef27ccf1ed5d26fc8760e5 (from c000843a14e73d593d87ff6674d0295d2cb64a12)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 11:00:21 2007 -0600

    alloc an extra byte in _mesa_ShaderSourceARB() to silence a valgrind warning

diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c
index 5bd4a3f..4c8ba47 100644
--- a/src/mesa/main/shaders.c
+++ b/src/mesa/main/shaders.c
@@ -373,7 +373,7 @@ _mesa_ShaderSourceARB(GLhandleARB shader
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint *offsets;
-   GLsizei i;
+   GLsizei i, totalLength;
    GLcharARB *source;
 
    if (string == NULL) {
@@ -406,8 +406,12 @@ _mesa_ShaderSourceARB(GLhandleARB shader
          offsets[i] += offsets[i - 1];
    }
 
-   source = (GLcharARB *) _mesa_malloc((offsets[count - 1] + 1) *
-                                       sizeof(GLcharARB));
+   /* Total length of source string is sum off all strings plus two.
+    * One extra byte for terminating zero, another extra byte to silence
+    * valgrind warnings in the parser/grammer code.
+    */
+   totalLength = offsets[count - 1] + 2;
+   source = (GLcharARB *) _mesa_malloc(totalLength * sizeof(GLcharARB));
    if (source == NULL) {
       _mesa_free((GLvoid *) offsets);
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
@@ -419,7 +423,8 @@ _mesa_ShaderSourceARB(GLhandleARB shader
       _mesa_memcpy(source + start, string[i],
                    (offsets[i] - start) * sizeof(GLcharARB));
    }
-   source[offsets[count - 1]] = '\0';
+   source[totalLength - 1] = '\0';
+   source[totalLength - 2] = '\0';
 
    ctx->Driver.ShaderSource(ctx, shaderObj, source);
 
diff-tree c000843a14e73d593d87ff6674d0295d2cb64a12 (from da554309521e8f351eecb30ce197535fb7541f40)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 10:58:48 2007 -0600

    be smarter about which fragment attribs are interpolated before running frag progs

diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index f9f0a1f..fa77612 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -554,7 +554,7 @@ interpolate_texcoords(GLcontext *ctx, SW
    for (u = 0; u < maxUnit; u++) {
       if (ctx->Texture._EnabledCoordUnits & (1 << u)) {
          const GLuint attr = FRAG_ATTRIB_TEX0 + u;
-         const struct gl_texture_object *obj =ctx->Texture.Unit[u]._Current;
+         const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
          GLfloat texW, texH;
          GLboolean needLambda;
          GLfloat (*texcoord)[4] = span->array->attribs[attr];
@@ -1261,8 +1261,18 @@ convert_color_type(SWspan *span, GLenum 
 static INLINE void
 shade_texture_span(GLcontext *ctx, SWspan *span)
 {
-   /* Now we need the rgba array, fill it in if needed */
-   if (span->interpMask & SPAN_RGBA)
+   GLbitfield inputsRead;
+
+   /* Determine which fragment attributes are actually needed */
+   if (ctx->FragmentProgram._Current) {
+      inputsRead = ctx->FragmentProgram._Current->Base.InputsRead;
+   }
+   else {
+      /* XXX we could be a bit smarter about this */
+      inputsRead = ~0;
+   }
+
+   if ((inputsRead & FRAG_BIT_COL0) && (span->interpMask & SPAN_RGBA))
       interpolate_colors(span);
 
    if (ctx->Texture._EnabledCoordUnits && (span->interpMask & SPAN_TEXTURE))
@@ -1270,35 +1280,35 @@ shade_texture_span(GLcontext *ctx, SWspa
 
    if (ctx->FragmentProgram._Current ||
        ctx->ATIFragmentShader._Enabled) {
-
       /* use float colors if running a fragment program or shader */
       const GLenum oldType = span->array->ChanType;
       const GLenum newType = GL_FLOAT;
-      if (oldType != newType) {
+
+      if ((inputsRead & FRAG_BIT_COL0) && (oldType != newType)) {
          GLvoid *src = (oldType == GL_UNSIGNED_BYTE)
             ? (GLvoid *) span->array->color.sz1.rgba
             : (GLvoid *) span->array->color.sz2.rgba;
+         assert(span->arrayMask & SPAN_RGBA);
          _mesa_convert_colors(oldType, src,
                               newType, span->array->attribs[FRAG_ATTRIB_COL0],
                               span->end, span->array->mask);
-         span->array->ChanType = newType;
       }
+      span->array->ChanType = newType;
 
       /* fragment programs/shaders may need specular, fog and Z coords */
-      if (span->interpMask & SPAN_SPEC)
+      if ((inputsRead & FRAG_BIT_COL1) && (span->interpMask & SPAN_SPEC))
          interpolate_specular(span);
 
-      if (span->interpMask & SPAN_FOG)
+      if ((inputsRead & FRAG_BIT_FOGC) && (span->interpMask & SPAN_FOG))
          interpolate_fog(ctx, span);
 
       if (span->interpMask & SPAN_Z)
          _swrast_span_interpolate_z (ctx, span);
 
-      if (ctx->Shader.CurrentProgram && span->interpMask & SPAN_VARYING)
+      if ((inputsRead >= FRAG_BIT_VAR0) && (span->interpMask & SPAN_VARYING))
          interpolate_varying(ctx, span);
 
-      if (ctx->FragmentProgram._Current &&
-          (ctx->FragmentProgram._Current->Base.InputsRead & FRAG_BIT_WPOS))
+      if (inputsRead & FRAG_BIT_WPOS)
          interpolate_wpos(ctx, span);
 
       /* Run fragment program/shader now */
diff-tree da554309521e8f351eecb30ce197535fb7541f40 (from 17ad1d12ebf04ebf4b2b35c1c37d36bb4d2bb550)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 10:58:23 2007 -0600

    comment about SPAN_* vs FRAG_BIT_* values

diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index 26ef399..8a9b9eb 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -35,6 +35,8 @@
  * \defgroup SpanFlags
  * Bitflags used for interpMask and arrayMask fields below to indicate
  * which interpolant values and fragment arrays are in use, respectively.
+ *
+ * XXX We should replace these flags with the FRAG_BIT_ values someday...
  */
 /*@{*/
 #define SPAN_RGBA         0x001
diff-tree 17ad1d12ebf04ebf4b2b35c1c37d36bb4d2bb550 (from 8b9842a2560a1254e98b5e01927f73917a0597fc)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 10:53:16 2007 -0600

    Check if FRAG_RESULT_COLR is written and update span->interpMask, arrayMask.
    
    Also, fix an assertion.

diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 7260759..7f7c0d6 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -201,12 +201,19 @@ _swrast_exec_fragment_program( GLcontext
    const struct gl_fragment_program *program = ctx->FragmentProgram._Current;
 
    /* incoming colors should be floats */
-   ASSERT(span->array->ChanType == GL_FLOAT);
+   if (program->Base.InputsRead & FRAG_BIT_COL0) {
+      ASSERT(span->array->ChanType == GL_FLOAT);
+   }
 
    ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */
 
    run_program(ctx, span, 0, span->end);
 
+   if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) {
+      span->interpMask &= ~SPAN_RGBA;
+      span->arrayMask |= SPAN_RGBA;
+   }
+
    if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) {
       span->interpMask &= ~SPAN_Z;
       span->arrayMask |= SPAN_Z;
diff-tree 8b9842a2560a1254e98b5e01927f73917a0597fc (from 7265e6928e873312d53eba4c24fcd3002e806831)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 10:49:08 2007 -0600

    Shuffle some code around in the emit_tex() and emit_move() instructions.
    
    Note that the inst ptr returned by new_instruction() may become invalid
    after calling emit_() since the emit functions may allocate new instructions
    which is done vial realloc().
    Also, add some new assertions to try to catch this kind of bug.

diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 6d39354..71741fb 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -482,12 +482,12 @@ storage_to_src_reg(struct prog_src_regis
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W),
       MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W)
    };
-   assert(st->File >= 0 && st->File <= 16);
-   src->File = st->File;
-   src->Index = st->Index;
-   assert(st->File != PROGRAM_UNDEFINED);
+   assert(st->File >= 0);
+   assert(st->File < PROGRAM_UNDEFINED);
    assert(st->Size >= 1);
    assert(st->Size <= 4);
+   src->File = st->File;
+   src->Index = st->Index;
    if (st->Swizzle != SWIZZLE_NOOP)
       src->Swizzle = st->Swizzle;
    else
@@ -520,6 +520,10 @@ new_instruction(slang_emit_info *emitInf
    _mesa_init_instructions(inst, 1);
    inst->Opcode = opcode;
    inst->BranchTarget = -1; /* invalid */
+   /*
+   printf("New inst %d: %p %s\n", prog->NumInstructions-1,(void*)inst,
+          _mesa_opcode_string(inst->Opcode));
+   */
    return inst;
 }
 
@@ -901,6 +905,9 @@ static struct prog_instruction *
 emit_tex(slang_emit_info *emitInfo, slang_ir_node *n)
 {
    struct prog_instruction *inst;
+
+   (void) emit(emitInfo, n->Children[1]);
+
    if (n->Opcode == IR_TEX) {
       inst = new_instruction(emitInfo, OPCODE_TEX);
    }
@@ -918,9 +925,9 @@ emit_tex(slang_emit_info *emitInfo, slan
 
    storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
 
-   (void) emit(emitInfo, n->Children[1]);
-
    /* Child[1] is the coord */
+   assert(n->Children[1]->Store->File != PROGRAM_UNDEFINED);
+   assert(n->Children[1]->Store->Index >= 0);
    storage_to_src_reg(&inst->SrcReg[0], n->Children[1]->Store);
 
    /* Child[0] is the sampler (a uniform which'll indicate the texture unit) */
@@ -941,15 +948,15 @@ emit_move(slang_emit_info *emitInfo, sla
 {
    struct prog_instruction *inst;
 
+   /* lhs */
+   emit(emitInfo, n->Children[0]);
+
    /* rhs */
    assert(n->Children[1]);
    inst = emit(emitInfo, n->Children[1]);
 
    assert(n->Children[1]->Store->Index >= 0);
 
-   /* lhs */
-   emit(emitInfo, n->Children[0]);
-
    assert(!n->Store);
    n->Store = n->Children[0]->Store;
 
diff-tree 7265e6928e873312d53eba4c24fcd3002e806831 (from b3a22d0ed61afa9df4d3a02962884d49bc5760a4)
Author: Brian <brian at yutani.localnet.net>
Date:   Tue Mar 13 10:28:26 2007 -0600

    properly compute ctx->Texture._EnabledCoordUnits

diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 7be3a44..bed2c12 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -41,8 +41,6 @@
 #include "texenvprogram.h"
 #include "mtypes.h"
 #include "math/m_xform.h"
-/*#include "shaderobjects.h"*/
-
 
 
 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
@@ -3076,16 +3074,14 @@ update_texture_state( GLcontext *ctx )
 	 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
    }
 
-   /* XXX maybe move this below as an else-clause */
-   ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
-
-   /* Fragment programs may need texture coordinates but not the
-    * corresponding texture images.
-    */
+   /* Determine which texture coordinate sets are actually needed */
    if (fprog) {
-      const GLuint coordMask = (1 << MAX_TEXTURE_UNITS) - 1;
+      const GLuint coordMask = (1 << MAX_TEXTURE_COORD_UNITS) - 1;
       ctx->Texture._EnabledCoordUnits
-         |= (fprog->Base.InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
+         = (fprog->Base.InputsRead >> FRAG_ATTRIB_TEX0) & coordMask;
+   }
+   else {
+      ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
    }
 }
 



More information about the mesa-commit mailing list