r300: fix compiler bugs introduced with MRT changes.
[mesa.git] / src / mesa / drivers / dri / r300 / r300_fragprog_common.c
index 0bdc90b4a84ead9cf9a5259c835cf33b0d2992d4..a0e2dd3c09f3dd60c339f405e9018c36c5f60dae 100644 (file)
 
 #include "r300_fragprog_common.h"
 
-#include "shader/program.h"
 #include "shader/prog_parameter.h"
 #include "shader/prog_print.h"
 
 #include "compiler/radeon_compiler.h"
 
-#include "r300_state.h"
+#include "radeon_mesa_to_rc.h"
 
 
 static GLuint build_dtm(GLuint depthmode)
@@ -119,7 +118,7 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler,
                return;
        }
 
-       rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, fp->wpos_attr);
+       rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, fp->wpos_attr, GL_FALSE);
 }
 
 /**
@@ -131,7 +130,7 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler,
  */
 static void rewriteFog(struct r300_fragment_program_compiler *compiler, struct r300_fragment_program * fp)
 {
-       struct prog_src_register src;
+       struct rc_src_register src;
        int i;
 
        fp->fog_attr = FRAG_ATTRIB_MAX;
@@ -155,7 +154,7 @@ static void rewriteFog(struct r300_fragment_program_compiler *compiler, struct r
        }
 
        memset(&src, 0, sizeof(src));
-       src.File = PROGRAM_INPUT;
+       src.File = RC_FILE_INPUT;
        src.Index = fp->fog_attr;
        src.Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE);
        rc_move_input(&compiler->Base, FRAG_ATTRIB_FOGC, src);
@@ -222,7 +221,8 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
        compiler.state = fp->state;
        compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) ? GL_TRUE : GL_FALSE;
        compiler.OutputDepth = FRAG_RESULT_DEPTH;
-       compiler.OutputColor = FRAG_RESULT_COLOR;
+       memset(compiler.OutputColor, 0, 4 * sizeof(unsigned));
+       compiler.OutputColor[0] = FRAG_RESULT_COLOR;
        compiler.AllocateHwInputs = &allocate_hw_inputs;
 
        if (compiler.Base.Debug) {
@@ -232,13 +232,26 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
                fflush(stderr);
        }
 
-       rc_mesa_to_rc_program(&compiler.Base, &cont->Base.Base);
+       radeon_mesa_to_rc_program(&compiler.Base, &cont->Base.Base);
 
        insert_WPOS_trailer(&compiler, fp);
 
        rewriteFog(&compiler, fp);
 
        r3xx_compile_fragment_program(&compiler);
+
+       if (compiler.is_r500) {
+               /* We need to support the non-KMS DRM interface, which
+                * artificially limits the number of instructions and
+                * constants which are available to us.
+                *
+                * See also the comment in r300_context.c where we
+                * set the MAX_NATIVE_xxx values.
+                */
+               if (fp->code.code.r500.inst_end >= 255 || fp->code.constants.Count > 255)
+                       rc_error(&compiler.Base, "Program is too big (upgrade to r300g to avoid this limitation).\n");
+       }
+
        fp->error = compiler.Base.Error;
 
        fp->InputsRead = compiler.Base.Program.InputsRead;