From 317be5a16dff5e3f39ba7426f53f0a9d35aa4442 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 10 Jul 2020 13:54:06 -0400 Subject: [PATCH] panfrost: Extend fetched framebuffer results So NIR doesn't complain about invalid swizzles when reading a format with less than 4 channels. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/util/pan_lower_framebuffer.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c index 3295d5697e0..61968e6bcb0 100644 --- a/src/panfrost/util/pan_lower_framebuffer.c +++ b/src/panfrost/util/pan_lower_framebuffer.c @@ -230,6 +230,22 @@ pan_fill_4(nir_builder *b, nir_ssa_def *v) return nir_vec(b, q, 4); } +static nir_ssa_def * +pan_extend(nir_builder *b, nir_ssa_def *v, unsigned N) +{ + nir_ssa_def *q[4]; + assert(v->num_components <= 4); + assert(N <= 4); + + for (unsigned j = 0; j < v->num_components; ++j) + q[j] = nir_channel(b, v, j); + + for (unsigned j = v->num_components; j < N; ++j) + q[j] = nir_imm_int(b, 0); + + return nir_vec(b, q, N); +} + static nir_ssa_def * pan_replicate_4(nir_builder *b, nir_ssa_def *v) { @@ -692,6 +708,7 @@ pan_lower_fb_load(nir_shader *shader, } unpacked = nir_convert_to_bit_size(b, unpacked, src_type, bits); + unpacked = pan_extend(b, unpacked, nir_dest_num_components(intr->dest)); nir_src rewritten = nir_src_for_ssa(unpacked); nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, rewritten, &intr->instr); -- 2.30.2