From: notaz Date: Sat, 14 Mar 2026 23:38:59 +0000 (+0200) Subject: enable gpu thread by default X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d2d32cf39e90a56899a76b2eda45f61a020ad6;p=pcsx_rearmed.git enable gpu thread by default should work with c11 threads too --- diff --git a/frontend/libretro.c b/frontend/libretro.c index 4040b3e4..9124626b 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -2730,8 +2730,10 @@ static void update_variables(bool in_flight) { if (strcmp(var.value, "enabled") == 0) pl_rearmed_cbs.thread_rendering = 1; - else + else if (strcmp(var.value, "disabled") == 0) pl_rearmed_cbs.thread_rendering = 0; + else + pl_rearmed_cbs.thread_rendering = -1; // auto } #endif diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 73bc0d3d..f073498e 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -334,15 +334,16 @@ struct retro_core_option_v2_definition option_defs_us[] = { "pcsx_rearmed_gpu_thread_rendering", "Threaded Rendering", NULL, - "When enabled, runs GPU commands in a secondary thread.", + "When enabled, runs GPU commands in a secondary thread. 'Auto' enables it if at least 2 CPU cores are detected.", NULL, "video", { + { "auto", "Auto" }, { "disabled", NULL }, { "enabled", NULL }, { NULL, NULL}, }, - "disabled", + "auto", }, #endif { diff --git a/frontend/menu.c b/frontend/menu.c index 05c8a085..a7706abe 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -1542,6 +1542,8 @@ static int menu_loop_plugin_spu(int id, int keys) return 0; } +static const char *men_autooo[] = { "Auto", "Off", "On", NULL }; + static const char *men_gpu_dithering[] = { "OFF", "ON", "Force", NULL }; static const char *men_bios_boot[] = { "OFF", "ON", "ON w/o PCSX", NULL }; @@ -1606,15 +1608,13 @@ static int menu_loop_pluginsel_options(int id, int keys) return 0; } -static int slowboot_sel; - static menu_entry e_menu_plugin_options[] = { mee_enum_h ("BIOS", 0, bios_sel, bioses, h_bios), - mee_enum ("BIOS logo (slow boot)", 0, slowboot_sel, men_bios_boot), + mee_enum ("BIOS logo (slow boot)", 0, menu_iopts[0], men_bios_boot), mee_enum_h ("GPU plugin", 0, gpu_plugsel, gpu_plugins, h_plugin_gpu), #ifdef USE_ASYNC_GPU - mee_onoff ("GPU multithreading", 0, pl_rearmed_cbs.thread_rendering, 1), + mee_enum ("GPU multithreading", 0, menu_iopts[1], men_autooo), #endif mee_enum ("GPU dithering", 0, pl_rearmed_cbs.dithering, men_gpu_dithering), mee_enum_h ("SPU plugin", 0, spu_plugsel, spu_plugins, h_plugin_spu), @@ -1631,12 +1631,14 @@ static menu_entry e_menu_main2[]; static int menu_loop_plugin_options(int id, int keys) { static int sel = 0; - slowboot_sel = Config.SlowBoot; + menu_iopts[0] = Config.SlowBoot; + menu_iopts[1] = pl_rearmed_cbs.thread_rendering + 1; #ifndef C64X_DSP me_enable(e_menu_plugin_options, MA_OPT_SPU_THREAD, spu_config.iThreadAvail); #endif me_loop(e_menu_plugin_options, &sel); - Config.SlowBoot = slowboot_sel; + Config.SlowBoot = menu_iopts[0]; + pl_rearmed_cbs.thread_rendering = menu_iopts[1] - 1; // sync BIOS/plugins snprintf(Config.Bios[0], sizeof(Config.Bios[0]), "%s", bioses[bios_sel]); @@ -1678,8 +1680,6 @@ static int menu_loop_speed_hacks(int id, int keys) return 0; } -static const char *men_autooo[] = { "Auto", "Off", "On", NULL }; - static const char h_cfg_cpul[] = "Shows CPU usage in %"; static const char h_cfg_spu[] = "Shows active SPU channels\n" "(green: normal, red: fmod, blue: noise)"; diff --git a/frontend/pcsxr-threads.c b/frontend/pcsxr-threads.c index 78472526..3f6348de 100644 --- a/frontend/pcsxr-threads.c +++ b/frontend/pcsxr-threads.c @@ -7,22 +7,24 @@ #include <3ds/services/apt.h> #include #include "../libpcsxcore/new_dynarec/new_dynarec.h" +static bool is_new_3ds; #endif - -#include "../deps/libretro-common/rthreads/rthreads.c" -#include "features/features_cpu.h" #include "pcsxr-threads.h" +int pcsxr_sthread_core_count; + // pcsxr "extensions" extern void SysPrintf(const char *fmt, ...); -#ifdef _3DS -static bool is_new_3ds; -#endif +#ifndef USE_C11_THREADS -void pcsxr_sthread_init(void) +#include "../deps/libretro-common/rthreads/rthreads.c" +#include "features/features_cpu.h" + +#define CORE_COUNT() cpu_features_get_core_amount() + +static void pcsxr_sthread_lib_init(void) { - SysPrintf("%d cpu core(s) detected\n", cpu_features_get_core_amount()); #ifdef _3DS int64_t version = 0; int fpscr = -1; @@ -104,3 +106,21 @@ sthread_t *pcsxr_sthread_create(void (*thread_func)(void *), #endif return h; } + +#else // USE_C11_THREADS + +#include +#define CORE_COUNT() sysconf(_SC_NPROCESSORS_ONLN) +#define pcsxr_sthread_lib_init() + +#endif + +void pcsxr_sthread_init(void) +{ + pcsxr_sthread_core_count = CORE_COUNT(); + if (pcsxr_sthread_core_count < 1) + pcsxr_sthread_core_count = 1; + SysPrintf("%d cpu core(s) detected\n", pcsxr_sthread_core_count); + + pcsxr_sthread_lib_init(); +} diff --git a/frontend/pcsxr-threads.h b/frontend/pcsxr-threads.h index 977830e0..48c06b6d 100644 --- a/frontend/pcsxr-threads.h +++ b/frontend/pcsxr-threads.h @@ -10,6 +10,10 @@ enum pcsxr_thread_type PCSXRT_COUNT // must be last }; +extern int pcsxr_sthread_core_count; + +void pcsxr_sthread_init(void); + #ifndef USE_C11_THREADS /* use libretro-common rthreads */ @@ -18,7 +22,6 @@ enum pcsxr_thread_type #define STRHEAD_RET_TYPE void #define STRHEAD_RETURN() -void pcsxr_sthread_init(void); sthread_t *pcsxr_sthread_create(void (*thread_func)(void*), enum pcsxr_thread_type type); @@ -30,8 +33,6 @@ sthread_t *pcsxr_sthread_create(void (*thread_func)(void*), #define STRHEAD_RET_TYPE int #define STRHEAD_RETURN() return 0 -#define pcsxr_sthread_init() - #define slock_new() ({ \ mtx_t *lock = malloc(sizeof(*lock)); \ if (lock) mtx_init(lock, mtx_plain); \ diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index 11282d49..1118f20c 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -77,9 +77,9 @@ struct rearmed_cbs { unsigned int *gpu_hcnt; unsigned int flip_cnt; // increment manually if not using pl_vout_flip unsigned int only_16bpp; // platform is 16bpp-only - unsigned int thread_rendering; unsigned int dithering; // 0 off, 1 on, 2 force unsigned int scale_hires; + int thread_rendering; // -1 auto, 0 off, 1 on struct { int allow_interlace; // 0 off, 1 on, 2 guess int enhancement_enable; diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 1ccd151e..bc1150e1 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -1254,10 +1254,7 @@ void GPUrearmedCallbacks(const struct rearmed_cbs *cbs) renderer_set_config(cbs); vout_set_config(cbs); - if (cbs->thread_rendering) - gpu_async_start(&gpu); - else - gpu_async_stop(&gpu); + gpu_async_enable(&gpu, cbs->thread_rendering); } // for standalone plugins only diff --git a/plugins/gpulib/gpu_async.c b/plugins/gpulib/gpu_async.c index 7c9e8820..373663d4 100644 --- a/plugins/gpulib/gpu_async.c +++ b/plugins/gpulib/gpu_async.c @@ -859,11 +859,17 @@ void gpu_async_stop(struct psx_gpu *gpu) } } -void gpu_async_start(struct psx_gpu *gpu) +void gpu_async_enable(struct psx_gpu *gpu, int enable) { struct psx_gpu_async *agpu; - if (gpu->async) + if (enable < 0) + enable = pcsxr_sthread_core_count > 1; + if (!gpu->async == !enable) return; + if (!enable) { + gpu_async_stop(gpu); + return; + } assert(AGPU_DMA_MAX <= AGPU_BUF_LEN / 2); diff --git a/plugins/gpulib/gpu_async.h b/plugins/gpulib/gpu_async.h index 65eafab8..65248945 100644 --- a/plugins/gpulib/gpu_async.h +++ b/plugins/gpulib/gpu_async.h @@ -15,7 +15,7 @@ struct psx_gpu_async; int gpu_async_do_cmd_list(struct psx_gpu *gpu, const uint32_t *list, int list_len, int *cycles_sum_out, int *cycles_last, int *last_cmd, int *vram_dirty); int gpu_async_try_dma(struct psx_gpu *gpu, const uint32_t *data, int words); -void gpu_async_start(struct psx_gpu *gpu); +void gpu_async_enable(struct psx_gpu *gpu, int enable); void gpu_async_stop(struct psx_gpu *gpu); void gpu_async_sync(struct psx_gpu *gpu); int gpu_async_sync_scanout(struct psx_gpu *gpu); @@ -29,7 +29,7 @@ void gpu_async_set_interlace(struct psx_gpu *gpu, int enable, int is_odd); #define gpu_async_enabled(gpu) 0 #define gpu_async_do_cmd_list(gpu, list, list_len, c0, c1, cmd, vrd) (list_len) #define gpu_async_try_dma(gpu, data, words) 0 -#define gpu_async_start(gpu) +#define gpu_async_enable(gpu, enable) #define gpu_async_stop(gpu) #define gpu_async_sync(gpu) do {} while (0) #define gpu_async_sync_scanout(gpu) 0