nir: Add a helper for adding texture instruction sources
[mesa.git] / src / compiler / nir / nir_lower_samplers.c
index 0c4e91b000fac1968fb78fc518b567802d753c30..f75fb1afe886f433c97d45e9a44aecf582f1575d 100644 (file)
@@ -109,32 +109,9 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
       assert(array_elements >= 1);
       indirect = nir_umin(b, indirect, nir_imm_int(b, array_elements - 1));
 
-      /* First, we have to resize the array of texture sources */
-      nir_tex_src *new_srcs = rzalloc_array(instr, nir_tex_src,
-                                            instr->num_srcs + 2);
-
-      for (unsigned i = 0; i < instr->num_srcs; i++) {
-         new_srcs[i].src_type = instr->src[i].src_type;
-         nir_instr_move_src(&instr->instr, &new_srcs[i].src,
-                            &instr->src[i].src);
-      }
-
-      ralloc_free(instr->src);
-      instr->src = new_srcs;
-
-      /* Now we can go ahead and move the source over to being a
-       * first-class texture source.
-       */
-      instr->src[instr->num_srcs].src_type = nir_tex_src_texture_offset;
-      instr->num_srcs++;
-      nir_instr_rewrite_src(&instr->instr,
-                            &instr->src[instr->num_srcs - 1].src,
+      nir_tex_instr_add_src(instr, nir_tex_src_texture_offset,
                             nir_src_for_ssa(indirect));
-
-      instr->src[instr->num_srcs].src_type = nir_tex_src_sampler_offset;
-      instr->num_srcs++;
-      nir_instr_rewrite_src(&instr->instr,
-                            &instr->src[instr->num_srcs - 1].src,
+      nir_tex_instr_add_src(instr, nir_tex_src_sampler_offset,
                             nir_src_for_ssa(indirect));
 
       instr->texture_array_size = array_elements;