gpu: some timing improvements
authornotaz <notasas@gmail.com>
Thu, 19 Dec 2024 23:04:28 +0000 (01:04 +0200)
committernotaz <notasas@gmail.com>
Thu, 19 Dec 2024 23:04:28 +0000 (01:04 +0200)
libretro/pcsx_rearmed#857
notaz/pcsx_rearmed#217

frontend/plugin_lib.h
libpcsxcore/gpu.c
libpcsxcore/gpu.h
plugins/gpulib/gpu.c
plugins/gpulib/gpu.h

index 420f89f..31acae9 100644 (file)
@@ -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
index 425537d..b86cfe6 100644 (file)
@@ -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;
        }
 }
index ec5019c..69474b4 100644 (file)
@@ -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__ */
index 677e18b..ac9b86a 100644 (file)
@@ -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);
   }
 }
 
index 7a84a25..893a751 100644 (file)
@@ -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;