From c384690ab7157044f2a7acb77cd36f077a34e5cb Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 24 Jan 2023 11:35:43 +0100 Subject: [PATCH] nir: support lowering nir_intrinsic_image_samples to a constant load This can be used by multiple drivers that do not support ms images Reviewed-by: Faith Ekstrand Reviewed-by: Rob Clark Reviewer-by: Alyssa Rosenzweig Signed-off-by: Amber Amber Part-of: --- src/compiler/nir/nir.h | 6 ++++++ src/compiler/nir/nir_lower_image.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f821efcdc8e..1875311894a 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5328,6 +5328,12 @@ typedef struct nir_lower_image_options { * Lower multi sample image load and samples_identical to use fragment_mask_load. */ bool lower_to_fragment_mask_load_amd; + + /** + * Lower image_samples to a constant in case the driver doesn't support multisampled + * images. + */ + bool lower_image_samples_to_one; } nir_lower_image_options; bool nir_lower_image(nir_shader *nir, diff --git a/src/compiler/nir/nir_lower_image.c b/src/compiler/nir/nir_lower_image.c index e9dfd82d4dd..4b9c3554674 100644 --- a/src/compiler/nir/nir_lower_image.c +++ b/src/compiler/nir/nir_lower_image.c @@ -182,6 +182,15 @@ lower_image_instr(nir_builder *b, nir_instr *instr, void *state) } return false; + case nir_intrinsic_image_samples: { + if (options->lower_image_samples_to_one) { + b->cursor = nir_after_instr(&intrin->instr); + nir_ssa_def *samples = nir_imm_intN_t(b, 1, nir_dest_bit_size(intrin->dest)); + nir_ssa_def_rewrite_uses(&intrin->dest.ssa, samples); + return true; + } + return false; + } default: return false; }