From 5d14757c033b78791968390201f2ece564a4c1ce Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 14 May 2020 18:06:58 -0400 Subject: [PATCH] panfrost: Un/pack R11G11B10 NIR has a helper for it already; we can reuse. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/util/pan_lower_framebuffer.c | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c index c0239c751b3..c21d42ba4ea 100644 --- a/src/panfrost/util/pan_lower_framebuffer.c +++ b/src/panfrost/util/pan_lower_framebuffer.c @@ -416,6 +416,32 @@ pan_unpack_uint_1010102(nir_builder *b, nir_ssa_def *packed) return nir_u2u16(b, mask); } +/* NIR means we can *finally* catch a break */ + +static nir_ssa_def * +pan_pack_r11g11b10(nir_builder *b, nir_ssa_def *v) +{ + return pan_replicate_4(b, nir_format_pack_11f11f10f(b, + nir_f2f32(b, v))); +} + +static nir_ssa_def * +pan_unpack_r11g11b10(nir_builder *b, nir_ssa_def *v) +{ + nir_ssa_def *f32 = nir_format_unpack_11f11f10f(b, nir_channel(b, v, 0)); + nir_ssa_def *f16 = nir_f2f16(b, f32); + + /* Extend to vec4 with alpha */ + nir_ssa_def *components[4] = { + nir_channel(b, f16, 0), + nir_channel(b, f16, 1), + nir_channel(b, f16, 2), + nir_imm_float16(b, 1.0) + }; + + return nir_vec(b, components, 4); +} + /* Generic dispatches for un/pack regardless of format */ static bool @@ -473,6 +499,8 @@ pan_unpack(nir_builder *b, return pan_unpack_unorm_1010102(b, packed); case PIPE_FORMAT_R10G10B10A2_UINT: return pan_unpack_uint_1010102(b, packed); + case PIPE_FORMAT_R11G11B10_FLOAT: + return pan_unpack_r11g11b10(b, packed); default: break; } @@ -520,6 +548,8 @@ pan_pack(nir_builder *b, return pan_pack_unorm_1010102(b, unpacked); case PIPE_FORMAT_R10G10B10A2_UINT: return pan_pack_uint_1010102(b, unpacked); + case PIPE_FORMAT_R11G11B10_FLOAT: + return pan_pack_r11g11b10(b, unpacked); default: break; } -- 2.30.2