<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 13/03/18 19:23, Jason Ekstrand
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAOFGe97vgr6-Xdza-HSARbAmG5bF7ZohVxUGZy2ZmO+XNE_pFg@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">On Tue, Mar 13, 2018 at 5:40 AM,
            Samuel Iglesias Gonsálvez <span dir="ltr"><<a
                href="mailto:siglesias@igalia.com" target="_blank"
                moz-do-not-send="true">siglesias@igalia.com</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex"><span
                class="">OpSConvert interprets the MSB of the unsigned
                value as the sign bit and<br>
                extends it to the new type. If we want to preserve the
                value, we need<br>
                to use OpUConvert opcode.<br>
                <br>
                v2:<br>
                - No need to check dst type.<br>
                - Fix typo in comment.<br>
                <br>
              </span>v3:<br>
              - Use src/dst bitsize to get the proper conversion opcode.
              (Jason)<br>
              <span class=""><br>
                Signed-off-by: Samuel Iglesias Gonsálvez <<a
                  href="mailto:siglesias@igalia.com"
                  moz-do-not-send="true">siglesias@igalia.com</a>><br>
                ---<br>
              </span> src/compiler/spirv/vtn_alu.c | 11 ++++++++++-<br>
               1 file changed, 10 insertions(+), 1 deletion(-)<br>
              <br>
              diff --git a/src/compiler/spirv/vtn_alu.c
              b/src/compiler/spirv/vtn_alu.c<br>
              index d0c9e316935..9dcd183a48d 100644<br>
              --- a/src/compiler/spirv/vtn_alu.c<br>
              +++ b/src/compiler/spirv/vtn_alu.c<br>
              @@ -354,10 +354,19 @@ vtn_nir_alu_op_for_spirv_<wbr>opcode(struct
              vtn_builder *b,<br>
              <span class="">    case SpvOpConvertFToS:<br>
                    case SpvOpConvertSToF:<br>
                    case SpvOpConvertUToF:<br>
              </span></blockquote>
            <div><br>
            </div>
            <div>We probably need to fix SToF and UToF as well.<br>
              <br>
            </div>
            <div>I'm starting to wonder if we don't want to do them all
              at once.  Maybe something like this:<br>
              <br>
            </div>
            <div>nir_alu_type src_type;<br>
            </div>
            <div>switch (opcode) {<br>
            </div>
            <div>case SpvOpConvertFToS:<br>
            </div>
            <div>case SpvOpConvertFToU:<br>
            </div>
            <div>case SpvOpFConvert:<br>
            </div>
            <div>   src_type = nir_type_float;<br>
            </div>
            <div>   break;<br>
            </div>
            <div>case SpvOpConvertSToF:<br>
            </div>
            <div>case SpvOpSConvert:<br>
            </div>
            <div>   src_type = nir_type_int;<br>
            </div>
            <div>   break;<br>
            </div>
            <div>case SpvOpConvertUToF:<br>
            </div>
            <div>case SpvOpUConvert:<br>
            </div>
            <div>   src_type = nir_type_uint;<br>
            </div>
            <div>   break;<br>
            </div>
            <div>default:<br>
            </div>
            <div>   unreachable("Invalid opcode");<br>
            </div>
            <div>}<br>
            </div>
            <div>src_type |= nir_alu_type_get_type_size(<wbr>src);<br>
              <span class="gmail-"><br>
              </span></div>
            <div>
              <div>nir_alu_type dst_type;<br>
              </div>
              <div>switch (opcode) {<br>
              </div>
              ...<br>
              <div>default:<br>
              </div>
              <div>   unreachable("Invalid opcode");<br>
              </div>
              <div>}<br>
              </div>
              <div>dst_type |= nir_alu_type_get_type_size(dst);<br>
                <br>
              </div>
              <div>While we're at it, since types don't really matter
                (only bit sizes), maybe nir_alu_op_for_spirv_opcode
                should just take bit sizes instead of types.  It would
                make things simpler and make it more obvious what data
                actually gets used.<br>
                <br>
              </div>
              <div>Sorry I didn't notice the other conversion opcodes
                earlier. :-(<br>
              </div>
              <span class="gmail-"></span></div>
            <div> </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    No prob. I am going to send a couple of patches, one generalizing
    the solution and another changing the arguments of
    vtn_nir_alu_op_for_spirv_opcode() to receive the bit size of source
    and destination.<br>
    <br>
    Thanks for the feedback!<br>
    <br>
    Sam<br>
    <br>
    <blockquote type="cite"
cite="mid:CAOFGe97vgr6-Xdza-HSARbAmG5bF7ZohVxUGZy2ZmO+XNE_pFg@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex"><span
                class="">
                -   case SpvOpSConvert:<br>
                    case SpvOpFConvert:<br>
                       return nir_type_conversion_op(src, dst,
                nir_rounding_mode_undef);<br>
                <br>
                +   case SpvOpSConvert: {<br>
              </span>+      /* SPIR-V expects to interpret the unsigned
              value as signed and<br>
              +       * sign extend. Return the opcode accordingly.<br>
              +       */<br>
              +      unsigned src_bit_size = nir_alu_type_get_type_size(<wbr>src);<br>
              +      nir_alu_type src_type = nir_type_int |
              src_bit_size; <br>
            </blockquote>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <span class="">+      unsigned dst_bit_size =
                nir_alu_type_get_type_size(<wbr>dst);<br>
              </span>+      nir_alu_type dst_type = nir_type_int |
              dst_bit_size;<br>
              +      return nir_type_conversion_op(src_<wbr>type,
              dst_type, nir_rounding_mode_undef);<br>
              <div class="HOEnZb">
                <div class="h5">+   }<br>
                      /* Derivatives: */<br>
                      case SpvOpDPdx:         return nir_op_fddx;<br>
                      case SpvOpDPdy:         return nir_op_fddy;<br>
                  --<br>
                  2.14.1<br>
                  <br>
                  ______________________________<wbr>_________________<br>
                  mesa-dev mailing list<br>
                  <a href="mailto:mesa-dev@lists.freedesktop.org"
                    moz-do-not-send="true">mesa-dev@lists.freedesktop.org</a><br>
                  <a
                    href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>