turnip: Refactor the intrinsic lowering.
authorEric Anholt <eric@anholt.net>
Thu, 19 Dec 2019 00:30:37 +0000 (16:30 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 21 Jan 2020 19:29:59 +0000 (19:29 +0000)
Too many things in one function, split them out based on the intrinsic.

Reviewed-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3433>

src/freedreno/vulkan/tu_shader.c

index 0b755a99f8e71f1667dda4b084e9a3986e94097c..514f3d852f9bbb422c24b9421b1bd86de22c5723 100644 (file)
@@ -233,45 +233,34 @@ lower_sampler(nir_builder *b, nir_tex_instr *instr, struct tu_shader *shader,
    return true;
 }
 
-static bool
-lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr,
-                struct tu_shader *shader,
-                const struct tu_pipeline_layout *layout)
+static void
+lower_load_push_constant(nir_builder *b, nir_intrinsic_instr *instr,
+                         struct tu_shader *shader)
 {
-   /* TODO: remove this when layered rendering is implemented */
-   if (instr->intrinsic == nir_intrinsic_load_layer_id) {
-      nir_ssa_def_rewrite_uses(&instr->dest.ssa,
-                               nir_src_for_ssa(nir_imm_int(b, 0)));
-      nir_instr_remove(&instr->instr);
-      return true;
-   }
-
-   if (instr->intrinsic == nir_intrinsic_load_push_constant) {
-      /* note: ir3 wants load_ubo, not load_uniform */
-      assert(nir_intrinsic_base(instr) == 0);
-
-      nir_intrinsic_instr *load =
-         nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_ubo);
-      load->num_components = instr->num_components;
-      load->src[0] = nir_src_for_ssa(nir_imm_int(b, 0));
-      load->src[1] = instr->src[0];
-      nir_ssa_dest_init(&load->instr, &load->dest,
-                        load->num_components, instr->dest.ssa.bit_size,
-                        instr->dest.ssa.name);
-      nir_builder_instr_insert(b, &load->instr);
-      nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(&load->dest.ssa));
+   /* note: ir3 wants load_ubo, not load_uniform */
+   assert(nir_intrinsic_base(instr) == 0);
+
+   nir_intrinsic_instr *load =
+      nir_intrinsic_instr_create(b->shader, nir_intrinsic_load_ubo);
+   load->num_components = instr->num_components;
+   load->src[0] = nir_src_for_ssa(nir_imm_int(b, 0));
+   load->src[1] = instr->src[0];
+   nir_ssa_dest_init(&load->instr, &load->dest,
+                     load->num_components, instr->dest.ssa.bit_size,
+                     instr->dest.ssa.name);
+   nir_builder_instr_insert(b, &load->instr);
+   nir_ssa_def_rewrite_uses(&instr->dest.ssa, nir_src_for_ssa(&load->dest.ssa));
 
-      nir_instr_remove(&instr->instr);
-
-      return true;
-   }
-
-   if (instr->intrinsic != nir_intrinsic_vulkan_resource_index)
-      return false;
+   nir_instr_remove(&instr->instr);
+}
 
+static void
+lower_vulkan_resource_index(nir_builder *b, nir_intrinsic_instr *instr,
+                            struct tu_shader *shader,
+                            const struct tu_pipeline_layout *layout)
+{
    nir_const_value *const_val = nir_src_as_const_value(instr->src[0]);
 
-
    unsigned set = nir_intrinsic_desc_set(instr);
    unsigned binding = nir_intrinsic_binding(instr);
    struct tu_descriptor_set_layout *set_layout = layout->set[set].layout;
@@ -304,8 +293,32 @@ lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr,
    nir_ssa_def_rewrite_uses(&instr->dest.ssa,
                             nir_src_for_ssa(nir_imm_int(b, index)));
    nir_instr_remove(&instr->instr);
+}
 
-   return true;
+static bool
+lower_intrinsic(nir_builder *b, nir_intrinsic_instr *instr,
+                struct tu_shader *shader,
+                const struct tu_pipeline_layout *layout)
+{
+   switch (instr->intrinsic) {
+   case nir_intrinsic_load_layer_id:
+      /* TODO: remove this when layered rendering is implemented */
+      nir_ssa_def_rewrite_uses(&instr->dest.ssa,
+                               nir_src_for_ssa(nir_imm_int(b, 0)));
+      nir_instr_remove(&instr->instr);
+      return true;
+
+   case nir_intrinsic_load_push_constant:
+      lower_load_push_constant(b, instr, shader);
+      return true;
+
+   case nir_intrinsic_vulkan_resource_index:
+      lower_vulkan_resource_index(b, instr, shader, layout);
+      return true;
+
+   default:
+      return false;
+   }
 }
 
 static bool