@@ -35,8 +35,8 @@ typedef struct
35
35
void * frontbuffer ; /**< main screen buffer */
36
36
void * backbuffer ; /**< buffer presented to display */
37
37
uint64_t drawColor ;
38
- int32_t vsync_callback_id ;
39
38
uint8_t vsync ; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
39
+ SDL_bool vblank_not_reached ; /**< whether vblank wasn't reached */
40
40
} PSP_RenderData ;
41
41
42
42
typedef struct PSP_Texture
@@ -90,6 +90,12 @@ int SDL_PSP_RenderGetProp(SDL_Renderer *r, enum SDL_PSP_RenderProps which, void*
90
90
static int vsync_sema_id = 0 ;
91
91
92
92
/* PRIVATE METHODS */
93
+ static void psp_on_vblank (u32 sub , PSP_RenderData * data )
94
+ {
95
+ if (data ) {
96
+ data -> vblank_not_reached = SDL_FALSE ;
97
+ }
98
+ }
93
99
94
100
static unsigned int getMemorySize (unsigned int width , unsigned int height , unsigned int psm )
95
101
{
@@ -116,7 +122,7 @@ static unsigned int getMemorySize(unsigned int width, unsigned int height, unsig
116
122
}
117
123
}
118
124
119
- static int PixelFormatToPSPFMT (Uint32 format )
125
+ static int pixelFormatToPSPFMT (Uint32 format )
120
126
{
121
127
switch (format ) {
122
128
case SDL_PIXELFORMAT_BGR565 :
@@ -147,18 +153,13 @@ static int calculatePitchForTextureFormat(int width, int format)
147
153
}
148
154
149
155
/* Return next power of 2 */
150
- static int TextureNextPow2 ( unsigned int w )
156
+ static int calculateNextPow2 ( int value )
151
157
{
152
- unsigned int n = 2 ;
153
- if ( w == 0 ) {
154
- return 0 ;
158
+ int i = 1 ;
159
+ while ( i < value ) {
160
+ i <<= 1 ;
155
161
}
156
-
157
- while (w > n ) {
158
- n <<= 1 ;
159
- }
160
-
161
- return n ;
162
+ return i ;
162
163
}
163
164
164
165
static void PSP_WindowEvent (SDL_Renderer * renderer , const SDL_WindowEvent * event )
@@ -173,11 +174,11 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
173
174
return SDL_OutOfMemory ();
174
175
}
175
176
176
- psp_tex -> format = PixelFormatToPSPFMT (texture -> format );
177
+ psp_tex -> format = pixelFormatToPSPFMT (texture -> format );
177
178
psp_tex -> width = calculatePitchForTextureFormat (texture -> w , psp_tex -> format );
178
179
psp_tex -> height = texture -> h ;
179
- psp_tex -> textureWidth = TextureNextPow2 (texture -> w );
180
- psp_tex -> textureHeight = TextureNextPow2 (texture -> h );
180
+ psp_tex -> textureWidth = calculateNextPow2 (texture -> w );
181
+ psp_tex -> textureHeight = calculateNextPow2 (texture -> h );
181
182
psp_tex -> data = SDL_calloc (1 , getMemorySize (psp_tex -> width , psp_tex -> height , psp_tex -> format ));
182
183
183
184
if (!psp_tex -> data ) {
@@ -199,6 +200,7 @@ static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
199
200
(void * )((Uint8 * )psp_texture -> data + rect -> y * psp_texture -> width * SDL_BYTESPERPIXEL (texture -> format ) +
200
201
rect -> x * SDL_BYTESPERPIXEL (texture -> format ));
201
202
* pitch = psp_texture -> width * SDL_BYTESPERPIXEL (texture -> format );
203
+
202
204
return 0 ;
203
205
}
204
206
@@ -277,6 +279,7 @@ static int PSP_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c
277
279
verts -> y = points -> y ;
278
280
verts -> z = 0.0f ;
279
281
}
282
+
280
283
return 0 ;
281
284
}
282
285
@@ -406,6 +409,7 @@ static int PSP_RenderSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd
406
409
colorB = cmd -> data .color .b ;
407
410
colorA = cmd -> data .color .a ;
408
411
sceGuColor (GU_RGBA (colorR , colorG , colorB , colorA ));
412
+
409
413
return 0 ;
410
414
}
411
415
@@ -502,7 +506,6 @@ int PSP_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *c
502
506
PSP_SetBlendMode (data , cmd -> data .draw .blend );
503
507
sceGuDrawArray (GU_LINES , GU_VERTEX_32BITF | GU_TRANSFORM_2D , count , 0 , verts );
504
508
505
- /* We're done! */
506
509
return 0 ;
507
510
}
508
511
@@ -515,7 +518,6 @@ int PSP_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *
515
518
PSP_SetBlendMode (data , cmd -> data .draw .blend );
516
519
sceGuDrawArray (GU_POINTS , GU_VERTEX_32BITF | GU_TRANSFORM_2D , count , 0 , verts );
517
520
518
- /* We're done! */
519
521
return 0 ;
520
522
}
521
523
@@ -583,29 +585,16 @@ static int PSP_RenderPresent(SDL_Renderer *renderer)
583
585
{
584
586
PSP_RenderData * data = (PSP_RenderData * )renderer -> driverdata ;
585
587
586
- // if (data->gsGlobal->DoubleBuffering == GS_SETTING_OFF) {
587
- // if (data->vsync == 2) { // Dynamic
588
- // gsKit_sync(data->gsGlobal);
589
- // } else if (data->vsync == 1) {
590
- // gsKit_vsync_wait();
591
- // }
592
- // gsKit_queue_exec(data->gsGlobal);
593
- // } else {
594
- // gsKit_queue_exec(data->gsGlobal);
595
- // gsKit_finish();
596
- // if (data->vsync == 2) { // Dynamic
597
- // gsKit_sync(data->gsGlobal);
598
- // } else if (data->vsync == 1) {
599
- // gsKit_vsync_wait();
600
- // }
601
- // gsKit_flip(data->gsGlobal);
602
- // }
603
- // gsKit_TexManager_nextFrame(data->gsGlobal);
604
- // gsKit_clear(data->gsGlobal, GS_BLACK);
588
+ if (((data -> vsync == 2 ) && (data -> vblank_not_reached )) || // Dynamic
589
+ (data -> vsync == 1 )) { // Normal VSync
590
+ sceDisplayWaitVblankStart ();
591
+ }
592
+ data -> vblank_not_reached = SDL_TRUE ;
605
593
606
594
sceGuFinish ();
607
595
sceGuSync (0 ,0 );
608
- sceGuSwapBuffers ();
596
+ data -> backbuffer = data -> frontbuffer ;
597
+ data -> frontbuffer = vabsptr (sceGuSwapBuffers ());
609
598
610
599
// Starting a new frame
611
600
sceGuStart (GU_DIRECT ,list );
@@ -699,8 +688,14 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
699
688
sceDisplayWaitVblankStart ();
700
689
sceGuDisplay (GU_TRUE );
701
690
691
+ /* Improve performance when VSYC is enabled and it is not reaching the 60 FPS */
702
692
dynamicVsync = SDL_GetHintBoolean (SDL_HINT_PSP_DYNAMIC_VSYNC , SDL_FALSE );
703
693
data -> vsync = flags & SDL_RENDERER_PRESENTVSYNC ? (dynamicVsync ? 2 : 1 ) : 0 ;
694
+ if (data -> vsync == 2 ) {
695
+ sceKernelRegisterSubIntrHandler (PSP_VBLANK_INT , 0 , psp_on_vblank , data );
696
+ sceKernelEnableSubIntr (PSP_VBLANK_INT , 0 );
697
+ }
698
+ data -> vblank_not_reached = SDL_TRUE ;
704
699
705
700
renderer -> WindowEvent = PSP_WindowEvent ;
706
701
renderer -> CreateTexture = PSP_CreateTexture ;
0 commit comments