From 50c3e9f87b7b3a6a7a5b4dcaa22c064d3b479f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 24 Dec 2022 12:51:16 -0500 Subject: [PATCH] st/mesa: move st_update_functions into st_context st_update_array will be set differently based on driver CAPs. Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-By: Mike Blumenkrantz Part-of: --- src/mesa/state_tracker/st_context.c | 28 ++++++++++------------------ src/mesa/state_tracker/st_context.h | 8 ++++---- src/mesa/state_tracker/st_util.h | 8 +++++--- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 7e08c837601..086d3b1585a 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -72,22 +72,6 @@ DEBUG_GET_ONCE_BOOL_OPTION(mesa_mvp_dp4, "MESA_MVP_DP4", false) -/* The list of state update functions. */ -st_update_func_t st_update_functions[ST_NUM_ATOMS]; - -static void -init_atoms_once(void) -{ - STATIC_ASSERT(ARRAY_SIZE(st_update_functions) <= 64); - -#define ST_STATE(FLAG, st_update) st_update_functions[FLAG##_INDEX] = st_update; -#include "st_atom_list.h" -#undef ST_STATE - - if (util_get_cpu_caps()->has_popcnt) - st_update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = st_update_array_with_popcnt; -} - void st_invalidate_buffers(struct st_context *st) { @@ -487,8 +471,16 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->cso_context = cso_create_context(pipe, cso_flags); ctx->cso_context = st->cso_context; - static once_flag flag = ONCE_FLAG_INIT; - call_once(&flag, init_atoms_once); + STATIC_ASSERT(ARRAY_SIZE(st->update_functions) <= 64); + +#define ST_STATE(FLAG, st_update) st->update_functions[FLAG##_INDEX] = st_update; +#include "st_atom_list.h" +#undef ST_STATE + + if (util_get_cpu_caps()->has_popcnt) { + st->update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = + st_update_array_with_popcnt; + } st_init_clear(st); { diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 021ae896fa1..284e55210c1 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -120,6 +120,7 @@ struct st_zombie_shader_node struct list_head node; }; +typedef void (*st_update_func_t)(struct st_context *st); struct st_context { @@ -128,6 +129,9 @@ struct st_context struct pipe_context *pipe; struct cso_context *cso_context; + /* The list of state update functions. */ + st_update_func_t update_functions[ST_NUM_ATOMS]; + struct pipe_frontend_screen *frontend_screen; /* e.g. dri_screen */ void *frontend_context; /* e.g. dri_context */ @@ -514,10 +518,6 @@ st_api_destroy_drawable(struct pipe_frontend_drawable *drawable); void st_screen_destroy(struct pipe_frontend_screen *fscreen); -typedef void (*st_update_func_t)(struct st_context *st); - -extern st_update_func_t st_update_functions[ST_NUM_ATOMS]; - #ifdef __cplusplus } #endif diff --git a/src/mesa/state_tracker/st_util.h b/src/mesa/state_tracker/st_util.h index 48d2d92f695..73179e7da64 100644 --- a/src/mesa/state_tracker/st_util.h +++ b/src/mesa/state_tracker/st_util.h @@ -124,18 +124,20 @@ st_validate_state(struct st_context *st, uint64_t pipeline_state_mask) * x86_64: u_bit_scan64 is negligibly faster than u_bit_scan * i386: u_bit_scan64 is noticably slower than u_bit_scan */ + st_update_func_t *update_state = st->update_functions; + if (sizeof(void*) == 8) { while (dirty) - st_update_functions[u_bit_scan64(&dirty)](st); + update_state[u_bit_scan64(&dirty)](st); } else { /* Split u_bit_scan64 into 2x u_bit_scan32 for i386. */ uint32_t dirty_lo = dirty; uint32_t dirty_hi = dirty >> 32; while (dirty_lo) - st_update_functions[u_bit_scan(&dirty_lo)](st); + update_state[u_bit_scan(&dirty_lo)](st); while (dirty_hi) - st_update_functions[32 + u_bit_scan(&dirty_hi)](st); + update_state[32 + u_bit_scan(&dirty_hi)](st); } } }