LIBNAME = r300compiler
C_SOURCES = \
+ radeon_compiler.c \
radeon_nqssadce.c \
radeon_program.c \
radeon_program_alu.c \
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))
{
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);
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);
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);
success = r300BuildFragmentProgramHwCode(c);
}
- if (!success || c->debug) {
+ if (!success || c->Base.Debug) {
if (c->is_r500) {
r500FragmentProgramDump(c->code);
} else {
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) {
--- /dev/null
+/*
+ * 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);
+}
#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
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);
#include "radeon_program_pair.h"
#include "memory_pool.h"
+#include "radeon_compiler.h"
#include "shader/prog_print.h"
#define error(fmt, args...) do { \
};
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;
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;
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;
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]) {
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)
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);
s->Error = s->Error || !s->Handler->EmitTex(s->UserData, &rpti);
}
- if (s->Debug)
+ if (s->Compiler->Debug)
_mesa_printf(" END_TEX\n");
}
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);
emit_alu(&s);
}
- if (s.Debug)
+ if (s.Compiler->Debug)
_mesa_printf(" END\n");
- memory_pool_destroy(&s.Pool);
-
return !s.Error;
}
#include "radeon_program.h"
+struct radeon_compiler;
+
/**
* Represents a paired instruction, as found in R300 and R500
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);
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)