From 2a356cefba1799a0222edc6574d32ee6ef1c77b4 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 6 Feb 2023 23:23:59 -0500 Subject: [PATCH] pan/blit: Lower load_sampler_lod_parameters_pan This will be needed to decouple the lowering in the Midgard compiler from the specific sampler descriptors used in the blit code. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- src/panfrost/lib/pan_blitter.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/panfrost/lib/pan_blitter.c b/src/panfrost/lib/pan_blitter.c index 2705bf6..44e59af 100644 --- a/src/panfrost/lib/pan_blitter.c +++ b/src/panfrost/lib/pan_blitter.c @@ -378,6 +378,35 @@ pan_blitter_get_blend_shaders(struct panfrost_device *dev, unsigned rt_count, #endif } +/* + * Early Mali GPUs did not respect sampler LOD clamps or bias, so the Midgard + * compiler inserts lowering code with a load_sampler_lod_parameters_pan sysval + * that we need to lower. Our samplers do not use LOD clamps or bias, so we + * lower to the identity settings and let constant folding get rid of the + * unnecessary lowering. + */ +static bool +lower_sampler_parameters(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); + if (intr->intrinsic != nir_intrinsic_load_sampler_lod_parameters_pan) + return false; + + const nir_const_value constants[4] = { + nir_const_value_for_float(0.0f, 32), /* min_lod */ + nir_const_value_for_float(INFINITY, 32), /* max_lod */ + nir_const_value_for_float(0.0f, 32), /* lod_bias */ + }; + + b->cursor = nir_after_instr(instr); + nir_ssa_def_rewrite_uses(&intr->dest.ssa, + nir_build_imm(b, 3, 32, constants)); + return true; +} + static const struct pan_blit_shader_data * pan_blitter_get_blit_shader(struct panfrost_device *dev, const struct pan_blit_shader_key *key) @@ -602,6 +631,12 @@ pan_blitter_get_blit_shader(struct panfrost_device *dev, for (unsigned i = 0; i < active_count; ++i) BITSET_SET(b.shader->info.textures_used, i); + if (PAN_ARCH == 4) { + NIR_PASS_V(b.shader, nir_shader_instructions_pass, + lower_sampler_parameters, + nir_metadata_block_index | nir_metadata_dominance, NULL); + } + GENX(pan_shader_compile)(b.shader, &inputs, &binary, &shader->info); /* Blit shaders shouldn't have sysvals */ -- 2.7.4