From 7de0e5500b6fbab2ed66131a7a54df9f95693a17 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 14 May 2020 14:49:08 -0400 Subject: [PATCH] panfrost: Un/pack RGB565 and RGB5A1 Basically the same as RGBA4 Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/util/pan_lower_framebuffer.c | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c index e0c00decab5..cc432c4c69c 100644 --- a/src/panfrost/util/pan_lower_framebuffer.c +++ b/src/panfrost/util/pan_lower_framebuffer.c @@ -299,6 +299,40 @@ pan_unpack_unorm_4(nir_builder *b, nir_ssa_def *v) nir_imm_ivec4(b, 4, 4, 4, 4)); } +/* UNORM RGB5_A1 and RGB565 are similar */ + +static nir_ssa_def * +pan_pack_unorm_5551(nir_builder *b, nir_ssa_def *v) +{ + return pan_pack_unorm_small(b, v, + nir_imm_vec4_16(b, 31.0, 31.0, 31.0, 1.0), + nir_imm_ivec4(b, 3, 3, 3, 7)); +} + +static nir_ssa_def * +pan_unpack_unorm_5551(nir_builder *b, nir_ssa_def *v) +{ + return pan_unpack_unorm_small(b, v, + nir_imm_vec4_16(b, 1.0 / 31.0, 1.0 / 31.0, 1.0 / 31.0, 1.0), + nir_imm_ivec4(b, 3, 3, 3, 7)); +} + +static nir_ssa_def * +pan_pack_unorm_565(nir_builder *b, nir_ssa_def *v) +{ + return pan_pack_unorm_small(b, v, + nir_imm_vec4_16(b, 31.0, 63.0, 31.0, 0.0), + nir_imm_ivec4(b, 3, 2, 3, 0)); +} + +static nir_ssa_def * +pan_unpack_unorm_565(nir_builder *b, nir_ssa_def *v) +{ + return pan_unpack_unorm_small(b, v, + nir_imm_vec4_16(b, 1.0 / 31.0, 1.0 / 63.0, 1.0 / 31.0, 0.0), + nir_imm_ivec4(b, 3, 2, 3, 0)); +} + /* Generic dispatches for un/pack regardless of format */ static bool @@ -347,6 +381,15 @@ pan_unpack(nir_builder *b, } } + switch (desc->format) { + case PIPE_FORMAT_B5G5R5A1_UNORM: + return pan_unpack_unorm_5551(b, packed); + case PIPE_FORMAT_B5G6R5_UNORM: + return pan_unpack_unorm_565(b, packed); + default: + break; + } + fprintf(stderr, "%s\n", desc->name); unreachable("Unknown format"); } @@ -381,6 +424,15 @@ pan_pack(nir_builder *b, } } + switch (desc->format) { + case PIPE_FORMAT_B5G5R5A1_UNORM: + return pan_pack_unorm_5551(b, unpacked); + case PIPE_FORMAT_B5G6R5_UNORM: + return pan_pack_unorm_565(b, unpacked); + default: + break; + } + fprintf(stderr, "%s\n", desc->name); unreachable("Unknown format"); } -- 2.30.2