From: Jason Ekstrand Date: Tue, 19 May 2020 18:53:41 +0000 (-0500) Subject: nir/builder: Add load/store_global helpers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a06955f4ef623c3767739f7b73438eb54b59222c;p=mesa.git nir/builder: Add load/store_global helpers Reviewed-by: Kenneth Graunke Part-of: --- diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 19dab6e9b10..a33a33a870d 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -1370,6 +1370,36 @@ nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src) nir_build_deref_var(build, src)); } +static inline nir_ssa_def * +nir_load_global(nir_builder *build, nir_ssa_def *addr, unsigned align, + unsigned num_components, unsigned bit_size) +{ + nir_intrinsic_instr *load = + nir_intrinsic_instr_create(build->shader, nir_intrinsic_load_global); + load->num_components = num_components; + load->src[0] = nir_src_for_ssa(addr); + nir_intrinsic_set_align(load, align, 0); + nir_ssa_dest_init(&load->instr, &load->dest, + num_components, bit_size, NULL); + nir_builder_instr_insert(build, &load->instr); + return &load->dest.ssa; +} + +static inline void +nir_store_global(nir_builder *build, nir_ssa_def *addr, unsigned align, + nir_ssa_def *value, nir_component_mask_t write_mask) +{ + nir_intrinsic_instr *store = + nir_intrinsic_instr_create(build->shader, nir_intrinsic_store_global); + store->num_components = value->num_components; + store->src[0] = nir_src_for_ssa(value); + store->src[1] = nir_src_for_ssa(addr); + nir_intrinsic_set_write_mask(store, + write_mask & BITFIELD_MASK(value->num_components)); + nir_intrinsic_set_align(store, align, 0); + nir_builder_instr_insert(build, &store->instr); +} + static inline nir_ssa_def * nir_load_param(nir_builder *build, uint32_t param_idx) {