X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_fragprog_to_c.c;h=d5d27d0bcf713cddb35a3ea8f69983b8a8cf035d;hb=4102a3045cb64a7875c524a58f13766a48bbe164;hp=f4bae2a82d000d4c0fccb5517ab163d1694829f6;hpb=563dadd674c7679d6246abfd982019287b4d58e7;p=mesa.git diff --git a/src/mesa/swrast/s_fragprog_to_c.c b/src/mesa/swrast/s_fragprog_to_c.c index f4bae2a82d0..d5d27d0bcf7 100644 --- a/src/mesa/swrast/s_fragprog_to_c.c +++ b/src/mesa/swrast/s_fragprog_to_c.c @@ -39,6 +39,8 @@ #include "s_texture.h" +#ifdef USE_TCC + /* UREG - a way of representing an FP source register including * swizzling and negation in a single GLuint. Major flaw is the * limitiation to source->Index < 32. Secondary flaw is the fact that @@ -157,19 +159,20 @@ static void emit( struct fragment_program *p, va_list ap; va_start( ap, fmt ); - p->c_strlen += vsnprintf( p->c_str + p->c_strlen, - sizeof(p->c_str) - p->c_strlen, - fmt, ap ); + if (p->c_strlen < sizeof(p->c_str)) + p->c_strlen += vsnprintf( p->c_str + p->c_strlen, + sizeof(p->c_str) - p->c_strlen, + fmt, ap ); va_end( ap ); } static INLINE void emit_char( struct fragment_program *p, char c ) { - if (p->c_strlen < sizeof(p->c_str)) + if (p->c_strlen < sizeof(p->c_str)) { p->c_str[p->c_strlen] = c; - - p->c_strlen++; + p->c_strlen++; + } } @@ -202,6 +205,18 @@ static void print_header( struct fragment_program *p ) { emit(p, "\n\n\n"); + /* Mesa's program_parameter struct: + */ + emit(p, + "struct program_parameter\n" + "{\n" + " const char *Name;\n" + " int Type;\n" + " int StateIndexes[6];\n" + " float Values[4];\n" + "};\n"); + + /* Texture samplers, not written yet: */ emit(p, "extern void TEX( void *ctx, const float *txc, int unit, float *rslt );\n" @@ -225,14 +240,15 @@ static void print_header( struct fragment_program *p ) /* The usual macros, not really needed, but handy: */ emit(p, "#define MIN2(x,y) ((x)<(y)?(x):(y))\n" - "#define MAX2(x,y) ((x)<(y)?(x):(y))\n"); + "#define MAX2(x,y) ((x)<(y)?(x):(y))\n" + "#define SATURATE(x) ((x)>1.0?1.0:((x)<0.0?0.0:(x)))\n"); /* Our function! */ - emit(p, "void run_program( void *ctx, \n" + emit(p, "int run_program( void *ctx, \n" " const float (*local_param)[4], \n" " const float (*env_param)[4], \n" - " const float (*state_param)[4], \n" + " const struct program_parameter *state_param, \n" " const float (*interp)[4], \n" " float (*outputs)[4])\n" "{\n" @@ -242,6 +258,7 @@ static void print_header( struct fragment_program *p ) static void print_footer( struct fragment_program *p ) { + emit(p, " return 1;"); emit(p, "}\n"); } @@ -279,11 +296,15 @@ static void print_reg( struct fragment_program *p, case UREG_TYPE_INTERP: emit(p, "interp"); break; case UREG_TYPE_LOCAL_CONST: emit(p, "local_const"); break; case UREG_TYPE_ENV_CONST: emit(p, "env_const"); break; - case UREG_TYPE_STATE_CONST: emit(p, "state_const"); break; + case UREG_TYPE_STATE_CONST: emit(p, "state_param"); break; case UREG_TYPE_PARAM: emit(p, "param"); break; }; emit(p, "[%d]", GET_UREG_NR(arg)); + + if (GET_UREG_TYPE(arg) == UREG_TYPE_STATE_CONST) { + emit(p, ".Values"); + } } @@ -305,7 +326,8 @@ static void print_arg( struct fragment_program *p, return; } - if (GET_UREG_TYPE(arg) == UREG_TYPE_STATE_CONST) { + if (GET_UREG_TYPE(arg) == UREG_TYPE_STATE_CONST && + p->Parameters->Parameters[GET_UREG_NR(arg)].Type == CONSTANT) { emit(p, "%g", p->Parameters->Parameters[GET_UREG_NR(arg)].Values[src]); return; } @@ -347,6 +369,26 @@ static void print_expression( struct fragment_program *p, emit(p, ";\n"); } +static void do_tex_kill( struct fragment_program *p, + const struct fp_instruction *inst, + GLuint arg ) +{ + GLuint i; + + emit(p, "if ("); + + for (i = 0; i < 4; i++) { + print_arg( p, deref(arg, i) ); + emit(p, " < 0 "); + if (i + 1 < 4) + emit(p, "|| "); + } + + emit(p, ")\n"); + emit(p, " return 0;\n"); + +} + static void do_tex_simple( struct fragment_program *p, const struct fp_instruction *inst, const char *fn, GLuint texunit, GLuint arg ) @@ -408,9 +450,9 @@ static void saturate( struct fragment_program *p, { emit(p, " "); print_dest(p, inst, i); - emit(p, " = CLAMPF( "); + emit(p, " = SATURATE( "); print_dest(p, inst, i); - emit(p, ", 0.0, 1.0);\n"); + emit(p, ");\n"); } static void assign_single( GLuint i, @@ -641,7 +683,7 @@ static void translate_program( struct fragment_program *p ) break; case FP_OPCODE_KIL: - /* TODO */ + do_tex_kill(p, inst, src[0]); break; case FP_OPCODE_LG2: @@ -774,10 +816,7 @@ void _swrast_translate_program( GLcontext *ctx ) print_header( p ); translate_program( p ); print_footer( p ); - emit_char(p, 0); - - printf("C program length: %d/%d chars\n", p->c_strlen, strlen(p->c_str)); - printf(p->c_str); } } +#endif /*USE_TCC*/