code->node[0].alu_end = -1;
code->node[0].tex_end = -1;
- if (!radeonPairProgram(&compiler->Base, compiler->program, &pair_handler, compiler))
+ if (!radeonPairProgram(&compiler->Base, &pair_handler, compiler))
return GL_FALSE;
if (!finish_node(compiler))
fflush(stdout);
}
+ rc_mesa_to_rc_program(&c->Base, c->program);
+
if (c->is_r500) {
success = r500BuildFragmentProgramHwCode(c);
} else {
code->inst_offset = 0;
code->inst_end = -1;
- if (!radeonPairProgram(&compiler->Base, compiler->program, &pair_handler, compiler))
+ if (!radeonPairProgram(&compiler->Base, &pair_handler, compiler))
return GL_FALSE;
if ((code->inst[code->inst_end].inst0 & R500_INST_TYPE_MASK) != R500_INST_TYPE_OUT) {
memset(c, 0, sizeof(*c));
memory_pool_init(&c->Pool);
+ c->Program.Instructions.Prev = &c->Program.Instructions;
+ c->Program.Instructions.Next = &c->Program.Instructions;
+ c->Program.Instructions.I.Opcode = OPCODE_END;
}
void rc_destroy(struct radeon_compiler * c)
gl_frag_attrib fog_attr;
};
+struct rc_instruction {
+ struct rc_instruction * Prev;
+ struct rc_instruction * Next;
+ struct prog_instruction I;
+};
+
+struct rc_program {
+ /**
+ * Instructions.Next points to the first instruction,
+ * Instructions.Prev points to the last instruction.
+ */
+ struct rc_instruction Instructions;
+
+ GLbitfield InputsRead;
+ GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
+};
+
struct radeon_compiler {
struct memory_pool Pool;
+ struct rc_program Program;
GLboolean Debug;
};
#include "radeon_program.h"
+#include "radeon_compiler.h"
#include "shader/prog_print.h"
_mesa_insert_instructions(program, oldnum, count);
return program->Instructions + oldnum;
}
+
+
+GLint rc_find_free_temporary(struct radeon_compiler * c)
+{
+ GLboolean used[MAX_PROGRAM_TEMPS];
+ GLuint i;
+
+ memset(used, 0, sizeof(used));
+
+ for (struct rc_instruction * rcinst = c->Program.Instructions.Next; rcinst != &c->Program.Instructions; rcinst = rcinst->Next) {
+ const struct prog_instruction *inst = &rcinst->I;
+ const GLuint n = _mesa_num_inst_src_regs(inst->Opcode);
+ GLuint k;
+
+ for (k = 0; k < n; k++) {
+ if (inst->SrcReg[k].File == PROGRAM_TEMPORARY)
+ used[inst->SrcReg[k].Index] = GL_TRUE;
+ }
+ }
+
+ for (i = 0; i < MAX_PROGRAM_TEMPS; i++) {
+ if (!used[i])
+ return i;
+ }
+
+ return -1;
+}
+
+
+struct rc_instruction *rc_alloc_instruction(struct radeon_compiler * c)
+{
+ struct rc_instruction * inst = memory_pool_malloc(&c->Pool, sizeof(struct rc_instruction));
+
+ inst->Prev = 0;
+ inst->Next = 0;
+
+ _mesa_init_instructions(&inst->I, 1);
+
+ return inst;
+}
+
+
+struct rc_instruction *rc_insert_new_instruction(struct radeon_compiler * c, struct rc_instruction * after)
+{
+ struct rc_instruction * inst = rc_alloc_instruction(c);
+
+ inst->Prev = after;
+ inst->Next = after->Next;
+
+ inst->Prev->Next = inst;
+ inst->Next->Prev = inst;
+
+ return inst;
+}
+
+
+void rc_mesa_to_rc_program(struct radeon_compiler * c, struct gl_program * program)
+{
+ struct prog_instruction *source;
+
+ for(source = program->Instructions; source->Opcode != OPCODE_END; ++source) {
+ struct rc_instruction * dest = rc_insert_new_instruction(c, c->Program.Instructions.Prev);
+ dest->I = *source;
+ }
+
+ c->Program.ShadowSamplers = program->ShadowSamplers;
+ c->Program.InputsRead = program->InputsRead;
+}
+
#include "shader/program.h"
#include "shader/prog_instruction.h"
+struct radeon_compiler;
+struct rc_instruction;
enum {
PROGRAM_BUILTIN = PROGRAM_FILE_MAX /**< not a real register, but a special swizzle constant */
struct prog_instruction *radeonAppendInstructions(struct gl_program *program, int count);
+GLint rc_find_free_temporary(struct radeon_compiler * c);
+
+struct rc_instruction *rc_alloc_instruction(struct radeon_compiler * c);
+struct rc_instruction *rc_insert_new_instruction(struct radeon_compiler * c, struct rc_instruction * after);
+
+void rc_mesa_to_rc_program(struct radeon_compiler * c, struct gl_program * program);
+
#endif
struct pair_state {
struct radeon_compiler * Compiler;
- struct gl_program *Program;
const struct radeon_pair_handler *Handler;
GLboolean Error;
GLboolean Verbose;
*/
static void scan_instructions(struct pair_state *s)
{
- struct prog_instruction *source;
+ struct rc_instruction *source;
GLuint ip;
- for(source = s->Program->Instructions, ip = 0;
- source->Opcode != OPCODE_END;
- ++source, ++ip) {
+ for(source = s->Compiler->Program.Instructions.Next, ip = 0;
+ source != &s->Compiler->Program.Instructions;
+ source = source->Next, ++ip) {
struct pair_state_instruction *pairinst = memory_pool_malloc(&s->Compiler->Pool, sizeof(*pairinst));
memset(pairinst, 0, sizeof(struct pair_state_instruction));
- pairinst->Instruction = *source;
+ pairinst->Instruction = source->I;
pairinst->IP = ip;
final_rewrite(s, &pairinst->Instruction);
classify_instruction(s, pairinst);
*/
static void allocate_input_registers(struct pair_state *s)
{
- GLuint InputsRead = s->Program->InputsRead;
+ GLuint InputsRead = s->Compiler->Program.InputsRead;
int i;
GLuint hwindex = 0;
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));
s.Compiler = compiler;
- s.Program = program;
s.Handler = handler;
s.UserData = userdata;
s.Verbose = GL_FALSE && s.Compiler->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);
if (!r3xx_compile_fragment_program(&compiler))
fp->error = GL_TRUE;
- fp->InputsRead = compiler.program->InputsRead;
+ fp->InputsRead = compiler.Base.Program.InputsRead;
fp->Base = compiler.program;
rc_destroy(&compiler.Base);