pan/blit: Lower load_sampler_lod_parameters_pan
authorAlyssa Rosenzweig <alyssa@collabora.com>
Tue, 7 Feb 2023 04:23:59 +0000 (23:23 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 23 Mar 2023 23:53:46 +0000 (23:53 +0000)
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 <alyssa@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20906>

src/panfrost/lib/pan_blitter.c

index 2705bf6..44e59af 100644 (file)
@@ -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 */