nir: introduce nir_pack_{sint,uint}_2x16 instructions
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 3 Mar 2022 07:37:29 +0000 (08:37 +0100)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Mar 2022 08:06:56 +0000 (08:06 +0000)
These instructions have AMD hardware equivalent and they will be used
to lower fragment shader outputs in NIR.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15231>

src/compiler/nir/nir_constant_expressions.py
src/compiler/nir/nir_opcodes.py

index 3876b68..b82d96d 100644 (file)
@@ -64,6 +64,7 @@ template = """\
 #include "util/double.h"
 #include "util/softfloat.h"
 #include "util/bigmath.h"
+#include "util/format/format_utils.h"
 #include "nir_constant_expressions.h"
 
 /**
index a490ea3..d23420a 100644 (file)
@@ -367,6 +367,18 @@ unpack_2x16("unorm")
 unpack_4x8("unorm")
 unpack_2x16("half")
 
+# Convert two unsigned integers into a packed unsigned short (clamp is applied).
+unop_horiz("pack_uint_2x16", 1, tuint32, 2, tuint32, """
+dst.x = _mesa_unsigned_to_unsigned(src0.x, 16);
+dst.x |= _mesa_unsigned_to_unsigned(src0.y, 16) << 16;
+""")
+
+# Convert two signed integers into a packed signed short (clamp is applied).
+unop_horiz("pack_sint_2x16", 1, tint32, 2, tint32, """
+dst.x = _mesa_signed_to_signed(src0.x, 16) & 0xffff;
+dst.x |= _mesa_signed_to_signed(src0.y, 16) << 16;
+""")
+
 unop_horiz("pack_uvec2_to_uint", 1, tuint32, 2, tuint32, """
 dst.x = (src0.x & 0xffff) | (src0.y << 16);
 """)