diff options
Diffstat (limited to 'src')
9 files changed, 82 insertions, 31 deletions
diff --git a/src/mesa/drivers/dri/r300/compiler/Makefile b/src/mesa/drivers/dri/r300/compiler/Makefile index 4da173cb587..c0fd85c1810 100644 --- a/src/mesa/drivers/dri/r300/compiler/Makefile +++ b/src/mesa/drivers/dri/r300/compiler/Makefile @@ -6,6 +6,7 @@ include $(TOP)/configs/current LIBNAME = r300compiler C_SOURCES = \ + radeon_compiler.c \ radeon_nqssadce.c \ radeon_program.c \ radeon_program_alu.c \ diff --git a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c index 520d81d3b4f..861d532d072 100644 --- a/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c +++ b/src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c @@ -334,7 +334,7 @@ GLboolean r300BuildFragmentProgramHwCode(struct r300_fragment_program_compiler * code->node[0].alu_end = -1; code->node[0].tex_end = -1; - if (!radeonPairProgram(compiler->program, &pair_handler, compiler, compiler->debug)) + if (!radeonPairProgram(&compiler->Base, compiler->program, &pair_handler, compiler)) return GL_FALSE; if (!finish_node(compiler)) diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c index daef20fe675..d4a6205e700 100644 --- a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c +++ b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c @@ -239,7 +239,7 @@ GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c { GLboolean success = GL_FALSE; - if (c->debug) { + if (c->Base.Debug) { fflush(stdout); _mesa_printf("Fragment Program: Initial program:\n"); _mesa_print_program(c->program); @@ -269,7 +269,7 @@ GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c radeonLocalTransform(c->program, 3, transformations); } - if (c->debug) { + if (c->Base.Debug) { _mesa_printf("Fragment Program: After native rewrite:\n"); _mesa_print_program(c->program); fflush(stdout); @@ -291,7 +291,7 @@ GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c radeonNqssaDce(c->program, &nqssadce, 0); } - if (c->debug) { + if (c->Base.Debug) { _mesa_printf("Compiler: after NqSSA-DCE:\n"); _mesa_print_program(c->program); fflush(stdout); @@ -303,7 +303,7 @@ GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c success = r300BuildFragmentProgramHwCode(c); } - if (!success || c->debug) { + if (!success || c->Base.Debug) { if (c->is_r500) { r500FragmentProgramDump(c->code); } else { diff --git a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c index 5640ed0bcaa..a0cc88da9ca 100644 --- a/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c +++ b/src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c @@ -310,7 +310,7 @@ GLboolean r500BuildFragmentProgramHwCode(struct r300_fragment_program_compiler * code->inst_offset = 0; code->inst_end = -1; - if (!radeonPairProgram(compiler->program, &pair_handler, compiler, compiler->debug)) + if (!radeonPairProgram(&compiler->Base, compiler->program, &pair_handler, compiler)) return GL_FALSE; if ((code->inst[code->inst_end].inst0 & R500_INST_TYPE_MASK) != R500_INST_TYPE_OUT) { diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c new file mode 100644 index 00000000000..20af4a651aa --- /dev/null +++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.c @@ -0,0 +1,36 @@ +/* + * Copyright 2009 Nicolai Hähnle <[email protected]> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "radeon_compiler.h" + + +void rc_init(struct radeon_compiler * c) +{ + memset(c, 0, sizeof(*c)); + + memory_pool_init(&c->Pool); +} + +void rc_destroy(struct radeon_compiler * c) +{ + memory_pool_destroy(&c->Pool); +} diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h index 92560b5d8ae..6c5a2e5c8c3 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h +++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler.h @@ -26,6 +26,8 @@ #include "main/mtypes.h" #include "shader/prog_instruction.h" +#include "memory_pool.h" + #define R300_PFS_MAX_ALU_INST 64 #define R300_PFS_MAX_TEX_INST 32 #define R300_PFS_MAX_TEX_INDIRECT 4 @@ -148,12 +150,20 @@ struct rX00_fragment_program_code { gl_frag_attrib fog_attr; }; +struct radeon_compiler { + struct memory_pool Pool; + GLboolean Debug; +}; + +void rc_init(struct radeon_compiler * c); +void rc_destroy(struct radeon_compiler * c); + struct r300_fragment_program_compiler { + struct radeon_compiler Base; struct rX00_fragment_program_code *code; struct gl_program *program; struct r300_fragment_program_external_state state; GLboolean is_r500; - GLboolean debug; }; GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c); diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.c b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.c index 254431731b3..5e0484f2960 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.c +++ b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.c @@ -36,6 +36,7 @@ #include "radeon_program_pair.h" #include "memory_pool.h" +#include "radeon_compiler.h" #include "shader/prog_print.h" #define error(fmt, args...) do { \ @@ -118,11 +119,10 @@ struct pair_register_translation { }; struct pair_state { - struct memory_pool Pool; + struct radeon_compiler * Compiler; struct gl_program *Program; const struct radeon_pair_handler *Handler; GLboolean Error; - GLboolean Debug; GLboolean Verbose; void *UserData; @@ -341,7 +341,7 @@ static void scan_instructions(struct pair_state *s) for(source = s->Program->Instructions, ip = 0; source->Opcode != OPCODE_END; ++source, ++ip) { - struct pair_state_instruction *pairinst = memory_pool_malloc(&s->Pool, sizeof(*pairinst)); + struct pair_state_instruction *pairinst = memory_pool_malloc(&s->Compiler->Pool, sizeof(*pairinst)); memset(pairinst, 0, sizeof(struct pair_state_instruction)); pairinst->Instruction = *source; @@ -377,7 +377,7 @@ static void scan_instructions(struct pair_state *s) GET_BIT(pairinst->Instruction.DstReg.WriteMask, swz)) continue; - struct reg_value_reader* r = memory_pool_malloc(&s->Pool, sizeof(*r)); + struct reg_value_reader* r = memory_pool_malloc(&s->Compiler->Pool, sizeof(*r)); pairinst->NumDependencies++; t->Value[swz]->NumReaders++; r->Reader = pairinst; @@ -400,7 +400,7 @@ static void scan_instructions(struct pair_state *s) if (!GET_BIT(pairinst->Instruction.DstReg.WriteMask, j)) continue; - struct reg_value* v = memory_pool_malloc(&s->Pool, sizeof(*v)); + struct reg_value* v = memory_pool_malloc(&s->Compiler->Pool, sizeof(*v)); memset(v, 0, sizeof(struct reg_value)); v->Writer = pairinst; if (t->Value[j]) { @@ -580,7 +580,7 @@ static void emit_all_tex(struct pair_state *s) get_hw_reg(s, inst->DstReg.File, inst->DstReg.Index); } - if (s->Debug) + if (s->Compiler->Debug) _mesa_printf(" BEGIN_TEX\n"); if (s->Handler->BeginTexBlock) @@ -594,7 +594,7 @@ static void emit_all_tex(struct pair_state *s) inst->DstReg.Index = get_hw_reg(s, inst->DstReg.File, inst->DstReg.Index); inst->SrcReg[0].Index = get_hw_reg(s, inst->SrcReg[0].File, inst->SrcReg[0].Index); - if (s->Debug) { + if (s->Compiler->Debug) { _mesa_printf(" "); _mesa_print_instruction(inst); fflush(stdout); @@ -620,7 +620,7 @@ static void emit_all_tex(struct pair_state *s) s->Error = s->Error || !s->Handler->EmitTex(s->UserData, &rpti); } - if (s->Debug) + if (s->Compiler->Debug) _mesa_printf(" END_TEX\n"); } @@ -867,28 +867,28 @@ static void emit_alu(struct pair_state *s) success: ; } - if (s->Debug) + if (s->Compiler->Debug) radeonPrintPairInstruction(&pair); s->Error = s->Error || !s->Handler->EmitPaired(s->UserData, &pair); } -GLboolean radeonPairProgram(struct gl_program *program, - const struct radeon_pair_handler* handler, void *userdata, - GLboolean debug) +GLboolean radeonPairProgram( + struct radeon_compiler * compiler, + struct gl_program *program, + const struct radeon_pair_handler* handler, void *userdata) { struct pair_state s; _mesa_bzero(&s, sizeof(s)); - memory_pool_init(&s.Pool); + s.Compiler = compiler; s.Program = program; s.Handler = handler; s.UserData = userdata; - s.Debug = debug; - s.Verbose = GL_FALSE && s.Debug; + s.Verbose = GL_FALSE && s.Compiler->Debug; - if (s.Debug) + if (s.Compiler->Debug) _mesa_printf("Emit paired program\n"); scan_instructions(&s); @@ -903,11 +903,9 @@ GLboolean radeonPairProgram(struct gl_program *program, emit_alu(&s); } - if (s.Debug) + if (s.Compiler->Debug) _mesa_printf(" END\n"); - memory_pool_destroy(&s.Pool); - return !s.Error; } diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h index 86e3ec4537d..2e6bdf90390 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h +++ b/src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h @@ -30,6 +30,8 @@ #include "radeon_program.h" +struct radeon_compiler; + /** * Represents a paired instruction, as found in R300 and R500 @@ -139,9 +141,10 @@ struct radeon_pair_handler { GLuint MaxHwTemps; }; -GLboolean radeonPairProgram(struct gl_program *program, - const struct radeon_pair_handler*, void *userdata, - GLboolean debug); +GLboolean radeonPairProgram( + struct radeon_compiler * compiler, + struct gl_program *program, + const struct radeon_pair_handler*, void *userdata); void radeonPrintPairInstruction(struct radeon_pair_instruction *inst); diff --git a/src/mesa/drivers/dri/r300/r300_fragprog_common.c b/src/mesa/drivers/dri/r300/r300_fragprog_common.c index c7ffbad475b..5216f5904ad 100644 --- a/src/mesa/drivers/dri/r300/r300_fragprog_common.c +++ b/src/mesa/drivers/dri/r300/r300_fragprog_common.c @@ -89,18 +89,21 @@ static void translate_fragment_program(GLcontext *ctx, struct r300_fragment_prog r300ContextPtr r300 = R300_CONTEXT(ctx); struct r300_fragment_program_compiler compiler; + rc_init(&compiler.Base); + compiler.Base.Debug = (RADEON_DEBUG & DEBUG_PIXEL) ? GL_TRUE : GL_FALSE; + compiler.code = &fp->code; compiler.state = fp->state; compiler.program = _mesa_clone_program(ctx, &cont->Base.Base); compiler.is_r500 = (r300->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV515) ? GL_TRUE : GL_FALSE; - compiler.debug = (RADEON_DEBUG & DEBUG_PIXEL) ? GL_TRUE : GL_FALSE; if (!r3xx_compile_fragment_program(&compiler)) fp->error = GL_TRUE; fp->InputsRead = compiler.program->InputsRead; - fp->Base = compiler.program; + + rc_destroy(&compiler.Base); } struct r300_fragment_program *r300SelectAndTranslateFragmentShader(GLcontext *ctx) |