nir: add can_replace_varying() helper
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 11 Dec 2018 00:53:54 +0000 (11:53 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 2 Jan 2019 01:19:17 +0000 (12:19 +1100)
This will be reused by the following patch.

Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir_linking_helpers.c

index 582d6b90b94c88923594513f9ea3c7e3ec6e75e0..b6eaebcb6a470f37e5a9ea538c7bead0c9df194f 100644 (file)
@@ -561,8 +561,7 @@ nir_link_xfb_varyings(nir_shader *producer, nir_shader *consumer)
 }
 
 static bool
-try_replace_constant_input(nir_shader *shader,
-                           nir_intrinsic_instr *store_intr)
+can_replace_varying(nir_intrinsic_instr *store_intr)
 {
    nir_deref_instr *out_deref = nir_src_as_deref(store_intr->src[0]);
    if (out_deref->mode != nir_var_shader_out)
@@ -589,11 +588,24 @@ try_replace_constant_input(nir_shader *shader,
        out_var->data.location - VARYING_SLOT_VAR0 >= MAX_VARYING)
       return false;
 
+   return true;
+}
+
+static bool
+try_replace_constant_input(nir_shader *shader,
+                           nir_intrinsic_instr *store_intr)
+{
+   if (!can_replace_varying(store_intr))
+      return false;
+
    nir_function_impl *impl = nir_shader_get_entrypoint(shader);
 
    nir_builder b;
    nir_builder_init(&b, impl);
 
+   nir_variable *out_var =
+      nir_deref_instr_get_variable(nir_src_as_deref(store_intr->src[0]));
+
    bool progress = false;
    nir_foreach_block(block, impl) {
       nir_foreach_instr(instr, block) {