*sz = p->nr_insn * sizeof(struct brw_instruction);
return (const GLuint *)p->store;
}
-
-
-
-/**
- * Subroutine calls require special attention.
- * Mesa instructions may be expanded into multiple hardware instructions
- * so the prog_instruction::BranchTarget field can't be used as an index
- * into the hardware instructions.
- *
- * The BranchTarget field isn't needed, however. Mesa's GLSL compiler
- * emits CAL and BGNSUB instructions with labels that can be used to map
- * subroutine calls to actual subroutine code blocks.
- *
- * The structures and function here implement patching of CAL instructions
- * so they jump to the right subroutine code...
- */
-
-
-/**
- * For each OPCODE_BGNSUB we create one of these.
- */
-struct brw_glsl_label
-{
- const char *name; /**< the label string */
- GLuint position; /**< the position of the brw instruction for this label */
- struct brw_glsl_label *next; /**< next in linked list */
-};
-
-
-/**
- * For each OPCODE_CAL we create one of these.
- */
-struct brw_glsl_call
-{
- GLuint call_inst_pos; /**< location of the CAL instruction */
- const char *sub_name; /**< name of subroutine to call */
- struct brw_glsl_call *next; /**< next in linked list */
-};
-
-
-/**
- * Called for each OPCODE_BGNSUB.
- */
-void
-brw_save_label(struct brw_compile *c, const char *name, GLuint position)
-{
- struct brw_glsl_label *label = CALLOC_STRUCT(brw_glsl_label);
- label->name = name;
- label->position = position;
- label->next = c->first_label;
- c->first_label = label;
-}
-
-
-/**
- * Called for each OPCODE_CAL.
- */
-void
-brw_save_call(struct brw_compile *c, const char *name, GLuint call_pos)
-{
- struct brw_glsl_call *call = CALLOC_STRUCT(brw_glsl_call);
- call->call_inst_pos = call_pos;
- call->sub_name = name;
- call->next = c->first_call;
- c->first_call = call;
-}
-
-
-/**
- * Lookup a label, return label's position/offset.
- */
-static GLuint
-brw_lookup_label(struct brw_compile *c, const char *name)
-{
- const struct brw_glsl_label *label;
- for (label = c->first_label; label; label = label->next) {
- if (strcmp(name, label->name) == 0) {
- return label->position;
- }
- }
- abort(); /* should never happen */
- return ~0;
-}
-
-
-/**
- * When we're done generating code, this function is called to resolve
- * subroutine calls.
- */
-void
-brw_resolve_cals(struct brw_compile *c)
-{
- const struct brw_glsl_call *call;
-
- for (call = c->first_call; call; call = call->next) {
- const GLuint sub_loc = brw_lookup_label(c, call->sub_name);
- struct brw_instruction *brw_call_inst = &c->store[call->call_inst_pos];
- struct brw_instruction *brw_sub_inst = &c->store[sub_loc];
- GLint offset = brw_sub_inst - brw_call_inst;
-
- /* patch brw_inst1 to point to brw_inst2 */
- brw_set_src1(c, brw_call_inst, brw_imm_d(offset * 16));
- }
-
- /* free linked list of calls */
- {
- struct brw_glsl_call *call, *next;
- for (call = c->first_call; call; call = next) {
- next = call->next;
- free(call);
- }
- c->first_call = NULL;
- }
-
- /* free linked list of labels */
- {
- struct brw_glsl_label *label, *next;
- for (label = c->first_label; label; label = next) {
- next = label->next;
- free(label);
- }
- c->first_label = NULL;
- }
-}
}
}
- if (c->needs_stack) {
- c->stack = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, reg, 0);
- reg += 2;
- }
-
/* Some opcodes need an internal temporary:
*/
c->first_tmp = reg;
struct intel_context *intel = &brw->intel;
const GLuint nr_insns = c->vp->program.Base.NumInstructions;
GLuint insn;
- const struct brw_indirect stack_index = brw_indirect(0, 0);
GLuint index;
GLuint file;
if (file == PROGRAM_OUTPUT && index != VERT_RESULT_HPOS)
c->output_regs[index].used_in_src = true;
}
-
- switch (inst->Opcode) {
- case OPCODE_CAL:
- case OPCODE_RET:
- c->needs_stack = true;
- break;
- default:
- break;
- }
}
/* Static register allocation
brw_vs_rescale_gl_fixed(c);
- if (c->needs_stack)
- brw_MOV(p, get_addr_reg(stack_index), brw_address(c->stack));
-
for (insn = 0; insn < nr_insns; insn++) {
const struct prog_instruction *inst = &c->vp->program.Base.Instructions[insn];
brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16));
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
break;
- case OPCODE_CAL:
- brw_set_access_mode(p, BRW_ALIGN_1);
- brw_ADD(p, deref_1d(stack_index, 0), brw_ip_reg(), brw_imm_d(3*16));
- brw_set_access_mode(p, BRW_ALIGN_16);
- brw_ADD(p, get_addr_reg(stack_index),
- get_addr_reg(stack_index), brw_imm_d(4));
- brw_save_call(p, inst->Comment, p->nr_insn);
- brw_ADD(p, brw_ip_reg(), brw_ip_reg(), brw_imm_d(1*16));
- break;
- case OPCODE_RET:
- brw_ADD(p, get_addr_reg(stack_index),
- get_addr_reg(stack_index), brw_imm_d(-4));
- brw_set_access_mode(p, BRW_ALIGN_1);
- brw_MOV(p, brw_ip_reg(), deref_1d(stack_index, 0));
- brw_set_access_mode(p, BRW_ALIGN_16);
- break;
case OPCODE_END:
emit_vertex_write(c);
break;
case OPCODE_PRINT:
/* no-op */
break;
- case OPCODE_BGNSUB:
- brw_save_label(p, inst->Comment, p->nr_insn);
- break;
- case OPCODE_ENDSUB:
- /* no-op */
- break;
default:
_mesa_problem(NULL, "Unsupported opcode %i (%s) in vertex shader",
inst->Opcode, inst->Opcode < MAX_OPCODE ?
release_tmps(c);
}
- brw_resolve_cals(p);
brw_set_uip_jip(p);
brw_optimize(p);