return &load_const->def;
}
+static inline nir_ssa_def *
+nir_imm_zero(nir_builder *build, unsigned num_components, unsigned bit_size)
+{
+ nir_load_const_instr *load_const =
+ nir_load_const_instr_create(build->shader, num_components, bit_size);
+
+ /* nir_load_const_instr_create uses rzalloc so it's already zero */
+
+ nir_builder_instr_insert(build, &load_const->instr);
+
+ return &load_const->def;
+}
+
static inline nir_ssa_def *
nir_imm_bool(nir_builder *build, bool x)
{
nir_ssa_def *d_lo = nir_unpack_64_2x32_split_x(b, d);
nir_ssa_def *d_hi = nir_unpack_64_2x32_split_y(b, d);
- nir_const_value v = { .u32 = { 0, 0, 0, 0 } };
- nir_ssa_def *q_lo = nir_build_imm(b, n->num_components, 32, v);
- nir_ssa_def *q_hi = nir_build_imm(b, n->num_components, 32, v);
+ nir_ssa_def *q_lo = nir_imm_zero(b, n->num_components, 32);
+ nir_ssa_def *q_hi = nir_imm_zero(b, n->num_components, 32);
nir_ssa_def *n_hi_before_if = n_hi;
nir_ssa_def *q_hi_before_if = q_hi;
* as to what we can do with an OOB read. Unfortunately, returning
* undefined values isn't one of them so we return an actual zero.
*/
- nir_const_value zero_val;
- memset(&zero_val, 0, sizeof(zero_val));
- nir_ssa_def *zero = nir_build_imm(b, load->num_components,
- load->dest.ssa.bit_size, zero_val);
+ nir_ssa_def *zero = nir_imm_zero(b, load->num_components,
+ load->dest.ssa.bit_size);
const unsigned load_size =
(load->dest.ssa.bit_size / 8) * load->num_components;
};
}
-static nir_ssa_def *
-nir_zero_vec(nir_builder *b, unsigned num_components)
-{
- nir_const_value v;
- memset(&v, 0, sizeof(v));
-
- return nir_build_imm(b, num_components, 32, v);
-}
-
static nir_ssa_def *
convert_color_for_load(nir_builder *b, const struct gen_device_info *devinfo,
nir_ssa_def *color,
nir_push_else(b, NULL);
- nir_ssa_def *zero = nir_zero_vec(b, load->num_components);
+ nir_ssa_def *zero = nir_imm_zero(b, load->num_components, 32);
nir_pop_if(b, NULL);