From b244864a61d5a5b40eefaa8f9b7b4d46361ae056 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 20 Dec 2024 01:04:28 +0200 Subject: [PATCH] gpu: some timing improvements libretro/pcsx_rearmed#857 notaz/pcsx_rearmed#217 --- frontend/plugin_lib.h | 2 +- libpcsxcore/gpu.c | 9 ++++++--- libpcsxcore/gpu.h | 2 +- plugins/gpulib/gpu.c | 11 ++++++----- plugins/gpulib/gpu.h | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h index 420f89f9..31acae97 100644 --- a/frontend/plugin_lib.h +++ b/frontend/plugin_lib.h @@ -63,7 +63,7 @@ struct rearmed_cbs { void (*pl_vout_set_raw_vram)(void *vram); void (*pl_set_gpu_caps)(int caps); // emulation related - void (*gpu_state_change)(int what); + void (*gpu_state_change)(int what, int cycles); // some stats, for display by some plugins int flips_per_sec, cpu_usage; float vsps_cur; // currect vsync/s diff --git a/libpcsxcore/gpu.c b/libpcsxcore/gpu.c index 425537d4..b86cfe65 100644 --- a/libpcsxcore/gpu.c +++ b/libpcsxcore/gpu.c @@ -13,7 +13,7 @@ #include "gpu.h" #include "psxdma.h" -void gpu_state_change(int what) +void gpu_state_change(int what, int cycles) { enum psx_gpu_state state = what; switch (state) @@ -22,10 +22,13 @@ void gpu_state_change(int what) psxRegs.gpuIdleAfter = psxRegs.cycle + PSXCLK / 50; break; case PGS_VRAM_TRANSFER_END: - psxRegs.gpuIdleAfter = psxRegs.cycle; + psxRegs.gpuIdleAfter = psxRegs.cycle - 1; break; case PGS_PRIMITIVE_START: - psxRegs.gpuIdleAfter = psxRegs.cycle + 200; + // limit because gpulib delays things with it's buffering... + if (cycles > 512) + cycles = 512; + psxRegs.gpuIdleAfter = psxRegs.cycle + cycles - 1; break; } } diff --git a/libpcsxcore/gpu.h b/libpcsxcore/gpu.h index ec5019c9..69474b45 100644 --- a/libpcsxcore/gpu.h +++ b/libpcsxcore/gpu.h @@ -49,6 +49,6 @@ enum psx_gpu_state { PGS_PRIMITIVE_START, // for non-dma only }; -void gpu_state_change(int what); +void gpu_state_change(int what, int cycles); #endif /* __GPU_H__ */ diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index 677e18b5..ac9b86a3 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -514,7 +514,7 @@ static noinline void start_vram_transfer(struct psx_gpu *gpu, uint32_t pos_word, log_io(gpu, "start_vram_transfer %c (%d, %d) %dx%d\n", is_read ? 'r' : 'w', gpu->dma.x, gpu->dma.y, gpu->dma.w, gpu->dma.h); if (gpu->gpu_state_change) - gpu->gpu_state_change(PGS_VRAM_TRANSFER_START); + gpu->gpu_state_change(PGS_VRAM_TRANSFER_START, 0); } static void finish_vram_transfer(struct psx_gpu *gpu, int is_read) @@ -540,7 +540,7 @@ static void finish_vram_transfer(struct psx_gpu *gpu, int is_read) gpu->dma_start.w, gpu->dma_start.h, 0); } if (gpu->gpu_state_change) - gpu->gpu_state_change(PGS_VRAM_TRANSFER_END); + gpu->gpu_state_change(PGS_VRAM_TRANSFER_END, 0); } static void do_vram_copy(struct psx_gpu *gpu, const uint32_t *params, int *cpu_cycles) @@ -749,14 +749,15 @@ static noinline int do_cmd_buffer(struct psx_gpu *gpu, uint32_t *data, int count static noinline void flush_cmd_buffer(struct psx_gpu *gpu) { + int cycles_last = 0; int dummy = 0, left; - left = do_cmd_buffer(gpu, gpu->cmd_buffer, gpu->cmd_len, &dummy, &dummy); + left = do_cmd_buffer(gpu, gpu->cmd_buffer, gpu->cmd_len, &dummy, &cycles_last); if (left > 0) memmove(gpu->cmd_buffer, gpu->cmd_buffer + gpu->cmd_len - left, left * 4); if (left != gpu->cmd_len) { - if (!gpu->dma.h && gpu->gpu_state_change) - gpu->gpu_state_change(PGS_PRIMITIVE_START); gpu->cmd_len = left; + if (!gpu->dma.h && gpu->gpu_state_change) + gpu->gpu_state_change(PGS_PRIMITIVE_START, cycles_last); } } diff --git a/plugins/gpulib/gpu.h b/plugins/gpulib/gpu.h index 7a84a254..893a7512 100644 --- a/plugins/gpulib/gpu.h +++ b/plugins/gpulib/gpu.h @@ -117,7 +117,7 @@ struct psx_gpu { (int *x, int *y, int *w, int *h, int *vram_h); void *(*mmap)(unsigned int size); void (*munmap)(void *ptr, unsigned int size); - void (*gpu_state_change)(int what); // psx_gpu_state + void (*gpu_state_change)(int what, int cycles); // psx_gpu_state }; extern struct psx_gpu gpu; -- 2.39.5