*/
#include "brw_vec4.h"
-#include "glsl/ir_print_visitor.h"
extern "C" {
#include "brw_eu.h"
+#include "main/macros.h"
+#include "program/prog_print.h"
+#include "program/prog_parameter.h"
};
-using namespace brw;
-
namespace brw {
-int
-vec4_visitor::setup_attributes(int payload_reg)
-{
- int nr_attributes;
- int attribute_map[VERT_ATTRIB_MAX + 1];
-
- nr_attributes = 0;
- for (int i = 0; i < VERT_ATTRIB_MAX; i++) {
- if (prog_data->inputs_read & BITFIELD64_BIT(i)) {
- attribute_map[i] = payload_reg + nr_attributes;
- nr_attributes++;
- }
- }
-
- /* VertexID is stored by the VF as the last vertex element, but we
- * don't represent it with a flag in inputs_read, so we call it
- * VERT_ATTRIB_MAX.
- */
- if (prog_data->uses_vertexid) {
- attribute_map[VERT_ATTRIB_MAX] = payload_reg + nr_attributes;
- nr_attributes++;
- }
-
- foreach_list(node, &this->instructions) {
- vec4_instruction *inst = (vec4_instruction *)node;
-
- /* We have to support ATTR as a destination for GL_FIXED fixup. */
- if (inst->dst.file == ATTR) {
- int grf = attribute_map[inst->dst.reg + inst->dst.reg_offset];
-
- struct brw_reg reg = brw_vec8_grf(grf, 0);
- reg.dw1.bits.writemask = inst->dst.writemask;
-
- inst->dst.file = HW_REG;
- inst->dst.fixed_hw_reg = reg;
- }
-
- for (int i = 0; i < 3; i++) {
- if (inst->src[i].file != ATTR)
- continue;
-
- int grf = attribute_map[inst->src[i].reg + inst->src[i].reg_offset];
-
- struct brw_reg reg = brw_vec8_grf(grf, 0);
- reg.dw1.bits.swizzle = inst->src[i].swizzle;
- reg.type = inst->src[i].type;
- if (inst->src[i].abs)
- reg = brw_abs(reg);
- if (inst->src[i].negate)
- reg = negate(reg);
-
- inst->src[i].file = HW_REG;
- inst->src[i].fixed_hw_reg = reg;
- }
- }
-
- /* The BSpec says we always have to read at least one thing from
- * the VF, and it appears that the hardware wedges otherwise.
- */
- if (nr_attributes == 0)
- nr_attributes = 1;
-
- prog_data->urb_read_length = (nr_attributes + 1) / 2;
-
- return payload_reg + nr_attributes;
-}
-
-int
-vec4_visitor::setup_uniforms(int reg)
-{
- /* The pre-gen6 VS requires that some push constants get loaded no
- * matter what, or the GPU would hang.
- */
- if (intel->gen < 6 && this->uniforms == 0) {
- this->uniform_vector_size[this->uniforms] = 1;
-
- for (unsigned int i = 0; i < 4; i++) {
- unsigned int slot = this->uniforms * 4 + i;
- static float zero = 0.0;
- c->prog_data.param[slot] = &zero;
- }
-
- this->uniforms++;
- reg++;
- } else {
- reg += ALIGN(uniforms, 2) / 2;
- }
-
- c->prog_data.nr_params = this->uniforms * 4;
-
- c->prog_data.curb_read_length = reg - 1;
- c->prog_data.uses_new_param_layout = true;
-
- return reg;
-}
-
-void
-vec4_visitor::setup_payload(void)
-{
- int reg = 0;
-
- /* The payload always contains important data in g0, which contains
- * the URB handles that are passed on to the URB write at the end
- * of the thread. So, we always start push constants at g1.
- */
- reg++;
-
- reg = setup_uniforms(reg);
-
- reg = setup_attributes(reg);
-
- this->first_non_payload_grf = reg;
-}
-
struct brw_reg
vec4_instruction::get_dst(void)
{
brw_math(p,
dst,
brw_math_function(inst->opcode),
- BRW_MATH_SATURATE_NONE,
inst->base_mrf,
src,
BRW_MATH_DATA_VECTOR,
brw_math(p,
dst,
brw_math_function(inst->opcode),
- BRW_MATH_SATURATE_NONE,
inst->base_mrf,
src,
BRW_MATH_DATA_SCALAR,
struct brw_reg &op0 = is_int_div ? src1 : src0;
struct brw_reg &op1 = is_int_div ? src0 : src1;
+ brw_push_insn_state(p);
+ brw_set_saturate(p, false);
+ brw_set_predicate_control(p, BRW_PREDICATE_NONE);
brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), op1.type), op1);
+ brw_pop_insn_state(p);
brw_math(p,
dst,
brw_math_function(inst->opcode),
- BRW_MATH_SATURATE_NONE,
inst->base_mrf,
op0,
BRW_MATH_DATA_VECTOR,
dst,
inst->base_mrf,
src,
- SURF_INDEX_TEXTURE(inst->sampler),
+ SURF_INDEX_VS_TEXTURE(inst->sampler),
inst->sampler,
WRITEMASK_XYZW,
msg_type,
brw_MOV(p, m1_0, index_0);
- brw_set_predicate_inverse(p, true);
if (index.file == BRW_IMMEDIATE_VALUE) {
index_4.dw1.ud += second_vertex_offset;
brw_MOV(p, m1_4, index_4);
void
vec4_visitor::generate_pull_constant_load(vec4_instruction *inst,
struct brw_reg dst,
- struct brw_reg index)
+ struct brw_reg index,
+ struct brw_reg offset)
{
+ assert(index.file == BRW_IMMEDIATE_VALUE &&
+ index.type == BRW_REGISTER_TYPE_UD);
+ uint32_t surf_index = index.dw1.ud;
+
+ if (intel->gen == 7) {
+ gen6_resolve_implied_move(p, &offset, inst->base_mrf);
+ brw_instruction *insn = brw_next_insn(p, BRW_OPCODE_SEND);
+ brw_set_dest(p, insn, dst);
+ brw_set_src0(p, insn, offset);
+ brw_set_sampler_message(p, insn,
+ surf_index,
+ 0, /* LD message ignores sampler unit */
+ GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
+ 1, /* rlen */
+ 1, /* mlen */
+ false, /* no header */
+ BRW_SAMPLER_SIMD_MODE_SIMD4X2,
+ 0);
+ return;
+ }
+
struct brw_reg header = brw_vec8_grf(0, 0);
gen6_resolve_implied_move(p, &header, inst->base_mrf);
brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_D),
- index);
+ offset);
uint32_t msg_type;
if (intel->gen < 6)
send->header.destreg__conditionalmod = inst->base_mrf;
brw_set_dp_read_message(p, send,
- SURF_INDEX_VERT_CONST_BUFFER,
+ surf_index,
BRW_DATAPORT_OWORD_DUAL_BLOCK_1OWORD,
msg_type,
BRW_DATAPORT_READ_TARGET_DATA_CACHE,
break;
case VS_OPCODE_PULL_CONSTANT_LOAD:
- generate_pull_constant_load(inst, dst, src[0]);
+ generate_pull_constant_load(inst, dst, src[0], src[1]);
break;
default:
- if (inst->opcode < (int)ARRAY_SIZE(brw_opcodes)) {
- fail("unsupported opcode in `%s' in VS\n",
- brw_opcodes[inst->opcode].name);
+ if (inst->opcode < (int) ARRAY_SIZE(opcode_descs)) {
+ _mesa_problem(ctx, "Unsupported opcode in `%s' in VS\n",
+ opcode_descs[inst->opcode].name);
} else {
- fail("Unsupported opcode %d in VS", inst->opcode);
+ _mesa_problem(ctx, "Unsupported opcode %d in VS", inst->opcode);
}
+ abort();
}
}
-bool
-vec4_visitor::run()
-{
- if (c->key.userclip_active && !c->key.uses_clip_distance)
- setup_uniform_clipplane_values();
-
- /* Generate VS IR for main(). (the visitor only descends into
- * functions called "main").
- */
- visit_instructions(shader->ir);
-
- emit_urb_writes();
-
- /* Before any optimization, push array accesses out to scratch
- * space where we need them to be. This pass may allocate new
- * virtual GRFs, so we want to do it early. It also makes sure
- * that we have reladdr computations available for CSE, since we'll
- * often do repeated subexpressions for those.
- */
- move_grf_array_access_to_scratch();
- move_uniform_array_access_to_pull_constants();
- pack_uniform_registers();
- move_push_constants_to_pull_constants();
-
- bool progress;
- do {
- progress = false;
- progress = dead_code_eliminate() || progress;
- progress = opt_copy_propagation() || progress;
- progress = opt_algebraic() || progress;
- progress = opt_compute_to_mrf() || progress;
- } while (progress);
-
-
- if (failed)
- return false;
-
- setup_payload();
- reg_allocate();
-
- if (failed)
- return false;
-
- brw_set_access_mode(p, BRW_ALIGN_16);
-
- generate_code();
-
- return !failed;
-}
-
void
vec4_visitor::generate_code()
{
- int last_native_inst = 0;
+ int last_native_insn_offset = 0;
const char *last_annotation_string = NULL;
- ir_instruction *last_annotation_ir = NULL;
-
- int loop_stack_array_size = 16;
- int loop_stack_depth = 0;
- int *if_depth_in_loop =
- rzalloc_array(this->mem_ctx, int, loop_stack_array_size);
-
+ const void *last_annotation_ir = NULL;
if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
- printf("Native code for vertex shader %d:\n", prog->Name);
+ if (shader) {
+ printf("Native code for vertex shader %d:\n", prog->Name);
+ } else {
+ printf("Native code for vertex program %d:\n", c->vp->program.Base.Id);
+ }
}
foreach_list(node, &this->instructions) {
last_annotation_ir = inst->ir;
if (last_annotation_ir) {
printf(" ");
- last_annotation_ir->print();
+ if (shader) {
+ ((ir_instruction *) last_annotation_ir)->print();
+ } else {
+ const prog_instruction *vpi;
+ vpi = (const prog_instruction *) inst->ir;
+ printf("%d: ", (int)(vpi - vp->Base.Instructions));
+ _mesa_fprint_instruction_opt(stdout, vpi, 0,
+ PROG_PRINT_DEBUG, NULL);
+ }
printf("\n");
}
}
brw_SEL(p, dst, src[0], src[1]);
break;
+ case BRW_OPCODE_DPH:
+ brw_DPH(p, dst, src[0], src[1]);
+ break;
+
case BRW_OPCODE_DP4:
brw_DP4(p, dst, src[0], src[1]);
break;
struct brw_instruction *brw_inst = brw_IF(p, BRW_EXECUTE_8);
brw_inst->header.predicate_control = inst->predicate;
}
- if_depth_in_loop[loop_stack_depth]++;
break;
case BRW_OPCODE_ELSE:
break;
case BRW_OPCODE_ENDIF:
brw_ENDIF(p);
- if_depth_in_loop[loop_stack_depth]--;
break;
case BRW_OPCODE_DO:
brw_DO(p, BRW_EXECUTE_8);
- loop_stack_depth++;
- if (loop_stack_array_size <= loop_stack_depth) {
- loop_stack_array_size *= 2;
- if_depth_in_loop = reralloc(this->mem_ctx, if_depth_in_loop, int,
- loop_stack_array_size);
- }
- if_depth_in_loop[loop_stack_depth] = 0;
break;
case BRW_OPCODE_BREAK:
- brw_BREAK(p, if_depth_in_loop[loop_stack_depth]);
+ brw_BREAK(p);
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
break;
case BRW_OPCODE_CONTINUE:
if (intel->gen >= 6)
gen6_CONT(p);
else
- brw_CONT(p, if_depth_in_loop[loop_stack_depth]);
+ brw_CONT(p);
brw_set_predicate_control(p, BRW_PREDICATE_NONE);
break;
case BRW_OPCODE_WHILE:
- assert(loop_stack_depth > 0);
- loop_stack_depth--;
brw_WHILE(p);
break;
}
if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
- for (unsigned int i = last_native_inst; i < p->nr_insn; i++) {
- if (0) {
- printf("0x%08x 0x%08x 0x%08x 0x%08x ",
- ((uint32_t *)&p->store[i])[3],
- ((uint32_t *)&p->store[i])[2],
- ((uint32_t *)&p->store[i])[1],
- ((uint32_t *)&p->store[i])[0]);
- }
- brw_disasm(stdout, &p->store[i], intel->gen);
- }
+ brw_dump_compile(p, stdout,
+ last_native_insn_offset, p->next_insn_offset);
}
- last_native_inst = p->nr_insn;
+ last_native_insn_offset = p->next_insn_offset;
}
if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
printf("\n");
}
- ralloc_free(if_depth_in_loop);
-
brw_set_uip_jip(p);
/* OK, while the INTEL_DEBUG=vs above is very nice for debugging VS
* which is often something we want to debug. So this is here in
* case you're doing that.
*/
- if (0) {
- if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
- for (unsigned int i = 0; i < p->nr_insn; i++) {
- printf("0x%08x 0x%08x 0x%08x 0x%08x ",
- ((uint32_t *)&p->store[i])[3],
- ((uint32_t *)&p->store[i])[2],
- ((uint32_t *)&p->store[i])[1],
- ((uint32_t *)&p->store[i])[0]);
- brw_disasm(stdout, &p->store[i], intel->gen);
- }
- }
+ if (0 && unlikely(INTEL_DEBUG & DEBUG_VS)) {
+ brw_dump_compile(p, stdout, 0, p->next_insn_offset);
}
}
-extern "C" {
-
-bool
-brw_vs_emit(struct gl_shader_program *prog, struct brw_vs_compile *c)
-{
- if (!prog)
- return false;
-
- struct brw_shader *shader =
- (brw_shader *) prog->_LinkedShaders[MESA_SHADER_VERTEX];
- if (!shader)
- return false;
-
- if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
- printf("GLSL IR for native vertex shader %d:\n", prog->Name);
- _mesa_print_ir(shader->ir, NULL);
- printf("\n\n");
- }
-
- vec4_visitor v(c, prog, shader);
- if (!v.run()) {
- prog->LinkStatus = false;
- ralloc_strcat(&prog->InfoLog, v.fail_msg);
- return false;
- }
-
- return true;
-}
-
-} /* extern "C" */
-
} /* namespace brw */