enable gpu thread by default
authornotaz <notasas@gmail.com>
Sat, 14 Mar 2026 23:38:59 +0000 (01:38 +0200)
committernotaz <notasas@gmail.com>
Sun, 15 Mar 2026 20:59:24 +0000 (22:59 +0200)
should work with c11 threads too

frontend/libretro.c
frontend/libretro_core_options.h
frontend/menu.c
frontend/pcsxr-threads.c
frontend/pcsxr-threads.h
frontend/plugin_lib.h
plugins/gpulib/gpu.c
plugins/gpulib/gpu_async.c
plugins/gpulib/gpu_async.h

index 4040b3e..9124626 100644 (file)
@@ -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
 
index 73bc0d3..f073498 100644 (file)
@@ -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
    {
index 05c8a08..a7706ab 100644 (file)
@@ -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)";
index 7847252..3f6348d 100644 (file)
@@ -7,22 +7,24 @@
 #include <3ds/services/apt.h>
 #include <sys/time.h>
 #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 <unistd.h>
+#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();
+}
index 977830e..48c06b6 100644 (file)
@@ -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); \
index 11282d4..1118f20 100644 (file)
@@ -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;
index 1ccd151..bc1150e 100644 (file)
@@ -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
index 7c9e882..373663d 100644 (file)
@@ -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);
 
index 65eafab..6524894 100644 (file)
@@ -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