nir: add nir_var_shader_storage
[mesa.git] / src / glsl / nir / nir_builder.h
index 587d014d3f406302ac48b41cafad58a56494d4ba..9223e838095cc3ca3a61ae3168cfdbdb0f9c55ab 100644 (file)
@@ -29,6 +29,7 @@ struct exec_list;
 typedef struct nir_builder {
    struct exec_list *cf_node_list;
    nir_instr *before_instr;
+   nir_instr *after_instr;
 
    nir_shader *shader;
    nir_function_impl *impl;
@@ -47,12 +48,24 @@ nir_builder_insert_after_cf_list(nir_builder *build,
                                  struct exec_list *cf_node_list)
 {
    build->cf_node_list = cf_node_list;
+   build->before_instr = NULL;
+   build->after_instr = NULL;
 }
 
 static inline void
 nir_builder_insert_before_instr(nir_builder *build, nir_instr *before_instr)
 {
+   build->cf_node_list = NULL;
    build->before_instr = before_instr;
+   build->after_instr = NULL;
+}
+
+static inline void
+nir_builder_insert_after_instr(nir_builder *build, nir_instr *after_instr)
+{
+   build->cf_node_list = NULL;
+   build->before_instr = NULL;
+   build->after_instr = after_instr;
 }
 
 static inline void
@@ -60,9 +73,12 @@ nir_builder_instr_insert(nir_builder *build, nir_instr *instr)
 {
    if (build->cf_node_list) {
       nir_instr_insert_after_cf_list(build->cf_node_list, instr);
-   } else {
-      assert(build->before_instr);
+   } else if (build->before_instr) {
       nir_instr_insert_before(build->before_instr, instr);
+   } else {
+      assert(build->after_instr);
+      nir_instr_insert_after(build->after_instr, instr);
+      build->after_instr = instr;
    }
 }
 
@@ -215,8 +231,7 @@ static inline nir_ssa_def *
 nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
             unsigned num_components, bool use_fmov)
 {
-   nir_alu_src alu_src;
-   memset(&alu_src, 0, sizeof(alu_src));
+   nir_alu_src alu_src = { NIR_SRC_INIT };
    alu_src.src = nir_src_for_ssa(src);
    for (int i = 0; i < 4; i++)
       alu_src.swizzle[i] = swiz[i];
@@ -235,8 +250,7 @@ nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
    if (src.is_ssa && src.ssa->num_components == num_components)
       return src.ssa;
 
-   nir_alu_src alu;
-   memset(&alu, 0, sizeof(alu));
+   nir_alu_src alu = { NIR_SRC_INIT };
    alu.src = src;
    for (int j = 0; j < 4; j++)
       alu.swizzle[j] = j;