diff --git a/src/mesa/main/compute.c b/src/mesa/main/compute.c index 9ad499040b7..5b1f352bf34 100644 --- a/src/mesa/main/compute.c +++ b/src/mesa/main/compute.c @@ -296,6 +296,7 @@ prepare_compute(struct gl_context *ctx) _mesa_update_state(ctx); st_validate_state(st, ST_PIPELINE_COMPUTE_STATE_MASK); + st_context_add_work(st); } static ALWAYS_INLINE void diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index c8e51b71b27..86d00a242cd 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -299,7 +299,7 @@ void _mesa_glthread_enable(struct gl_context *ctx) ctx->GLApi = ctx->MarshalExec; /* glthread takes over all thread scheduling. */ - ctx->st->pin_thread_counter = ST_THREAD_SCHEDULER_DISABLED; + ctx->st->thread_scheduler_disabled = true; /* Update the dispatch only if the dispatch is current. */ if (GET_DISPATCH() == ctx->Dispatch.Current) { @@ -319,7 +319,7 @@ void _mesa_glthread_disable(struct gl_context *ctx) /* Re-enable thread scheduling in st/mesa when glthread is disabled. */ if (ctx->pipe->set_context_param && util_thread_scheduler_enabled()) - ctx->st->pin_thread_counter = 0; + ctx->st->thread_scheduler_disabled = false; /* Update the dispatch only if the dispatch is current. */ if (GET_DISPATCH() == ctx->MarshalExec) { diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index ef4d81e8748..506b521cc7c 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -717,7 +717,7 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->shader_has_one_variant[MESA_SHADER_COMPUTE] = st->has_shareable_shaders; if (!st->pipe->set_context_param || !util_thread_scheduler_enabled()) - st->pin_thread_counter = ST_THREAD_SCHEDULER_DISABLED; + st->thread_scheduler_disabled = true; st->bitmap.cache.empty = true; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index b5c51082527..68740071b88 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -39,7 +39,7 @@ #include "vbo/vbo.h" #include "util/list.h" #include "cso_cache/cso_context.h" - +#include "util/u_cpu_detect.h" #ifdef __cplusplus extern "C" { @@ -53,8 +53,6 @@ struct st_context; struct st_program; struct u_upload_mgr; -#define ST_THREAD_SCHEDULER_DISABLED 0xffffffff - struct st_bitmap_cache { /** Window pos to render the cached image */ @@ -141,10 +139,11 @@ struct st_context struct draw_stage *selection_stage; /**< For GL_SELECT rendermode */ struct draw_stage *rastpos_stage; /**< For glRasterPos */ - unsigned pin_thread_counter; /* for L3 thread pinning on AMD Zen */ + unsigned work_counter; /* for L3 thread pinning on AMD Zen and resource pruning */ GLboolean clamp_frag_color_in_shader; GLboolean clamp_vert_color_in_shader; + bool thread_scheduler_disabled; bool has_stencil_export; /**< can do shader stencil export? */ bool has_time_elapsed; bool has_etc1; @@ -517,6 +516,37 @@ st_api_destroy_drawable(struct pipe_frontend_drawable *drawable); void st_screen_destroy(struct pipe_frontend_screen *fscreen); +static inline void +st_context_apply_scheduler_policy(struct st_context *st) +{ + int cpu = util_get_current_cpu(); + if (cpu >= 0) { + struct pipe_context *pipe = st->pipe; + uint16_t L3_cache = util_get_cpu_caps()->cpu_to_L3[cpu]; + + if (L3_cache != U_CPU_INVALID_L3) { + pipe->set_context_param(pipe, + PIPE_CONTEXT_PARAM_UPDATE_THREAD_SCHEDULING, + cpu); + } + } +} + +static inline void +st_context_add_work(struct st_context *st) +{ + + /* Apply our thread scheduling policy for better multithreading + * performance. + */ + if (unlikely(++st->work_counter % 512 == 0)) { + st->work_counter = 0; + if (!st->thread_scheduler_disabled) + st_context_apply_scheduler_policy(st); + } +} + + #ifdef __cplusplus } #endif diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 6df165c3723..55c7e50d5e4 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -55,7 +55,6 @@ #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "util/u_cpu_detect.h" #include "util/u_inlines.h" #include "util/format/u_format.h" #include "util/u_prim.h" @@ -87,27 +86,7 @@ st_prepare_draw(struct gl_context *ctx, uint64_t state_mask) /* Validate state. */ st_validate_state(st, state_mask); - - /* Apply our thread scheduling policy for better multithreading - * performance. - */ - if (unlikely(st->pin_thread_counter != ST_THREAD_SCHEDULER_DISABLED && - /* do it occasionally */ - ++st->pin_thread_counter % 512 == 0)) { - st->pin_thread_counter = 0; - - int cpu = util_get_current_cpu(); - if (cpu >= 0) { - struct pipe_context *pipe = st->pipe; - uint16_t L3_cache = util_get_cpu_caps()->cpu_to_L3[cpu]; - - if (L3_cache != U_CPU_INVALID_L3) { - pipe->set_context_param(pipe, - PIPE_CONTEXT_PARAM_UPDATE_THREAD_SCHEDULING, - cpu); - } - } - } + st_context_add_work(st); } void