Improve performance when vsync is enabled and the game is not reaching the 60 FPS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c
index ebeddc2..124ede3 100644
--- a/src/render/psp/SDL_render_psp.c
+++ b/src/render/psp/SDL_render_psp.c
@@ -80,6 +80,8 @@ typedef struct
int currentBlendMode;
PSP_DrawStateCache drawstate;
+
+ SDL_bool vblank_not_reached; /**< wether vblank wasn't reached */
} PSP_RenderData;
@@ -175,6 +177,12 @@ TextureNextPow2(unsigned int w)
return n;
}
+static void psp_on_vblank(u32 sub, PSP_RenderData *data)
+{
+ if (data)
+ data->vblank_not_reached = SDL_FALSE;
+}
+
static int
PixelFormatToPSPFMT(Uint32 format)
@@ -1009,8 +1017,9 @@ PSP_RenderPresent(SDL_Renderer * renderer)
sceGuFinish();
sceGuSync(0,0);
-/* if(data->vsync) */
+ if ((data->vsync) && (data->vblank_not_reached))
sceDisplayWaitVblankStart();
+ data->vblank_not_reached = SDL_TRUE;
data->backbuffer = data->frontbuffer;
data->frontbuffer = vabsptr(sceGuSwapBuffers());
@@ -1044,6 +1053,10 @@ PSP_DestroyRenderer(SDL_Renderer * renderer)
StartDrawing(renderer);
+ sceKernelDisableSubIntr(PSP_VBLANK_INT, 0);
+ sceKernelReleaseSubIntrHandler(PSP_VBLANK_INT,0);
+ sceDisplayWaitVblankStart();
+ sceGuDisplay(GU_FALSE);
sceGuTerm();
/* vfree(data->backbuffer); */
/* vfree(data->frontbuffer); */
@@ -1179,6 +1192,11 @@ PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
sceDisplayWaitVblankStartCB();
sceGuDisplay(GU_TRUE);
+ /* Improve performance when VSYC is enabled and it is not reaching the 60 FPS */
+ data->vblank_not_reached = SDL_TRUE;
+ sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, data);
+ sceKernelEnableSubIntr(PSP_VBLANK_INT, 0);
+
return renderer;
}