<p dir="ltr"><br>
On Jan 16, 2015 5:30 AM, "Kenneth Graunke" <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br>
><br>
> Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> ---<br>
> src/mesa/drivers/dri/i965/brw_fs.cpp | 5 +--<br>
> src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 73 +++++++++++++++++++++-----------<br>
> 2 files changed, 50 insertions(+), 28 deletions(-)<br>
><br>
> That was easy<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> index b7378de..9572f3a 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> @@ -1035,8 +1035,8 @@ fs_visitor::virtual_grf_alloc(int size)<br>
> fs_reg<br>
> fs_visitor::vgrf(int num_components)<br>
> {<br>
> - return fs_reg(GRF, virtual_grf_alloc(num_components), BRW_REGISTER_TYPE_F,<br>
> - dispatch_width);<br>
> + return fs_reg(GRF, virtual_grf_alloc(num_components * (dispatch_width / 8)),<br>
> + BRW_REGISTER_TYPE_F, dispatch_width);<br>
> }</p>
<p dir="ltr">For fs_visitor, we use a constructor that takes a fs_visotor and a glsl_type. I kind of prefer this in fs_visitor over fs_reg. Maybe we should move the fs_reg(fs_visitor, glsl_type) constructor to be a vgrf(glsl_type) function? That doesn't have to be part of this though.</p>
<p dir="ltr">><br>
> /** Fixed HW reg constructor. */<br>
> @@ -3759,7 +3759,6 @@ fs_visitor::run_fs()<br>
> */<br>
> if (shader) {<br>
> if (getenv("INTEL_USE_NIR") != NULL && !brw->use_rep_send) {</p>
<p dir="ltr">You can kill the !brw->use_rep_send now. It was only there to keep us from GPU-hanging on rep and fast clears due to having no shaders at all. Since we have SIMD16 in NIR, we don't need it anymore.</p>
<p dir="ltr">> - no16("Cannot do 16-wide in NIR yet");<br>
> emit_nir_code();<br>
> } else {<br>
> foreach_in_list(ir_instruction, ir, shader-><a href="http://base.ir">base.ir</a>) {<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> index fca03e5..5208985 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> @@ -132,12 +132,14 @@ fs_visitor::emit_nir_code()<br>
> void<br>
> fs_visitor::nir_setup_inputs(nir_shader *shader)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> fs_reg varying = nir_inputs;<br>
><br>
> struct hash_entry *entry;<br>
> hash_table_foreach(shader->inputs, entry) {<br>
> nir_variable *var = (nir_variable *) entry->data;<br>
> - varying.reg_offset = var->data.driver_location;<br>
> + varying.reg_offset = var->data.driver_location * reg_width;<br>
><br>
> fs_reg reg;<br>
> if (!strcmp(var->name, "gl_FragCoord")) {<br>
> @@ -159,13 +161,15 @@ fs_visitor::nir_setup_inputs(nir_shader *shader)<br>
> void<br>
> fs_visitor::nir_setup_outputs(nir_shader *shader)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> brw_wm_prog_key *key = (brw_wm_prog_key*) this->key;<br>
> fs_reg reg = nir_outputs;<br>
><br>
> struct hash_entry *entry;<br>
> hash_table_foreach(shader->outputs, entry) {<br>
> nir_variable *var = (nir_variable *) entry->data;<br>
> - reg.reg_offset = var->data.driver_location;<br>
> + reg.reg_offset = var->data.driver_location * reg_width;<br>
><br>
> if (var->data.index > 0) {<br>
> assert(var->data.location == FRAG_RESULT_DATA0);<br>
> @@ -195,7 +199,8 @@ fs_visitor::nir_setup_outputs(nir_shader *shader)<br>
> for (unsigned int i = 0; i < MAX2(1, var->type->length); i++) {<br>
> int output = var->data.location - FRAG_RESULT_DATA0 + i;<br>
> this->outputs[output] = reg;<br>
> - this->outputs[output].reg_offset += vector_elements * i;<br>
> + this->outputs[output].reg_offset +=<br>
> + (vector_elements * i) * reg_width;</p>
<p dir="ltr">Assuming the register width is correct, you can just use reg = offset(reg, vector_elements *i) here and offset() will deal with the width. Connor originally wrote the NIR->FS pass while I was in the middle of my SIMD16 stuff so it didn't get incorporated.</p>
<p dir="ltr">I could repeat the above comment through the patch. Also, replacing everything with offset() can be done as its own patch before flipping the switch.</p>
<p dir="ltr">> this->output_components[output] = vector_elements;<br>
> }<br>
> }<br>
> @@ -1035,6 +1040,8 @@ fs_visitor::nir_emit_alu(nir_alu_instr *instr)<br>
> fs_reg<br>
> fs_visitor::get_nir_src(nir_src src)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> if (src.is_ssa) {<br>
> assert(src.ssa->parent_instr->type == nir_instr_type_load_const);<br>
> nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);<br>
> @@ -1057,7 +1064,7 @@ fs_visitor::get_nir_src(nir_src src)<br>
> * this to F if they need to<br>
> */<br>
> reg.type = BRW_REGISTER_TYPE_D;<br>
> - reg.reg_offset = src.reg.base_offset;<br>
> + reg.reg_offset = src.reg.base_offset * reg_width;<br>
> if (src.reg.indirect) {<br>
> reg.reladdr = new(mem_ctx) fs_reg();<br>
> *reg.reladdr = retype(get_nir_src(*src.reg.indirect),<br>
> @@ -1111,13 +1118,15 @@ fs_visitor::get_nir_alu_src(nir_alu_instr *instr, unsigned src)<br>
> fs_reg<br>
> fs_visitor::get_nir_dest(nir_dest dest)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> fs_reg reg;<br>
> if (dest.reg.reg->is_global)<br>
> reg = nir_globals[dest.reg.reg->index];<br>
> else<br>
> reg = nir_locals[dest.reg.reg->index];<br>
><br>
> - reg.reg_offset = dest.reg.base_offset;<br>
> + reg.reg_offset = dest.reg.base_offset * reg_width;<br>
> if (dest.reg.indirect) {<br>
> reg.reladdr = new(mem_ctx) fs_reg();<br>
> *reg.reladdr = retype(get_nir_src(*dest.reg.indirect),<br>
> @@ -1130,15 +1139,17 @@ fs_visitor::get_nir_dest(nir_dest dest)<br>
> void<br>
> fs_visitor::emit_percomp(fs_inst *inst, unsigned wr_mask)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> for (unsigned i = 0; i < 4; i++) {<br>
> if (!((wr_mask >> i) & 1))<br>
> continue;<br>
><br>
> fs_inst *new_inst = new(mem_ctx) fs_inst(*inst);<br>
> - new_inst->dst.reg_offset += i;<br>
> + new_inst->dst.reg_offset += i * reg_width;<br>
> for (unsigned j = 0; j < new_inst->sources; j++)<br>
> if (inst->src[j].file == GRF)<br>
> - new_inst->src[j].reg_offset += i;<br>
> + new_inst->src[j].reg_offset += i * reg_width;<br>
><br>
> emit(new_inst);<br>
> }<br>
> @@ -1150,15 +1161,17 @@ fs_visitor::emit_percomp(enum opcode op, fs_reg dest, fs_reg src0,<br>
> enum brw_predicate predicate,<br>
> enum brw_conditional_mod mod)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> for (unsigned i = 0; i < 4; i++) {<br>
> if (!((wr_mask >> i) & 1))<br>
> continue;<br>
><br>
> fs_inst *new_inst = new(mem_ctx) fs_inst(op, dest, src0);<br>
> - new_inst->dst.reg_offset += i;<br>
> + new_inst->dst.reg_offset += i * reg_width;<br>
> for (unsigned j = 0; j < new_inst->sources; j++)<br>
> if (new_inst->src[j].file == GRF)<br>
> - new_inst->src[j].reg_offset += i;<br>
> + new_inst->src[j].reg_offset += i * reg_width;<br>
><br>
> new_inst->predicate = predicate;<br>
> new_inst->conditional_mod = mod;<br>
> @@ -1173,15 +1186,17 @@ fs_visitor::emit_percomp(enum opcode op, fs_reg dest, fs_reg src0, fs_reg src1,<br>
> enum brw_predicate predicate,<br>
> enum brw_conditional_mod mod)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> for (unsigned i = 0; i < 4; i++) {<br>
> if (!((wr_mask >> i) & 1))<br>
> continue;<br>
><br>
> fs_inst *new_inst = new(mem_ctx) fs_inst(op, dest, src0, src1);<br>
> - new_inst->dst.reg_offset += i;<br>
> + new_inst->dst.reg_offset += i * reg_width;<br>
> for (unsigned j = 0; j < new_inst->sources; j++)<br>
> if (new_inst->src[j].file == GRF)<br>
> - new_inst->src[j].reg_offset += i;<br>
> + new_inst->src[j].reg_offset += i * reg_width;<br>
><br>
> new_inst->predicate = predicate;<br>
> new_inst->conditional_mod = mod;<br>
> @@ -1194,15 +1209,17 @@ void<br>
> fs_visitor::emit_math_percomp(enum opcode op, fs_reg dest, fs_reg src0,<br>
> unsigned wr_mask, bool saturate)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> for (unsigned i = 0; i < 4; i++) {<br>
> if (!((wr_mask >> i) & 1))<br>
> continue;<br>
><br>
> fs_reg new_dest = dest;<br>
> - new_dest.reg_offset += i;<br>
> + new_dest.reg_offset += i * reg_width;<br>
> fs_reg new_src0 = src0;<br>
> if (src0.file == GRF)<br>
> - new_src0.reg_offset += i;<br>
> + new_src0.reg_offset += i * reg_width;<br>
><br>
> fs_inst *new_inst = emit_math(op, new_dest, new_src0);<br>
> new_inst->saturate = saturate;<br>
> @@ -1214,18 +1231,20 @@ fs_visitor::emit_math_percomp(enum opcode op, fs_reg dest, fs_reg src0,<br>
> fs_reg src1, unsigned wr_mask,<br>
> bool saturate)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> for (unsigned i = 0; i < 4; i++) {<br>
> if (!((wr_mask >> i) & 1))<br>
> continue;<br>
><br>
> fs_reg new_dest = dest;<br>
> - new_dest.reg_offset += i;<br>
> + new_dest.reg_offset += i * reg_width;<br>
> fs_reg new_src0 = src0;<br>
> if (src0.file == GRF)<br>
> - new_src0.reg_offset += i;<br>
> + new_src0.reg_offset += i * reg_width;<br>
> fs_reg new_src1 = src1;<br>
> if (src1.file == GRF)<br>
> - new_src1.reg_offset += i;<br>
> + new_src1.reg_offset += i * reg_width;<br>
><br>
> fs_inst *new_inst = emit_math(op, new_dest, new_src0, new_src1);<br>
> new_inst->saturate = saturate;<br>
> @@ -1236,9 +1255,11 @@ void<br>
> fs_visitor::emit_reduction(enum opcode op, fs_reg dest, fs_reg src,<br>
> unsigned num_components)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> fs_reg src0 = src;<br>
> fs_reg src1 = src;<br>
> - src1.reg_offset++;<br>
> + src1.reg_offset += 1 * reg_width;<br>
><br>
> if (num_components == 2) {<br>
> emit(op, dest, src0, src1);<br>
> @@ -1250,7 +1271,7 @@ fs_visitor::emit_reduction(enum opcode op, fs_reg dest, fs_reg src,<br>
> emit(op, temp1, src0, src1);<br>
><br>
> fs_reg src2 = src;<br>
> - src2.reg_offset += 2;<br>
> + src2.reg_offset += 2 * reg_width;<br>
><br>
> if (num_components == 3) {<br>
> emit(op, dest, temp1, src2);<br>
> @@ -1260,7 +1281,7 @@ fs_visitor::emit_reduction(enum opcode op, fs_reg dest, fs_reg src,<br>
> assert(num_components == 4);<br>
><br>
> fs_reg src3 = src;<br>
> - src3.reg_offset += 3;<br>
> + src3.reg_offset += 3 * reg_width;<br>
> fs_reg temp2 = vgrf(1);<br>
> temp2.type = src.type;<br>
><br>
> @@ -1271,6 +1292,8 @@ fs_visitor::emit_reduction(enum opcode op, fs_reg dest, fs_reg src,<br>
> void<br>
> fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)<br>
> {<br>
> + int reg_width = dispatch_width / 8;<br>
> +<br>
> fs_reg dest;<br>
> if (nir_intrinsic_infos[instr->intrinsic].has_dest)<br>
> dest = get_nir_dest(instr->dest);<br>
> @@ -1374,7 +1397,7 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)<br>
> index++;<br>
><br>
> emit(MOV(dest, src));<br>
> - dest.reg_offset++;<br>
> + dest.reg_offset += 1 * reg_width;<br>
> }<br>
> }<br>
> break;<br>
> @@ -1435,7 +1458,7 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)<br>
> assert(packed_consts.subreg_offset < 32);<br>
><br>
> emit(MOV(dest, packed_consts));<br>
> - dest.reg_offset++;<br>
> + dest.reg_offset += 1 * reg_width;<br>
> }<br>
> }<br>
> break;<br>
> @@ -1448,14 +1471,14 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)<br>
> for (int i = 0; i < instr->const_index[1]; i++) {<br>
> for (unsigned j = 0; j < instr->num_components; j++) {<br>
> fs_reg src = nir_inputs;<br>
> - src.reg_offset = instr->const_index[0] + index;<br>
> + src.reg_offset = (instr->const_index[0] + index) * reg_width;<br>
> if (has_indirect)<br>
> src.reladdr = new(mem_ctx) fs_reg(get_nir_src(instr->src[0]));<br>
> src.type = dest.type;<br>
> index++;<br>
><br>
> emit(MOV(dest, src));<br>
> - dest.reg_offset++;<br>
> + dest.reg_offset += 1 * reg_width;<br>
> }<br>
> }<br>
> break;<br>
> @@ -1587,13 +1610,13 @@ fs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)<br>
> for (int i = 0; i < instr->const_index[1]; i++) {<br>
> for (unsigned j = 0; j < instr->num_components; j++) {<br>
> fs_reg new_dest = nir_outputs;<br>
> - new_dest.reg_offset = instr->const_index[0] + index;<br>
> + new_dest.reg_offset = (instr->const_index[0] + index) * reg_width;<br>
> if (has_indirect)<br>
> src.reladdr = new(mem_ctx) fs_reg(get_nir_src(instr->src[1]));<br>
> new_dest.type = src.type;<br>
> index++;<br>
> emit(MOV(new_dest, src));<br>
> - src.reg_offset++;<br>
> + src.reg_offset += 1 * reg_width;<br>
> }<br>
> }<br>
> break;<br>
> --<br>
> 2.2.2<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>