<p dir="ltr"><br>
On Jul 13, 2015 7:14 AM, "Alejandro Piñeiro" <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>> wrote:<br>
><br>
><br>
><br>
> On 13/07/15 14:05, Jason Ekstrand wrote:<br>
> > On Mon, Jul 13, 2015 at 3:00 AM, Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>> wrote:<br>
> >> On 01/07/15 01:37, Jason Ekstrand wrote:<br>
> >>> If we can avoid duplication in the texturing code, that would be<br>
> >>> really nice.  Could we do this as a refactor of the old code and then<br>
> >>> a much smaller NIR function that calls some shared code?  That's what<br>
> >>> we did for FS and it worked ok.  I looked at the layout of your code<br>
> >>> and, after you finish reading instruction inputs, very little of it is<br>
> >>> actually NIR-specific.<br>
> >> Our wip second batch of commits has now a version that refactors the old<br>
> >> code. But I have a doubt. As part of this refactor, I created a new<br>
> >> method to be used by brw_fs and brw_vec4, that returns the ir texture<br>
> >> opcode based on the nir texture opcode. You can take a look to that<br>
> >> method here [1]. The issue with this method is that ir_texture_opcode is<br>
> >> defined at glsl/ir.h inside a #ifdef __cplusplus. So I needed to rename<br>
> >> brw_nir.c to brw_nir.cpp. On a previous early review [2] you mentioned<br>
> >> that it would be better to keep it as brw_nir.c unless we have a good<br>
> >> reason. Is using this enum good reason to do the renaming? If not, the<br>
> >> other option I see is modify glsl/ir.h and move the enum definitions to<br>
> >> the top, outside the ifdef __cplusplus, as other headers (like<br>
> >> glsl/glsl_types.h) have.<br>
> > Go ahead and make it a cpp file if you have to.<br>
><br>
> Ok, thanks.<br>
><br>
> > Another option would<br>
> > be to do the map the other way: ir_opcode -> nir_tex_op and refactor<br>
> > the code to use the nir_tex_op.<br>
><br>
> But even if we do the map in the other way, the helper function would be<br>
> using the enum type defined at glsl/ir.h, so we would need to make it a<br>
> cpp file in any case. So for now, I will keep things simple, and keep<br>
> the current mapping,  and do the change later.</p>
<p dir="ltr">The difference is that, with the patch I sent a few hours ago, you only need to do the conversion one place so there's no need for the helper.</p>
<p dir="ltr">> > That's probably what we should be<br>
> > doing in the FS now that the old visitor is gone.<br>
> > --Jason<br>
> ><br>
> >> BR<br>
> >><br>
> >> [1]<br>
> >> <a href="https://github.com/Igalia/mesa/commit/e81ce150ef931e50b6cb1aae0b42a79f448863f5">https://github.com/Igalia/mesa/commit/e81ce150ef931e50b6cb1aae0b42a79f448863f5</a><br>
> >> [2] <a href="https://bugs.freedesktop.org/show_bug.cgi?id=89580#c7">https://bugs.freedesktop.org/show_bug.cgi?id=89580#c7</a><br>
> >>> --Jason<br>
> >>><br>
> >>> On Fri, Jun 26, 2015 at 1:07 AM, Eduardo Lima Mitev <<a href="mailto:elima@igalia.com">elima@igalia.com</a>> wrote:<br>
> >>>> From: Alejandro Piñeiro <<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>><br>
> >>>><br>
> >>>> This sets up the basic structure and placeholders for the implementation of<br>
> >>>> texture operations, which will be added incrementally in subsequent patches.<br>
> >>>><br>
> >>>> Apart from helping split the texture support into smaller patches, this patch<br>
> >>>> is useful to get a simplified picture of the steps involved in the emission of<br>
> >>>> texture operations.<br>
> >>>><br>
> >>>> Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=89580">https://bugs.freedesktop.org/show_bug.cgi?id=89580</a><br>
> >>>> ---<br>
> >>>>  src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 120 ++++++++++++++++++++++++++++-<br>
> >>>>  1 file changed, 119 insertions(+), 1 deletion(-)<br>
> >>>><br>
> >>>> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >>>> index 08a70b0..c3638a0 100644<br>
> >>>> --- a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >>>> +++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp<br>
> >>>> @@ -1412,7 +1412,125 @@ vec4_visitor::nir_swizzle_result(nir_tex_instr *instr, dst_reg dest,<br>
> >>>>  void<br>
> >>>>  vec4_visitor::nir_emit_texture(nir_tex_instr *instr)<br>
> >>>>  {<br>
> >>>> -   /* @TODO: Not yet implemented */<br>
> >>>> +   unsigned sampler = instr->sampler_index;<br>
> >>>> +   src_reg sampler_reg = src_reg(sampler);<br>
> >>>> +<br>
> >>>> +   const glsl_type *dest_type;<br>
> >>>> +<br>
> >>>> +   /* Load the texture operation sources */<br>
> >>>> +   for (unsigned i = 0; i < instr->num_srcs; i++) {<br>
> >>>> +      src_reg src = get_nir_src(instr->src[i].src);<br>
> >>>> +<br>
> >>>> +      switch (instr->src[i].src_type) {<br>
> >>>> +      case nir_tex_src_comparitor:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_coord:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_ddx:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_ddy:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_lod:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_ms_index:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_offset:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_sampler_offset:<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +         break;<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_projector:<br>
> >>>> +         unreachable("Should be lowered by do_lower_texture_projection");<br>
> >>>> +<br>
> >>>> +      case nir_tex_src_bias:<br>
> >>>> +         unreachable("LOD bias is not valid for vertex shaders.\n");<br>
> >>>> +<br>
> >>>> +      default:<br>
> >>>> +         unreachable("unknown texture source");<br>
> >>>> +      }<br>
> >>>> +   }<br>
> >>>> +<br>
> >>>> +   /* Get the texture operation opcode */<br>
> >>>> +   enum opcode opcode = shader_opcode_for_nir_opcode(instr->op);<br>
> >>>> +<br>
> >>>> +   /* Build the instruction */<br>
> >>>> +   enum glsl_base_type dest_base_type =<br>
> >>>> +      brw_glsl_base_type_for_nir_type(instr->dest_type);<br>
> >>>> +<br>
> >>>> +   dest_type =<br>
> >>>> +      glsl_type::get_instance(dest_base_type, nir_tex_instr_dest_size(instr), 1);<br>
> >>>> +<br>
> >>>> +   vec4_instruction *inst = new(mem_ctx)<br>
> >>>> +      vec4_instruction(opcode, dst_reg(this, dest_type));<br>
> >>>> +<br>
> >>>> +   for (unsigned i = 0; i < 3; i++) {<br>
> >>>> +      if (instr->const_offset[i] != 0) {<br>
> >>>> +         inst->offset = brw_texture_offset(instr->const_offset, 3);<br>
> >>>> +         break;<br>
> >>>> +      }<br>
> >>>> +   }<br>
> >>>> +<br>
> >>>> +   /* The message header is necessary for:<br>
> >>>> +    * - Texel offsets<br>
> >>>> +    * - Gather channel selection<br>
> >>>> +    * - Sampler indices too large to fit in a 4-bit value.<br>
> >>>> +    */<br>
> >>>> +   inst->header_size =<br>
> >>>> +      (inst->offset != 0 ||<br>
> >>>> +       instr->op == nir_texop_tg4 ||<br>
> >>>> +       is_high_sampler(sampler_reg)) ? 1 : 0;<br>
> >>>> +   inst->base_mrf = 2;<br>
> >>>> +   inst->mlen = inst->header_size + 1;<br>
> >>>> +   inst->dst.writemask = WRITEMASK_XYZW;<br>
> >>>> +<br>
> >>>> +   inst->src[1] = sampler_reg;<br>
> >>>> +<br>
> >>>> +   /* Calculate the MRF for the first parameter */<br>
> >>>> +   int param_base = inst->base_mrf + inst->header_size;<br>
> >>>> +<br>
> >>>> +   if (instr->op == nir_texop_txs || instr->op == nir_texop_query_levels) {<br>
> >>>> +      /* @TODO: not yet implemented */<br>
> >>>> +   } else {<br>
> >>>> +      /* @TODO: Load the coordinate */<br>
> >>>> +<br>
> >>>> +      /* @TODO: Load the shadow comparitor */<br>
> >>>> +<br>
> >>>> +      /* Load the LOD info */<br>
> >>>> +      if (instr->op == nir_texop_tex || instr->op == nir_texop_txl) {<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +      } else if (instr->op == nir_texop_txf) {<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +      } else if (instr->op == nir_texop_txf_ms) {<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +      } else if (instr->op == nir_texop_txd) {<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +      } else if (instr->op == nir_texop_tg4) {<br>
> >>>> +         /* @TODO: not yet implemented */<br>
> >>>> +      }<br>
> >>>> +   }<br>
> >>>> +<br>
> >>>> +   /* Emit the instruction */<br>
> >>>> +   emit(inst);<br>
> >>>> +<br>
> >>>> +   /* Move the result to the destination registry, applying swizzle */<br>
> >>>> +   dst_reg dest = get_nir_dest(instr->dest, brw_type_for_base_type(dest_type));<br>
> >>>> +<br>
> >>>> +   nir_swizzle_result(instr, dest, src_reg(inst->dst), sampler, dest_type);<br>
> >>>>  }<br>
> >>>><br>
> >>>>  }<br>
> >>>> --<br>
> >>>> 2.1.4<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>
> >>> _______________________________________________<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>
> >> --<br>
> >> Alejandro Piñeiro (<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>)<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>
><br>
> --<br>
> Alejandro Piñeiro (<a href="mailto:apinheiro@igalia.com">apinheiro@igalia.com</a>)<br>
><br>
</p>