From 54d59cfb70f270dfec1253aff540953ee653bb7e Mon Sep 17 00:00:00 2001
From: Brian <brian@yutani.localnet.net>
Date: Thu, 26 Apr 2007 12:20:53 -0600
Subject: Added error check that all varying vars needed by the fragment shader
 are produced by vertex shader.

---
 src/mesa/shader/slang/slang_link.c | 43 +++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index 5a9385571b6..d6d1c7523e5 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -114,18 +114,18 @@ link_varying_vars(struct gl_shader_program *shProg, struct gl_program *prog)
             varsRead |= (1 << inst->SrcReg[j].Index);
          }
       }
-      /* XXX update program OutputsWritten, InputsRead */
    }
 
    if (prog->Target == GL_VERTEX_PROGRAM_ARB) {
       prog->OutputsWritten |= varsWritten;
+      /*printf("VERT OUTPUTS: 0x%x \n", varsWritten);*/
    }
    else {
       assert(prog->Target == GL_FRAGMENT_PROGRAM_ARB);
       prog->InputsRead |= varsRead;
+      /*printf("FRAG INPUTS: 0x%x\n", varsRead);*/
    }
 
-
    free(map);
 
    return GL_TRUE;
@@ -452,6 +452,21 @@ fragment_program(struct gl_program *prog)
 }
 
 
+/**
+ * Record a linking error.
+ */
+static void
+link_error(struct gl_shader_program *shProg, const char *msg)
+{
+   if (shProg->InfoLog) {
+      _mesa_free(shProg->InfoLog);
+   }
+   shProg->InfoLog = _mesa_strdup(msg);
+   shProg->LinkStatus = GL_FALSE;
+}
+
+
+
 /**
  * Shader linker.  Currently:
  *
@@ -553,18 +568,30 @@ _slang_link(GLcontext *ctx,
       _slang_update_inputs_outputs(&shProg->VertexProgram->Base);
       if (!(shProg->VertexProgram->Base.OutputsWritten & (1 << VERT_RESULT_HPOS))) {
          /* the vertex program did not compute a vertex position */
-         if (shProg->InfoLog) {
-            _mesa_free(shProg->InfoLog);
-         }
-         shProg->InfoLog
-            = _mesa_strdup("gl_Position was not written by vertex shader\n");
-         shProg->LinkStatus = GL_FALSE;
+         link_error(shProg,
+                    "gl_Position was not written by vertex shader\n");
          return;
       }
    }
    if (shProg->FragmentProgram)
       _slang_update_inputs_outputs(&shProg->FragmentProgram->Base);
 
+   /* Check that all the varying vars needed by the fragment shader are
+    * actually produced by the vertex shader.
+    */
+   if (shProg->FragmentProgram) {
+      const GLbitfield varyingRead
+         = shProg->FragmentProgram->Base.InputsRead >> FRAG_ATTRIB_VAR0;
+      const GLbitfield varyingWritten = shProg->VertexProgram ?
+         shProg->VertexProgram->Base.OutputsWritten >> VERT_RESULT_VAR0 : 0x0;
+      if ((varyingRead & varyingWritten) != varyingRead) {
+         link_error(shProg,
+          "Fragment program using varying vars not written by vertex shader\n");
+         return;
+      }         
+   }
+
+
    if (fragProg && shProg->FragmentProgram) {
       /* notify driver that a new fragment program has been compiled/linked */
       ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_PROGRAM_ARB,
-- 
cgit v1.2.3