From e4d75c22beba5533b499f7f8f8be6ab0a110ecbc Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Mon, 24 Aug 2020 13:58:49 +0100 Subject: [PATCH] nir/opt_shrink_vectors: shrink image stores using the format fossil-db (Navi): Totals from 657 (0.48% of 135946) affected shaders: VGPRs: 26076 -> 25520 (-2.13%); split: -2.15%, +0.02% CodeSize: 3033016 -> 3014472 (-0.61%); split: -0.64%, +0.03% MaxWaves: 9386 -> 9420 (+0.36%) Instrs: 590109 -> 585502 (-0.78%); split: -0.82%, +0.04% Signed-off-by: Rhys Perry Reviewed-by: Eric Anholt Part-of: --- src/compiler/nir/nir_opt_shrink_vectors.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/compiler/nir/nir_opt_shrink_vectors.c b/src/compiler/nir/nir_opt_shrink_vectors.c index d46b377..0536598 100644 --- a/src/compiler/nir/nir_opt_shrink_vectors.c +++ b/src/compiler/nir/nir_opt_shrink_vectors.c @@ -110,6 +110,30 @@ opt_shrink_vectors_alu(nir_builder *b, nir_alu_instr *instr) } static bool +opt_shrink_vectors_image_store(nir_builder *b, nir_intrinsic_instr *instr) +{ + enum pipe_format format; + if (instr->intrinsic == nir_intrinsic_image_deref_store) { + nir_deref_instr *deref = nir_src_as_deref(instr->src[0]); + format = nir_deref_instr_get_variable(deref)->data.image.format; + } else { + format = nir_intrinsic_format(instr); + } + if (format == PIPE_FORMAT_NONE) + return false; + + unsigned components = util_format_get_nr_components(format); + if (components >= instr->num_components) + return false; + + nir_ssa_def *data = nir_channels(b, instr->src[3].ssa, BITSET_MASK(components)); + nir_instr_rewrite_src(&instr->instr, &instr->src[3], nir_src_for_ssa(data)); + instr->num_components = components; + + return true; +} + +static bool opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr) { switch (instr->intrinsic) { @@ -133,6 +157,10 @@ opt_shrink_vectors_intrinsic(nir_builder *b, nir_intrinsic_instr *instr) case nir_intrinsic_store_global: case nir_intrinsic_store_scratch: break; + case nir_intrinsic_bindless_image_store: + case nir_intrinsic_image_deref_store: + case nir_intrinsic_image_store: + return opt_shrink_vectors_image_store(b, instr); default: return false; } -- 2.7.4