From: Justin Weiss Date: Fri, 23 Oct 2020 05:27:53 +0000 (-0700) Subject: Allow threaded rendering for peops and enable on unix X-Git-Tag: r24l~614^2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a903b13150257ec490fe776fb5bc2e1fbc2a312e;p=pcsx_rearmed.git Allow threaded rendering for peops and enable on unix --- diff --git a/Makefile b/Makefile index d6cb946c..993b05e1 100644 --- a/Makefile +++ b/Makefile @@ -184,10 +184,6 @@ endif ifeq "$(BUILTIN_GPU)" "unai" CFLAGS += -DGPU_UNAI CFLAGS += -DUSE_GPULIB=1 -ifeq "$(THREAD_RENDERING)" "1" -CFLAGS += -DTHREAD_RENDERING -OBJS += plugins/gpulib/gpulib_thread_if.o -endif #CFLAGS += -DINLINE="static __inline__" #CFLAGS += -Dasm="__asm__ __volatile__" OBJS += plugins/gpu_unai/gpulib_if.o @@ -197,6 +193,10 @@ endif plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -O3 CC_LINK = $(CXX) endif +ifeq "$(THREAD_RENDERING)" "1" +CFLAGS += -DTHREAD_RENDERING +OBJS += plugins/gpulib/gpulib_thread_if.o +endif # cdrcimg OBJS += plugins/cdrcimg/cdrcimg.o diff --git a/Makefile.libretro b/Makefile.libretro index e58d63d2..6a387414 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -48,6 +48,7 @@ EXTRA_LDFLAGS = ifeq ($(platform), unix) TARGET := $(TARGET_NAME)_libretro.so fpic := -fPIC + THREAD_RENDERING = 1 ifneq ($(findstring SunOS,$(shell uname -s)),) CC = gcc endif diff --git a/frontend/libretro_core_options.h b/frontend/libretro_core_options.h index 1075e8f8..c28de2a3 100644 --- a/frontend/libretro_core_options.h +++ b/frontend/libretro_core_options.h @@ -972,6 +972,7 @@ struct retro_core_option_definition option_defs_us[] = { }, "disabled", }, +#endif /* GPU UNAI Advanced Settings */ #ifdef THREAD_RENDERING { "pcsx_rearmed_gpu_thread_rendering", @@ -986,7 +987,6 @@ struct retro_core_option_definition option_defs_us[] = { "disabled", }, #endif -#endif /* GPU UNAI Advanced Settings */ { "pcsx_rearmed_show_bios_bootlogo", diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index db0797cb..b2cca195 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -17,6 +17,22 @@ #include #include "../gpulib/gpu.h" +#ifdef THREAD_RENDERING +#include "../gpulib/gpulib_thread_if.h" +#define do_cmd_list real_do_cmd_list +#define renderer_init real_renderer_init +#define renderer_finish real_renderer_finish +#define renderer_sync_ecmds real_renderer_sync_ecmds +#define renderer_update_caches real_renderer_update_caches +#define renderer_flush_queues real_renderer_flush_queues +#define renderer_set_interlace real_renderer_set_interlace +#define renderer_set_config real_renderer_set_config +#define renderer_notify_res_change real_renderer_notify_res_change +#define renderer_notify_update_lace real_renderer_notify_update_lace +#define renderer_sync real_renderer_sync +#define ex_regs scratch_ex_regs +#endif + #define u32 uint32_t #define INFO_TW 0 diff --git a/plugins/gpulib/gpulib_thread_if.c b/plugins/gpulib/gpulib_thread_if.c index f0f607d6..c95f5295 100644 --- a/plugins/gpulib/gpulib_thread_if.c +++ b/plugins/gpulib/gpulib_thread_if.c @@ -18,12 +18,17 @@ ***************************************************************************/ #include +#include #include #include #include "../gpulib/gpu.h" #include "../../frontend/plugin_lib.h" #include "gpulib_thread_if.h" +#define FALSE 0 +#define TRUE 1 +#define BOOL unsigned short + typedef struct { uint32_t *cmd_list; int count; @@ -47,14 +52,14 @@ typedef struct { pthread_cond_t cond_queue_empty; video_thread_queue *queue; video_thread_queue *bg_queue; - bool running; + BOOL running; } video_thread_state; static video_thread_state thread; static video_thread_queue queues[2]; static int thread_rendering; -static bool hold_cmds; -static bool needs_display; +static BOOL hold_cmds; +static BOOL needs_display; extern const unsigned char cmd_lengths[]; @@ -62,7 +67,10 @@ static void *video_thread_main(void *arg) { video_thread_state *thread = (video_thread_state *)arg; video_thread_cmd *cmd; int i; + +#ifdef _3DS static int processed = 0; +#endif /* _3DS */ while(1) { int result, last_cmd, start, end; @@ -99,7 +107,7 @@ static void *video_thread_main(void *arg) { svcSleepThread(1); processed %= 512; } -#endif +#endif /* _3DS */ } pthread_mutex_lock(&thread->queue_lock); @@ -124,7 +132,7 @@ static void cmd_queue_swap() { tmp = thread.queue; thread.queue = thread.bg_queue; thread.bg_queue = tmp; - needs_display = true; + needs_display = TRUE; pthread_cond_signal(&thread.cond_msg_avail); } pthread_mutex_unlock(&thread.queue_lock); @@ -169,7 +177,7 @@ void renderer_sync(void) { * drop a frame. */ renderer_wait(); cmd_queue_swap(); - hold_cmds = false; + hold_cmds = FALSE; renderer_wait(); } @@ -178,7 +186,7 @@ static void video_thread_stop() { renderer_sync(); if (thread.running) { - thread.running = false; + thread.running = FALSE; pthread_cond_signal(&thread.cond_msg_avail); pthread_join(thread.thread, NULL); } @@ -215,7 +223,7 @@ static void video_thread_start() { thread.queue = &queues[0]; thread.bg_queue = &queues[1]; - thread.running = true; + thread.running = TRUE; return; error: @@ -227,7 +235,7 @@ static void video_thread_queue_cmd(uint32_t *list, int count, int last_cmd) { video_thread_cmd *cmd; uint32_t *cmd_list; video_thread_queue *queue; - bool lock; + BOOL lock; cmd_list = (uint32_t *)calloc(count, sizeof(uint32_t)); @@ -248,10 +256,10 @@ static void video_thread_queue_cmd(uint32_t *list, int count, int last_cmd) { if (hold_cmds) { queue = thread.bg_queue; - lock = false; + lock = FALSE; } else { queue = thread.queue; - lock = true; + lock = TRUE; } if (lock) { @@ -436,23 +444,23 @@ void renderer_notify_update_lace(int updated) { /* We are no longer holding commands back, so the next frame may * get mixed into the following frame. This is usually fine, but can * result in frameskip-like effects for 60fps games. */ - hold_cmds = false; - needs_display = true; - gpu.state.fb_dirty = true; + hold_cmds = FALSE; + needs_display = TRUE; + gpu.state.fb_dirty = TRUE; } else if (thread.queue->used) { /* We are still drawing during a vblank. Cut off the current frame * by sending new commands to the background queue and skip * drawing our partly rendered frame to the display. */ - hold_cmds = true; - needs_display = true; - gpu.state.fb_dirty = false; + hold_cmds = TRUE; + needs_display = TRUE; + gpu.state.fb_dirty = FALSE; } else if (needs_display && !thread.queue->used) { /* We have processed all commands in the queue, render the * buffer. We know we have something to render, because - * needs_display is true. */ - hold_cmds = false; - needs_display = false; - gpu.state.fb_dirty = true; + * needs_display is TRUE. */ + hold_cmds = FALSE; + needs_display = FALSE; + gpu.state.fb_dirty = TRUE; } else { /* Everything went normally, so do the normal thing. */ }