ac/nir: move store_var_components to common place
authorQiang Yu <yuq825@gmail.com>
Tue, 14 Feb 2023 02:19:44 +0000 (10:19 +0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 16 Mar 2023 04:33:30 +0000 (04:33 +0000)
It will be shared by other nir lowering too.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21437>

src/amd/common/ac_nir.c
src/amd/common/ac_nir.h
src/amd/common/ac_nir_lower_ngg.c

index 4fb4088..3bdf9c7 100644 (file)
@@ -46,6 +46,31 @@ ac_nir_unpack_arg(nir_builder *b, const struct ac_shader_args *ac_args, struct a
 }
 
 void
+ac_nir_store_var_components(nir_builder *b, nir_variable *var, nir_ssa_def *value,
+                            unsigned component, unsigned writemask)
+{
+   /* component store */
+   if (value->num_components != 4) {
+      nir_ssa_def *undef = nir_ssa_undef(b, 1, value->bit_size);
+
+      /* add undef component before and after value to form a vec4 */
+      nir_ssa_def *comp[4];
+      for (int i = 0; i < 4; i++) {
+         comp[i] = (i >= component && i < component + value->num_components) ?
+            nir_channel(b, value, i - component) : undef;
+      }
+
+      value = nir_vec(b, comp, 4);
+      writemask <<= component;
+   } else {
+      /* if num_component==4, there should be no component offset */
+      assert(component == 0);
+   }
+
+   nir_store_var(b, var, value, writemask);
+}
+
+void
 ac_nir_export_primitive(nir_builder *b, nir_ssa_def *prim)
 {
    unsigned write_mask = BITFIELD_MASK(prim->num_components);
index 1885100..2197282 100644 (file)
@@ -74,6 +74,10 @@ ac_nir_unpack_arg(nir_builder *b, const struct ac_shader_args *ac_args, struct a
                   unsigned rshift, unsigned bitwidth);
 
 void
+ac_nir_store_var_components(nir_builder *b, nir_variable *var, nir_ssa_def *value,
+                            unsigned component, unsigned writemask);
+
+void
 ac_nir_export_primitive(nir_builder *b, nir_ssa_def *prim);
 
 void
index 2d13364..4b20018 100644 (file)
@@ -607,31 +607,6 @@ emit_store_ngg_nogs_es_primitive_id(nir_builder *b, lower_ngg_nogs_state *st)
 }
 
 static void
-store_var_components(nir_builder *b, nir_variable *var, nir_ssa_def *value,
-                     unsigned component, unsigned writemask)
-{
-   /* component store */
-   if (value->num_components != 4) {
-      nir_ssa_def *undef = nir_ssa_undef(b, 1, value->bit_size);
-
-      /* add undef component before and after value to form a vec4 */
-      nir_ssa_def *comp[4];
-      for (int i = 0; i < 4; i++) {
-         comp[i] = (i >= component && i < component + value->num_components) ?
-            nir_channel(b, value, i - component) : undef;
-      }
-
-      value = nir_vec(b, comp, 4);
-      writemask <<= component;
-   } else {
-      /* if num_component==4, there should be no component offset */
-      assert(component == 0);
-   }
-
-   nir_store_var(b, var, value, writemask);
-}
-
-static void
 add_clipdist_bit(nir_builder *b, nir_ssa_def *dist, unsigned index, nir_variable *mask)
 {
    nir_ssa_def *is_neg = nir_flt(b, dist, nir_imm_float(b, 0));
@@ -671,7 +646,7 @@ remove_culling_shader_output(nir_builder *b, nir_instr *instr, void *state)
    nir_io_semantics io_sem = nir_intrinsic_io_semantics(intrin);
    switch (io_sem.location) {
    case VARYING_SLOT_POS:
-      store_var_components(b, s->position_value_var, store_val, component, writemask);
+      ac_nir_store_var_components(b, s->position_value_var, store_val, component, writemask);
       break;
    case VARYING_SLOT_CLIP_DIST0:
    case VARYING_SLOT_CLIP_DIST1: {
@@ -688,7 +663,7 @@ remove_culling_shader_output(nir_builder *b, nir_instr *instr, void *state)
       break;
    }
    case VARYING_SLOT_CLIP_VERTEX:
-      store_var_components(b, s->clip_vertex_var, store_val, component, writemask);
+      ac_nir_store_var_components(b, s->clip_vertex_var, store_val, component, writemask);
       break;
    default:
       break;