From 063d7bfa1c1e995658377c7e4c713286de1a975d Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 5 Jul 2021 06:35:50 +1000 Subject: [PATCH] crocus: inline group_index<->bti this is on a fastpath for ubo emission Part-of: --- src/gallium/drivers/crocus/crocus_context.h | 48 ++++++++++++++++++--- src/gallium/drivers/crocus/crocus_program.c | 42 ------------------ 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/src/gallium/drivers/crocus/crocus_context.h b/src/gallium/drivers/crocus/crocus_context.h index 0e4fc2e7bc3..fc2cea03d7f 100644 --- a/src/gallium/drivers/crocus/crocus_context.h +++ b/src/gallium/drivers/crocus/crocus_context.h @@ -832,12 +832,48 @@ const struct shader_info *crocus_get_shader_info(const struct crocus_context *ic struct crocus_bo *crocus_get_scratch_space(struct crocus_context *ice, unsigned per_thread_scratch, gl_shader_stage stage); -uint32_t crocus_group_index_to_bti(const struct crocus_binding_table *bt, - enum crocus_surface_group group, - uint32_t index); -uint32_t crocus_bti_to_group_index(const struct crocus_binding_table *bt, - enum crocus_surface_group group, - uint32_t bti); +/** + * Map a pair to a binding table index. + * + * For example: => binding table index 12 + */ +static inline uint32_t crocus_group_index_to_bti(const struct crocus_binding_table *bt, + enum crocus_surface_group group, + uint32_t index) +{ + assert(index < bt->sizes[group]); + uint64_t mask = bt->used_mask[group]; + uint64_t bit = 1ull << index; + if (bit & mask) { + return bt->offsets[group] + util_bitcount64((bit - 1) & mask); + } else { + return CROCUS_SURFACE_NOT_USED; + } +} + +/** + * Map a binding table index back to a pair. + * + * For example: binding table index 12 => + */ +static inline uint32_t +crocus_bti_to_group_index(const struct crocus_binding_table *bt, + enum crocus_surface_group group, uint32_t bti) +{ + uint64_t used_mask = bt->used_mask[group]; + assert(bti >= bt->offsets[group]); + + uint32_t c = bti - bt->offsets[group]; + while (used_mask) { + int i = u_bit_scan64(&used_mask); + if (c == 0) + return i; + c--; + } + + return CROCUS_SURFACE_NOT_USED; +} + /* crocus_disk_cache.c */ diff --git a/src/gallium/drivers/crocus/crocus_program.c b/src/gallium/drivers/crocus/crocus_program.c index b236a267a61..b0865b87943 100644 --- a/src/gallium/drivers/crocus/crocus_program.c +++ b/src/gallium/drivers/crocus/crocus_program.c @@ -740,48 +740,6 @@ enum { SURFACE_GROUP_MAX_ELEMENTS = 64, }; -/** - * Map a pair to a binding table index. - * - * For example: => binding table index 12 - */ -uint32_t -crocus_group_index_to_bti(const struct crocus_binding_table *bt, - enum crocus_surface_group group, uint32_t index) -{ - assert(index < bt->sizes[group]); - uint64_t mask = bt->used_mask[group]; - uint64_t bit = 1ull << index; - if (bit & mask) { - return bt->offsets[group] + util_bitcount64((bit - 1) & mask); - } else { - return CROCUS_SURFACE_NOT_USED; - } -} - -/** - * Map a binding table index back to a pair. - * - * For example: binding table index 12 => - */ -uint32_t -crocus_bti_to_group_index(const struct crocus_binding_table *bt, - enum crocus_surface_group group, uint32_t bti) -{ - uint64_t used_mask = bt->used_mask[group]; - assert(bti >= bt->offsets[group]); - - uint32_t c = bti - bt->offsets[group]; - while (used_mask) { - int i = u_bit_scan64(&used_mask); - if (c == 0) - return i; - c--; - } - - return CROCUS_SURFACE_NOT_USED; -} - static void rewrite_src_with_bti(nir_builder *b, struct crocus_binding_table *bt, nir_instr *instr, nir_src *src,