3ds: use proper stack size for drc thread
authornotaz <notasas@gmail.com>
Sun, 22 Feb 2026 23:40:13 +0000 (01:40 +0200)
committernotaz <notasas@gmail.com>
Sun, 22 Feb 2026 23:40:13 +0000 (01:40 +0200)
frontend/pcsxr-threads.c
libpcsxcore/new_dynarec/new_dynarec.c
libpcsxcore/new_dynarec/new_dynarec.h

index 1c1ff2e..7847252 100644 (file)
@@ -6,6 +6,7 @@
 #include <3ds/os.h>
 #include <3ds/services/apt.h>
 #include <sys/time.h>
+#include "../libpcsxcore/new_dynarec/new_dynarec.h"
 #endif
 
 #include "../deps/libretro-common/rthreads/rthreads.c"
@@ -45,6 +46,7 @@ sthread_t *pcsxr_sthread_create(void (*thread_func)(void *),
 {
        sthread_t *h = NULL;
 #ifdef _3DS
+       size_t stack_size = 64*1024;
        Thread ctr_thread;
        int core_id = 0;
        s32 prio = 0x30;
@@ -61,6 +63,8 @@ sthread_t *pcsxr_sthread_create(void (*thread_func)(void *),
                core_id = 1;
                break;
        case PCSXRT_DRC:
+               stack_size = new_dynarec_estimate_stack_size();
+               // fallthrough
        case PCSXRT_GPU:
                core_id = is_new_3ds ? 2 : 1;
                break;
@@ -68,18 +72,19 @@ sthread_t *pcsxr_sthread_create(void (*thread_func)(void *),
                break;
        }
 
-       ctr_thread = threadCreate(thread_func, NULL, STACKSIZE, prio, core_id, false);
+       ctr_thread = threadCreate(thread_func, NULL, stack_size, prio, core_id, false);
        if (!ctr_thread) {
                if (core_id == 1) {
                        SysPrintf("threadCreate pcsxt %d core %d failed\n",
                                type, core_id);
                        core_id = is_new_3ds ? 2 : -1;
-                       ctr_thread = threadCreate(thread_func, NULL, STACKSIZE,
+                       ctr_thread = threadCreate(thread_func, NULL, stack_size,
                                prio, core_id, false);
                }
        }
+       SysPrintf("threadCreate: pcsxt %d core %d stack %zd: %p\n",
+               type, core_id, stack_size, ctr_thread);
        if (!ctr_thread) {
-               SysPrintf("threadCreate pcsxt %d core %d failed\n", type, core_id);
                free(h);
                return NULL;
        }
index 004d036..ecef746 100644 (file)
@@ -6715,6 +6715,12 @@ void new_dynarec_print_stats(void)
 #endif
 }
 
+int new_dynarec_estimate_stack_size(void)
+{
+  // see: pass6_clean_registers
+  return (sizeof(struct compile_state) + (4+4) * MAXBLOCK + 20 * 1024) & ~4095;
+}
+
 static void force_intcall(int i)
 {
   memset(&dops[i], 0, sizeof(dops[i]));
index 0d3a686..c597821 100644 (file)
@@ -36,6 +36,7 @@ void new_dynarec_clear_full(void);
 int  new_dynarec_save_blocks(void *save, int size);
 void new_dynarec_load_blocks(const void *save, int size);
 void new_dynarec_print_stats(void);
+int  new_dynarec_estimate_stack_size(void);
 
 int  new_dynarec_quick_check_range(unsigned int start, unsigned int end);
 void new_dynarec_invalidate_range(unsigned int start, unsigned int end);