From b162c7962f78755d24aa972cf91c36cf989ba2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Fri, 21 Jun 2024 17:05:26 +0200 Subject: [PATCH] ac/nir: Add helper for I/O location mapping. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Map I/O locations based on a prefix sum (for linked shaders), or based on the provided callback. Signed-off-by: Timur Kristóf Reviewed-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák Reviewed-by: Samuel Pitoiset Part-of: --- src/amd/common/ac_nir.c | 20 ++++++++++++++++++++ src/amd/common/ac_nir_helpers.h | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/src/amd/common/ac_nir.c b/src/amd/common/ac_nir.c index b77e8b5a4a0..06621a980df 100644 --- a/src/amd/common/ac_nir.c +++ b/src/amd/common/ac_nir.c @@ -594,6 +594,26 @@ ac_nir_export_parameters(nir_builder *b, } } +unsigned +ac_nir_map_io_location(unsigned location, + uint64_t mask, + ac_nir_map_io_driver_location map_io) +{ + /* Unlinked shaders: + * We are unaware of the inputs of the next stage while lowering outputs. + * The driver needs to pass a callback to map varyings to a fixed location. + */ + if (map_io) + return map_io(location); + + /* Linked shaders: + * Take advantage of knowledge of the inputs of the next stage when lowering outputs. + * Map varyings to a prefix sum of the IO mask to save space in LDS or VRAM. + */ + assert(mask & BITFIELD64_BIT(location)); + return util_bitcount64(mask & BITFIELD64_MASK(location)); +} + /** * This function takes an I/O intrinsic like load/store_input, * and emits a sequence that calculates the full offset of that instruction, diff --git a/src/amd/common/ac_nir_helpers.h b/src/amd/common/ac_nir_helpers.h index 9f84b3cfdcd..1ed28b2c05c 100644 --- a/src/amd/common/ac_nir_helpers.h +++ b/src/amd/common/ac_nir_helpers.h @@ -125,6 +125,11 @@ ac_nir_calc_io_offset_mapped(nir_builder *b, unsigned component_stride, unsigned mapped_location); +unsigned +ac_nir_map_io_location(unsigned location, + uint64_t mask, + ac_nir_map_io_driver_location map_io); + nir_def * ac_nir_cull_primitive(nir_builder *b, nir_def *initially_accepted,