From: Nicolai Hähnle Date: Fri, 24 Jul 2009 23:19:04 +0000 (+0200) Subject: r300/fragprog: Move some of the attribute handling out of the compiler X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=836050ba5eb9690e4a64499249eb71af14961deb;p=mesa.git r300/fragprog: Move some of the attribute handling out of the compiler Attribute indices will probably be different in Gallium, so make the compiler independent of magic values. Signed-off-by: Nicolai Hähnle --- diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c index 3c63da81766..d39b82be71c 100644 --- a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c +++ b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c @@ -35,73 +35,11 @@ static void nqssadce_init(struct nqssadce_state* s) { - s->Outputs[FRAG_RESULT_COLOR].Sourced = WRITEMASK_XYZW; - s->Outputs[FRAG_RESULT_DEPTH].Sourced = WRITEMASK_W; + struct r300_fragment_program_compiler * c = s->UserData; + s->Outputs[c->OutputColor].Sourced = WRITEMASK_XYZW; + s->Outputs[c->OutputDepth].Sourced = WRITEMASK_W; } -/** - * Transform the program to support fragment.position. - * - * Introduce a small fragment at the start of the program that will be - * the only code that directly reads the FRAG_ATTRIB_WPOS input. - * All other code pieces that reference that input will be rewritten - * to read from a newly allocated temporary. - * - */ -static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) -{ - int i; - - if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) { - compiler->code->wpos_attr = FRAG_ATTRIB_MAX; - return; - } - - for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i) - { - if (!(compiler->Base.Program.InputsRead & (1 << i))) { - compiler->code->wpos_attr = i; - break; - } - } - - rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, compiler->code->wpos_attr); -} - -/** - * Rewrite fragment.fogcoord to use a texture coordinate slot. - * Note that fogcoord is forced into an X001 pattern, and this enforcement - * is done here. - * - * See also the counterpart rewriting for vertex programs. - */ -static void rewriteFog(struct r300_fragment_program_compiler *compiler) -{ - struct rX00_fragment_program_code *code = compiler->code; - struct prog_src_register src; - int i; - - if (!(compiler->Base.Program.InputsRead & FRAG_BIT_FOGC)) { - code->fog_attr = FRAG_ATTRIB_MAX; - return; - } - - for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i) - { - if (!(compiler->Base.Program.InputsRead & (1 << i))) { - code->fog_attr = i; - break; - } - } - - reset_srcreg(&src); - src.File = PROGRAM_INPUT; - src.Index = code->fog_attr; - src.Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE); - rc_move_input(&compiler->Base, FRAG_ATTRIB_FOGC, src); -} - - static void rewrite_depth_out(struct r300_fragment_program_compiler * c) { struct rc_instruction *rci; @@ -109,7 +47,7 @@ static void rewrite_depth_out(struct r300_fragment_program_compiler * c) for (rci = c->Base.Program.Instructions.Next; rci != &c->Base.Program.Instructions; rci = rci->Next) { struct prog_instruction * inst = &rci->I; - if (inst->DstReg.File != PROGRAM_OUTPUT || inst->DstReg.Index != FRAG_RESULT_DEPTH) + if (inst->DstReg.File != PROGRAM_OUTPUT || inst->DstReg.Index != c->OutputDepth) continue; if (inst->DstReg.WriteMask & WRITEMASK_Z) { @@ -146,10 +84,6 @@ static void rewrite_depth_out(struct r300_fragment_program_compiler * c) void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c) { - insert_WPOS_trailer(c); - - rewriteFog(c); - rewrite_depth_out(c); if (c->is_r500) { @@ -181,14 +115,14 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c) .IsNativeSwizzle = &r500FPIsNativeSwizzle, .BuildSwizzle = &r500FPBuildSwizzle }; - radeonNqssaDce(&c->Base, &nqssadce, 0); + radeonNqssaDce(&c->Base, &nqssadce, c); } else { struct radeon_nqssadce_descr nqssadce = { .Init = &nqssadce_init, .IsNativeSwizzle = &r300FPIsNativeSwizzle, .BuildSwizzle = &r300FPBuildSwizzle }; - radeonNqssaDce(&c->Base, &nqssadce, 0); + radeonNqssaDce(&c->Base, &nqssadce, c); } if (c->Base.Debug) { diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h index b9e1a7959af..34f87183169 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h +++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h @@ -76,6 +76,8 @@ struct r300_fragment_program_compiler { struct rX00_fragment_program_code *code; struct r300_fragment_program_external_state state; GLboolean is_r500; + unsigned OutputDepth; + unsigned OutputColor; }; void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c); diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_common.c b/src/mesa/drivers/dri/r300/r300_fragprog_common.c index 05f46ad0607..00807245752 100644 --- a/src/mesa/drivers/dri/r300/r300_fragprog_common.c +++ b/src/mesa/drivers/dri/r300/r300_fragprog_common.c @@ -86,6 +86,69 @@ static void build_state( } +/** + * Transform the program to support fragment.position. + * + * Introduce a small fragment at the start of the program that will be + * the only code that directly reads the FRAG_ATTRIB_WPOS input. + * All other code pieces that reference that input will be rewritten + * to read from a newly allocated temporary. + * + */ +static void insert_WPOS_trailer(struct r300_fragment_program_compiler *compiler) +{ + int i; + + if (!(compiler->Base.Program.InputsRead & FRAG_BIT_WPOS)) { + compiler->code->wpos_attr = FRAG_ATTRIB_MAX; + return; + } + + for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i) + { + if (!(compiler->Base.Program.InputsRead & (1 << i))) { + compiler->code->wpos_attr = i; + break; + } + } + + rc_transform_fragment_wpos(&compiler->Base, FRAG_ATTRIB_WPOS, compiler->code->wpos_attr); +} + +/** + * Rewrite fragment.fogcoord to use a texture coordinate slot. + * Note that fogcoord is forced into an X001 pattern, and this enforcement + * is done here. + * + * See also the counterpart rewriting for vertex programs. + */ +static void rewriteFog(struct r300_fragment_program_compiler *compiler) +{ + struct rX00_fragment_program_code *code = compiler->code; + struct prog_src_register src; + int i; + + if (!(compiler->Base.Program.InputsRead & FRAG_BIT_FOGC)) { + code->fog_attr = FRAG_ATTRIB_MAX; + return; + } + + for (i = FRAG_ATTRIB_TEX0; i <= FRAG_ATTRIB_TEX7; ++i) + { + if (!(compiler->Base.Program.InputsRead & (1 << i))) { + code->fog_attr = i; + break; + } + } + + memset(&src, 0, sizeof(src)); + src.File = PROGRAM_INPUT; + src.Index = code->fog_attr; + src.Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ONE); + rc_move_input(&compiler->Base, FRAG_ATTRIB_FOGC, src); +} + + static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_program_cont *cont, struct r300_fragment_program *fp) { r300ContextPtr r300 = R300_CONTEXT(ctx); @@ -97,6 +160,8 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog 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; if (compiler.Base.Debug) { fflush(stdout); @@ -107,6 +172,10 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog rc_mesa_to_rc_program(&compiler.Base, &cont->Base.Base); + insert_WPOS_trailer(&compiler); + + rewriteFog(&compiler); + r3xx_compile_fragment_program(&compiler); fp->error = compiler.Base.Error;