From: Jason Ekstrand Date: Tue, 2 Apr 2019 02:31:26 +0000 (-0500) Subject: nir/builder: Add a nir_imm_zero helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9b1e4bab6bb3be7a5dad910b10a28db0a4bb8b5f;p=mesa.git nir/builder: Add a nir_imm_zero helper v2: replace nir_zero_vec with nir_imm_zero (Karol Herbst) Reviewed-by: Karol Herbst --- diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 66a028bac97..9ee58dafd21 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -208,6 +208,19 @@ nir_build_imm(nir_builder *build, unsigned num_components, 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) { diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c index e7d361da6da..b3b78c6649a 100644 --- a/src/compiler/nir/nir_lower_int64.c +++ b/src/compiler/nir/nir_lower_int64.c @@ -493,9 +493,8 @@ lower_udiv64_mod64(nir_builder *b, nir_ssa_def *n, nir_ssa_def *d, 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; diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c index 331ecc08324..c666fe16f7b 100644 --- a/src/compiler/nir/nir_lower_io.c +++ b/src/compiler/nir/nir_lower_io.c @@ -754,10 +754,8 @@ build_explicit_io_load(nir_builder *b, nir_intrinsic_instr *intrin, * 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; diff --git a/src/intel/compiler/brw_nir_lower_image_load_store.c b/src/intel/compiler/brw_nir_lower_image_load_store.c index 48b98bc57bd..c23f64fb338 100644 --- a/src/intel/compiler/brw_nir_lower_image_load_store.c +++ b/src/intel/compiler/brw_nir_lower_image_load_store.c @@ -312,15 +312,6 @@ get_format_info(enum isl_format fmt) }; } -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, @@ -498,7 +489,7 @@ lower_image_load_instr(nir_builder *b, 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);