r300: Add radeon_compiler as a base for compilation-related tasks
authorNicolai Hähnle <nhaehnle@gmail.com>
Wed, 22 Jul 2009 19:29:35 +0000 (21:29 +0200)
committerNicolai Hähnle <nhaehnle@gmail.com>
Mon, 27 Jul 2009 18:32:04 +0000 (20:32 +0200)
Signed-off-by: Nicolai Hähnle <nhaehnle@gmail.com>
src/mesa/drivers/dri/r300/compiler/Makefile
src/mesa/drivers/dri/r300/compiler/r300_fragprog_emit.c
src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
src/mesa/drivers/dri/r300/compiler/r500_fragprog_emit.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.c [new file with mode: 0644]
src/mesa/drivers/dri/r300/compiler/radeon_compiler.h
src/mesa/drivers/dri/r300/compiler/radeon_program_pair.c
src/mesa/drivers/dri/r300/compiler/radeon_program_pair.h
src/mesa/drivers/dri/r300/r300_fragprog_common.c

index 4da173cb58712bcdf3f14c195cd402467b33dacd..c0fd85c181031b71c5953850780970eaa0e659e3 100644 (file)
@@ -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 \
index 520d81d3b4f385ab63044cb516362a3359cc2379..861d532d072076bd46f78f44417aca8435f2928c 100644 (file)
@@ -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))
index daef20fe675a5472617d48842b0900aee0909d26..d4a6205e7002604e43888bb3b1f4f7b5254f4548 100644 (file)
@@ -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 {
index 5640ed0bcaad88304bf20ea610e94b25cce86b63..a0cc88da9caba80fc52a3f6cbad4f549a3a1f1f3 100644 (file)
@@ -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 (file)
index 0000000..20af4a6
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
+ *
+ * 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);
+}
index 92560b5d8ae7d69b8dbfd2d772afe37e935fc17e..6c5a2e5c8c33b94ded84157753dd12eb49a0233f 100644 (file)
@@ -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);
index 254431731b32d4d8b9e0a0e286f45020ae9228ab..5e0484f29604aafdfa7a54f43d91af4e4bfda6e7 100644 (file)
@@ -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;
 }
 
index 86e3ec4537d0fb9bb5758f83a1ee1ac597414310..2e6bdf90390b33679deed89ab05d12460d279777 100644 (file)
@@ -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);
 
index c7ffbad475bba5756a62d6052514b16d34cc4dd0..5216f5904ad1a14bee54db84375f88fd225cc2ce 100644 (file)
@@ -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)