panfrost: Un/pack 8-bit UNORM
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 13 May 2020 18:06:55 +0000 (14:06 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 1 Jun 2020 15:46:23 +0000 (15:46 +0000)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5265>

src/panfrost/util/pan_lower_framebuffer.c

index e791ff5ea08b23039eea55f7e58978682a260717..dc0aa9ab84706dc239e5dfc9636540d2d7bc37a6 100644 (file)
@@ -231,6 +231,26 @@ pan_unpack_pure_8(nir_builder *b, nir_ssa_def *pack, unsigned num_components)
         return nir_channels(b, unpacked, (1 << num_components) - 1);
 }
 
+/* UNORM 8 is unpacked to f16 vec4. We could directly use the un/pack_unorm_4x8
+ * ops provided we replicate appropriately, but for packing we'd rather stay in
+ * 8/16-bit whereas the NIR op forces 32-bit, so we do it manually */
+
+static nir_ssa_def *
+pan_pack_unorm_8(nir_builder *b, nir_ssa_def *v)
+{
+        return pan_replicate_4(b, nir_pack_32_4x8(b,
+                nir_f2u8(b, nir_fround_even(b, nir_fmul(b, nir_fsat(b,
+                        pan_fill_4(b, v)), nir_imm_float16(b, 255.0))))));
+}
+
+static nir_ssa_def *
+pan_unpack_unorm_8(nir_builder *b, nir_ssa_def *pack, unsigned num_components)
+{
+        assert(num_components <= 4);
+        nir_ssa_def *unpacked = nir_unpack_unorm_4x8(b, nir_channel(b, pack, 0));
+        return nir_f2f16(b, unpacked);
+}
+
 /* Generic dispatches for un/pack regardless of format */
 
 static nir_ssa_def *