From c6e33249801fcf3e88ab2d645df0b628df4cc712 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 25 May 2023 15:01:22 -0400 Subject: [PATCH] agx: Legalize image LODs to be 16-bit Required by the hardware. Do it in NIR so we can optimize the conversion. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_nir_lower_texture.c | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/asahi/compiler/agx_nir_lower_texture.c b/src/asahi/compiler/agx_nir_lower_texture.c index 3309767a72b..33191283351 100644 --- a/src/asahi/compiler/agx_nir_lower_texture.c +++ b/src/asahi/compiler/agx_nir_lower_texture.c @@ -457,6 +457,39 @@ lower_sampler_bias(nir_builder *b, nir_instr *instr, UNUSED void *data) } } +static bool +legalize_image_lod(nir_builder *b, nir_instr *instr, UNUSED void *data) +{ + if (instr->type != nir_instr_type_intrinsic) + return false; + + nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr); + nir_src *src; + +#define CASE(op, idx) \ + case nir_intrinsic_##op: \ + case nir_intrinsic_bindless_##op: \ + src = &intr->src[idx]; \ + break; + + switch (intr->intrinsic) { + CASE(image_load, 3) + CASE(image_store, 4) + CASE(image_size, 1) + default: + return false; + } + +#undef CASE + + if (src->ssa->bit_size == 16) + return false; + + b->cursor = nir_before_instr(instr); + nir_src_rewrite_ssa(src, nir_i2i16(b, src->ssa)); + return true; +} + bool agx_nir_lower_texture(nir_shader *s, bool support_lod_bias) { @@ -492,6 +525,8 @@ agx_nir_lower_texture(nir_shader *s, bool support_lod_bias) nir_metadata_block_index | nir_metadata_dominance, NULL); } + NIR_PASS(progress, s, nir_shader_instructions_pass, legalize_image_lod, + nir_metadata_block_index | nir_metadata_dominance, NULL); NIR_PASS(progress, s, nir_legalize_16bit_sampler_srcs, tex_constraints); /* Lower texture sources after legalizing types (as the lowering depends on