nir/builder: Add a helper for storing to a deref
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 6 Jan 2016 23:24:24 +0000 (15:24 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 6 Jan 2016 23:30:53 +0000 (15:30 -0800)
src/glsl/nir/nir_builder.h

index 985f4af5339589d0732327499531fb44ebbf9576..e842b2252ff323401241b6e071f17d5cd0bf871b 100644 (file)
@@ -366,6 +366,22 @@ nir_store_var(nir_builder *build, nir_variable *var, nir_ssa_def *value,
    nir_builder_instr_insert(build, &store->instr);
 }
 
+static inline void
+nir_store_deref_var(nir_builder *build, nir_deref_var *deref,
+                    nir_ssa_def *value, unsigned writemask)
+{
+   const unsigned num_components =
+      glsl_get_vector_elements(nir_deref_tail(&deref->deref)->type);
+
+   nir_intrinsic_instr *store =
+      nir_intrinsic_instr_create(build->shader, nir_intrinsic_store_var);
+   store->num_components = num_components;
+   store->const_index[0] = writemask & ((1 << num_components) - 1);
+   store->variables[0] = nir_deref_as_var(nir_copy_deref(store, &deref->deref));
+   store->src[0] = nir_src_for_ssa(value);
+   nir_builder_instr_insert(build, &store->instr);
+}
+
 static inline void
 nir_copy_deref_var(nir_builder *build, nir_deref_var *dest, nir_deref_var *src)
 {