st/mesa: inline st_validate_state and remove redundant checking in callers
authorMarek Olšák <marek.olsak@amd.com>
Mon, 21 Nov 2022 12:59:14 +0000 (07:59 -0500)
committerMarge Bot <emma+marge@anholt.net>
Mon, 12 Dec 2022 19:15:34 +0000 (19:15 +0000)
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19953>

src/mesa/main/buffers.c
src/mesa/main/compute.c
src/mesa/main/fbobject.c
src/mesa/main/multisample.c
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_util.h

index 169987a..13a0116 100644 (file)
@@ -46,6 +46,7 @@
 #include "state_tracker/st_manager.h"
 #include "state_tracker/st_atom.h"
 #include "state_tracker/st_context.h"
+#include "state_tracker/st_util.h"
 
 #define BAD_MASK ~0u
 
index c0ba026..e601f19 100644 (file)
@@ -295,10 +295,7 @@ prepare_compute(struct gl_context *ctx)
    if (ctx->NewState)
       _mesa_update_state(ctx);
 
-   if (ctx->NewDriverState & st->active_states &
-       ST_PIPELINE_COMPUTE_STATE_MASK)
-      st_validate_state(st, ST_PIPELINE_COMPUTE_STATE_MASK);
-
+   st_validate_state(st, ST_PIPELINE_COMPUTE_STATE_MASK);
 }
 
 static ALWAYS_INLINE void
index be1a8dd..65562e7 100644 (file)
@@ -56,6 +56,7 @@
 #include "state_tracker/st_cb_eglimage.h"
 #include "state_tracker/st_context.h"
 #include "state_tracker/st_format.h"
+#include "state_tracker/st_util.h"
 
 /**
  * Notes:
index e5f9f0a..801a997 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "state_tracker/st_context.h"
 #include "state_tracker/st_format.h"
-#include "state_tracker/st_context.h"
+#include "state_tracker/st_util.h"
 
 /**
  * Called via glSampleCoverageARB
index c69f4e6..3e33c2b 100644 (file)
 #include "util/u_cpu_detect.h"
 
 
-typedef void (*update_func_t)(struct st_context *st);
-
 /* The list state update functions. */
-static update_func_t update_functions[ST_NUM_ATOMS];
+st_update_func_t st_update_functions[ST_NUM_ATOMS];
 
 static void
 init_atoms_once(void)
 {
-#define ST_STATE(FLAG, st_update) update_functions[FLAG##_INDEX] = st_update;
+#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)
-      update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = st_update_array_with_popcnt;
+      st_update_functions[ST_NEW_VERTEX_ARRAYS_INDEX] = st_update_array_with_popcnt;
 }
 
 void st_init_atoms( struct st_context *st )
 {
-   STATIC_ASSERT(ARRAY_SIZE(update_functions) <= 64);
+   STATIC_ASSERT(ARRAY_SIZE(st_update_functions) <= 64);
 
    static once_flag flag = ONCE_FLAG_INIT;
    call_once(&flag, init_atoms_once);
@@ -69,31 +67,3 @@ void st_destroy_atoms( struct st_context *st )
 {
    /* no-op */
 }
-
-/***********************************************************************
- * Update all derived state:
- */
-
-void st_validate_state(struct st_context *st, uint64_t pipeline_state_mask)
-{
-   struct gl_context *ctx = st->ctx;
-
-   /* Inactive states are shader states not used by shaders at the moment. */
-   uint64_t dirty = ctx->NewDriverState & st->active_states & pipeline_state_mask;
-   if (!dirty)
-      return;
-
-   ctx->NewDriverState &= ~dirty;
-
-   uint32_t dirty_lo = dirty;
-   uint32_t dirty_hi = dirty >> 32;
-
-   /* Update states.
-    *
-    * Don't use u_bit_scan64, it may be slower on 32-bit.
-    */
-   while (dirty_lo)
-      update_functions[u_bit_scan(&dirty_lo)](st);
-   while (dirty_hi)
-      update_functions[32 + u_bit_scan(&dirty_hi)](st);
-}
index 0f8063f..11bfcb0 100644 (file)
@@ -35,6 +35,7 @@
 #define ST_ATOM_H
 
 #include "util/glheader.h"
+#include "main/mtypes.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -50,7 +51,6 @@ struct cso_velems_state;
 
 void st_init_atoms( struct st_context *st );
 void st_destroy_atoms( struct st_context *st );
-void st_validate_state(struct st_context *st, uint64_t pipeline_state_mask);
 
 void
 st_setup_arrays(struct st_context *st,
@@ -183,6 +183,10 @@ enum {
 #define ST_ALL_STATES_MASK (ST_PIPELINE_RENDER_STATE_MASK | \
                             ST_PIPELINE_COMPUTE_STATE_MASK)
 
+typedef void (*st_update_func_t)(struct st_context *st);
+
+extern st_update_func_t st_update_functions[ST_NUM_ATOMS];
+
 #ifdef __cplusplus
 }
 #endif
index 7d8e12a..a3a3858 100644 (file)
@@ -633,10 +633,7 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y,
     * for bitmap drawing uses no constants and the FS constants are
     * explicitly uploaded in the draw_bitmap_quad() function.
     */
-   if (ctx->NewDriverState & st->active_states &
-       ~ST_NEW_CONSTANTS & ST_PIPELINE_RENDER_STATE_MASK) {
-      st_validate_state(st, ST_PIPELINE_META_STATE_MASK);
-   }
+   st_validate_state(st, ST_PIPELINE_META_STATE_MASK & ~ST_NEW_CONSTANTS);
 
    struct pipe_sampler_view *view = NULL;
 
index 244df25..1ccdda1 100644 (file)
@@ -52,6 +52,7 @@
 #include "st_draw.h"
 #include "st_program.h"
 #include "st_cb_rasterpos.h"
+#include "st_util.h"
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
 #include "vbo/vbo.h"
index d47fe46..bf198ad 100644 (file)
@@ -85,9 +85,7 @@ prepare_draw(struct st_context *st, struct gl_context *ctx, uint64_t state_mask)
    st_invalidate_readpix_cache(st);
 
    /* Validate state. */
-   if (ctx->NewDriverState & st->active_states & state_mask) {
-      st_validate_state(st, state_mask);
-   }
+   st_validate_state(st, state_mask);
 
    /* Pin threads regularly to the same Zen CCX that the main thread is
     * running on. The main thread can move between CCXs.
index 32c098a..2fcbbf2 100644 (file)
@@ -106,6 +106,30 @@ st_point_size_per_vertex(struct gl_context *ctx)
    return false;
 }
 
+static inline void
+st_validate_state(struct st_context *st, uint64_t pipeline_state_mask)
+{
+   struct gl_context *ctx = st->ctx;
+
+   /* Inactive states are shader states not used by shaders at the moment. */
+   uint64_t dirty = ctx->NewDriverState & st->active_states & pipeline_state_mask;
+
+   if (dirty) {
+      ctx->NewDriverState &= ~dirty;
+
+      uint32_t dirty_lo = dirty;
+      uint32_t dirty_hi = dirty >> 32;
+
+      /* Update states. Don't use u_bit_scan64 because 64-bit ffs (x86 BSF)
+       * is slower on x86_64 and emulated on i386.
+       */
+      while (dirty_lo)
+         st_update_functions[u_bit_scan(&dirty_lo)](st);
+      while (dirty_hi)
+         st_update_functions[32 + u_bit_scan(&dirty_hi)](st);
+   }
+}
+
 #ifdef __cplusplus
 }
 #endif