From 7bfbff74400a8805a306af7b994844f5ff9e2819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Tue, 23 Apr 2024 16:19:50 +0200 Subject: [PATCH] ac/nir: Add helper macros for emitting IO code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are implemented as macros because C doesn't have templates. They are meant for implementing properly split packed 16-bit IO stores and loads, to avoid repetition in the code. Signed-off-by: Timur Kristóf Reviewed-by: Georg Lehmann Part-of: --- src/amd/common/ac_nir.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/amd/common/ac_nir.h b/src/amd/common/ac_nir.h index cd0f41dffdf..762a85f0bdb 100644 --- a/src/amd/common/ac_nir.h +++ b/src/amd/common/ac_nir.h @@ -361,6 +361,35 @@ ac_nir_store_debug_log_amd(nir_builder *b, nir_def *uvec4); bool ac_nir_opt_pack_half(nir_shader *shader, enum amd_gfx_level gfx_level); +#define AC_NIR_STORE_IO(b, store_val, const_offset, write_mask, hi_16bit, func, ...) \ + do { \ + if ((store_val)->bit_size >= 32) { \ + const unsigned store_write_mask = (write_mask); \ + const unsigned store_const_offset = (const_offset); \ + func((b), (store_val), __VA_ARGS__); \ + } else { \ + u_foreach_bit(c, (write_mask)) { \ + const unsigned store_write_mask = 1; \ + const unsigned store_const_offset = (const_offset) + c * 4 + ((hi_16bit) ? 2 : 0); \ + nir_def *store_component = nir_channel(b, (store_val), c); \ + func((b), store_component, __VA_ARGS__); \ + } \ + } \ + } while (0) + +#define AC_NIR_LOAD_IO(load, b, num_components, bit_size, hi_16bit, func, ...) \ + do { \ + const unsigned load_bit_size = MAX2(32, (bit_size)); \ + (load) = func((b), (num_components), load_bit_size, __VA_ARGS__); \ + if ((bit_size) < load_bit_size) { \ + if ((hi_16bit)) { \ + (load) = nir_unpack_32_2x16_split_y(b, load); \ + } else { \ + (load) = nir_unpack_32_2x16_split_x(b, load); \ + } \ + } \ + } while (0) + #ifdef __cplusplus } #endif