lavapipe: strip unneeded scoped barriers
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 14 Mar 2022 14:04:42 +0000 (10:04 -0400)
committerMarge Bot <emma+marge@anholt.net>
Tue, 15 Mar 2022 22:17:43 +0000 (22:17 +0000)
most of these do nothing and can't be emitted without breaking shaders

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15377>

src/gallium/frontends/lavapipe/lvp_pipeline.c

index e158489..da71793 100644 (file)
@@ -566,6 +566,29 @@ scan_pipeline_info(struct lvp_pipeline *pipeline, nir_shader *nir)
 
 }
 
+static bool
+remove_scoped_barriers_impl(nir_builder *b, nir_instr *instr, 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_scoped_barrier)
+      return false;
+   if (data) {
+      if (nir_intrinsic_memory_scope(intr) == NIR_SCOPE_WORKGROUP ||
+          nir_intrinsic_memory_scope(intr) == NIR_SCOPE_DEVICE)
+         return false;
+   }
+   nir_instr_remove(instr);
+   return true;
+}
+
+static bool
+remove_scoped_barriers(nir_shader *nir, bool is_compute)
+{
+   return nir_shader_instructions_pass(nir, remove_scoped_barriers_impl, nir_metadata_dominance, (void*)is_compute);
+}
+
 static void
 lvp_shader_compile_to_ir(struct lvp_pipeline *pipeline,
                          struct vk_shader_module *module,
@@ -637,6 +660,9 @@ lvp_shader_compile_to_ir(struct lvp_pipeline *pipeline,
 
    free(spec_entries);
 
+   if (nir->info.stage != MESA_SHADER_TESS_CTRL)
+      NIR_PASS_V(nir, remove_scoped_barriers, nir->info.stage == MESA_SHADER_COMPUTE);
+
    const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
       .frag_coord = true,
       .point_coord = true,