mesa: replace _mesa_bzero() with memset()
[mesa.git] / src / mesa / drivers / dri / r300 / r300_fragprog_common.c
index 6674efc5bcaa8d89d6da6c5b7ee9e30ec26e67f4..acc66e0ae0231352425a14d1d028df402d70384d 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)
@@ -73,7 +72,7 @@ static void build_state(
 {
        int unit;
 
-       _mesa_bzero(state, sizeof(*state));
+       memset(state, 0, sizeof(*state));
 
        for(unit = 0; unit < 16; ++unit) {
                if (fp->Base.ShadowSamplers & (1 << unit)) {
@@ -99,8 +98,8 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler,
 {
        int i;
 
+       fp->wpos_attr = FRAG_ATTRIB_MAX;
        if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) {
-               fp->wpos_attr = FRAG_ATTRIB_MAX;
                return;
        }
 
@@ -112,7 +111,14 @@ static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler,
                }
        }
 
-       rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, fp->wpos_attr);
+       /* No free texcoord found, fall-back to software rendering */
+       if (fp->wpos_attr == FRAG_ATTRIB_MAX)
+       {
+               compiler->Base.Error = 1;
+               return;
+       }
+
+       rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, fp->wpos_attr, GL_FALSE);
 }
 
 /**
@@ -124,11 +130,11 @@ 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;
        if (!(compiler->Base.Program.InputsRead & FRAG_BIT_FOGC)) {
-               fp->fog_attr = FRAG_ATTRIB_MAX;
                return;
        }
 
@@ -140,8 +146,15 @@ static void rewriteFog(struct r300_fragment_program_compiler *compiler, struct r
                }
        }
 
+       /* No free texcoord found, fall-back to software rendering */
+       if (fp->fog_attr == FRAG_ATTRIB_MAX)
+       {
+               compiler->Base.Error = 1;
+               return;
+       }
+
        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);
@@ -202,29 +215,43 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog
        struct r300_fragment_program_compiler compiler;
 
        rc_init(&compiler.Base);
-       compiler.Base.Debug = (RADEON_DEBUG & DEBUG_PIXEL) ? GL_TRUE : GL_FALSE;
+       compiler.Base.Debug = (RADEON_DEBUG & RADEON_PIXEL) ? GL_TRUE : GL_FALSE;
 
        compiler.code = &fp->code;
        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) {
-               fflush(stdout);
+               fflush(stderr);
                _mesa_printf("Fragment Program: Initial program:\n");
                _mesa_print_program(&cont->Base.Base);
-               fflush(stdout);
+               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;
@@ -244,7 +271,7 @@ struct r300_fragment_program *r300SelectAndTranslateFragmentShader(GLcontext *ct
 
        fp = fp_list->progs;
        while (fp) {
-               if (_mesa_memcmp(&fp->state, &state, sizeof(state)) == 0) {
+               if (memcmp(&fp->state, &state, sizeof(state)) == 0) {
                        return r300->selected_fp = fp;
                }
                fp = fp->next;