(WiiU) only wait for vsync when not missed.
This commit is contained in:
parent
e268630b84
commit
6f7f6a363b
|
@ -88,8 +88,8 @@ typedef struct
|
||||||
|
|
||||||
wiiu_render_mode_t render_mode;
|
wiiu_render_mode_t render_mode;
|
||||||
int frames;
|
int frames;
|
||||||
bool noblock;
|
OSTime last_vsync;
|
||||||
int syncframes;
|
bool vsync;
|
||||||
} wiiu_video_t;
|
} wiiu_video_t;
|
||||||
|
|
||||||
static const wiiu_render_mode_t wiiu_render_mode_map[] =
|
static const wiiu_render_mode_t wiiu_render_mode_map[] =
|
||||||
|
@ -216,7 +216,7 @@ static void* wiiu_gfx_init(const video_info_t* video,
|
||||||
GX2_DISABLE, GX2_BLEND_MODE_ONE, GX2_BLEND_MODE_ZERO, GX2_BLEND_COMBINE_MODE_ADD);
|
GX2_DISABLE, GX2_BLEND_MODE_ONE, GX2_BLEND_MODE_ZERO, GX2_BLEND_COMBINE_MODE_ADD);
|
||||||
#endif
|
#endif
|
||||||
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_DISABLE);
|
GX2SetCullOnlyControl(GX2_FRONT_FACE_CCW, GX2_DISABLE, GX2_DISABLE);
|
||||||
GX2SetSwapInterval(1);
|
GX2SetSwapInterval(0);
|
||||||
|
|
||||||
/* init shader */
|
/* init shader */
|
||||||
// wiiu->shader = MEM2_alloc(sizeof(*wiiu->shader), GX2_VERTEX_BUFFER_ALIGNMENT);
|
// wiiu->shader = MEM2_alloc(sizeof(*wiiu->shader), GX2_VERTEX_BUFFER_ALIGNMENT);
|
||||||
|
@ -326,8 +326,7 @@ static void* wiiu_gfx_init(const video_info_t* video,
|
||||||
GX2SetTVEnable(GX2_ENABLE);
|
GX2SetTVEnable(GX2_ENABLE);
|
||||||
GX2SetDRCEnable(GX2_ENABLE);
|
GX2SetDRCEnable(GX2_ENABLE);
|
||||||
|
|
||||||
wiiu->noblock = false;
|
wiiu->vsync = true;
|
||||||
wiiu->syncframes = 60;
|
|
||||||
|
|
||||||
return wiiu;
|
return wiiu;
|
||||||
}
|
}
|
||||||
|
@ -385,29 +384,61 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
|
||||||
unsigned width, unsigned height, uint64_t frame_count,
|
unsigned width, unsigned height, uint64_t frame_count,
|
||||||
unsigned pitch, const char* msg)
|
unsigned pitch, const char* msg)
|
||||||
{
|
{
|
||||||
(void)frame;
|
|
||||||
(void)width;
|
|
||||||
(void)height;
|
|
||||||
(void)pitch;
|
|
||||||
(void)msg;
|
(void)msg;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
wiiu_video_t* wiiu = (wiiu_video_t*) data;
|
wiiu_video_t* wiiu = (wiiu_video_t*) data;
|
||||||
if(wiiu->menu.enable || wiiu->noblock == false)
|
|
||||||
wiiu->syncframes = 60;
|
|
||||||
else if(wiiu->syncframes > 0)
|
|
||||||
wiiu->syncframes--;
|
|
||||||
GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
// GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.3f, 0.8f, 1.0f);
|
|
||||||
/* can't call GX2ClearColor after GX2SetContextState for whatever reason */
|
|
||||||
GX2SetContextState(wiiu->ctx_state);
|
|
||||||
|
|
||||||
if (!width || !height)
|
if (!width || !height)
|
||||||
{
|
{
|
||||||
GX2WaitForVsync();
|
GX2WaitForVsync();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(wiiu->vsync)
|
||||||
|
{
|
||||||
|
uint32_t swap_count;
|
||||||
|
uint32_t flip_count;
|
||||||
|
OSTime last_flip;
|
||||||
|
OSTime last_vsync;
|
||||||
|
|
||||||
|
GX2GetSwapStatus(&swap_count, &flip_count, &last_flip, &last_vsync);
|
||||||
|
|
||||||
|
if(wiiu->last_vsync >= last_vsync)
|
||||||
|
{
|
||||||
|
GX2WaitForVsync();
|
||||||
|
wiiu->last_vsync = last_vsync + ms_to_ticks(17);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wiiu->last_vsync = last_vsync;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 lastTick , currentTick;
|
||||||
|
currentTick = OSGetSystemTick();
|
||||||
|
u32 diff = currentTick - lastTick;
|
||||||
|
static float fps;
|
||||||
|
static u32 frames;
|
||||||
|
frames++;
|
||||||
|
if(diff > wiiu_timer_clock)
|
||||||
|
{
|
||||||
|
fps = (float)frames * ((float) wiiu_timer_clock / (float) diff);
|
||||||
|
lastTick = currentTick;
|
||||||
|
frames = 0;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
static u32 last_frame_tick;
|
||||||
|
if (!(wiiu->menu.enable))
|
||||||
|
printf("\r frame time : %10.6f ms \n", (float)(currentTick - last_frame_tick) * 1000.0f / (float)wiiu_timer_clock);
|
||||||
|
last_frame_tick = currentTick;
|
||||||
|
#endif
|
||||||
|
printf("\rfps: %8.8f frames : %5i", fps, wiiu->frames++);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
/* can't call GX2ClearColor after GX2SetContextState for whatever reason */
|
||||||
|
GX2SetContextState(wiiu->ctx_state);
|
||||||
|
|
||||||
|
|
||||||
if(frame)
|
if(frame)
|
||||||
{
|
{
|
||||||
if (width > wiiu->texture.surface.width)
|
if (width > wiiu->texture.surface.width)
|
||||||
|
@ -424,7 +455,6 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
|
||||||
|
|
||||||
for (i = 0; i < height; i++)
|
for (i = 0; i < height; i++)
|
||||||
{
|
{
|
||||||
// memcpy(dst, src, width * sizeof(uint16_t));
|
|
||||||
int j;
|
int j;
|
||||||
for(j = 0; j < width; j++)
|
for(j = 0; j < width; j++)
|
||||||
dst[j] = __builtin_bswap16(src[j]);
|
dst[j] = __builtin_bswap16(src[j]);
|
||||||
|
@ -461,24 +491,6 @@ static bool wiiu_gfx_frame(void* data, const void* frame,
|
||||||
|
|
||||||
GX2SwapScanBuffers();
|
GX2SwapScanBuffers();
|
||||||
GX2Flush();
|
GX2Flush();
|
||||||
if(wiiu->syncframes)
|
|
||||||
GX2WaitForVsync();
|
|
||||||
|
|
||||||
static u32 lastTick , currentTick;
|
|
||||||
currentTick = OSGetSystemTick();
|
|
||||||
u32 diff = currentTick - lastTick;
|
|
||||||
static float fps;
|
|
||||||
static u32 frames;
|
|
||||||
frames++;
|
|
||||||
if(diff > wiiu_timer_clock)
|
|
||||||
{
|
|
||||||
fps = (float)frames * ((float) wiiu_timer_clock / (float) diff);
|
|
||||||
lastTick = currentTick;
|
|
||||||
frames = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\rfps: %8.4f frames : %5i", fps, wiiu->frames++);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -490,8 +502,8 @@ static void wiiu_gfx_set_nonblock_state(void* data, bool toggle)
|
||||||
if (!wiiu)
|
if (!wiiu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wiiu->noblock = toggle;
|
wiiu->vsync = !toggle;
|
||||||
GX2SetSwapInterval(!toggle);
|
/* GX2SetSwapInterval(!toggle); */ /* do we need this ? */
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wiiu_gfx_alive(void* data)
|
static bool wiiu_gfx_alive(void* data)
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
EXPORT_BEGIN(gx2.rpl);
|
EXPORT_BEGIN(gx2.rpl);
|
||||||
|
|
||||||
#include "../rpl/libgx2/exports.h"
|
#include "../rpl/libgx2/exports.h"
|
||||||
|
EXPORT(GX2GetSwapStatus);
|
||||||
EXPORT_END();
|
EXPORT_END();
|
||||||
|
|
|
@ -13,7 +13,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
|
//#define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0)
|
||||||
#define DEBUG_LINE() do{printf("%s:%d.\n",__FUNCTION__, __LINE__);fflush(stdout);}while(0)
|
#define DEBUG_LINE() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);}while(0)
|
||||||
#define DEBUG_STR(X) printf( "%s: %s\n", #X, (char*)(X))
|
#define DEBUG_STR(X) printf( "%s: %s\n", #X, (char*)(X))
|
||||||
#define DEBUG_VAR(X) printf( "%-20s: 0x%08X\n", #X, (u32)(X))
|
#define DEBUG_VAR(X) printf( "%-20s: 0x%08X\n", #X, (u32)(X))
|
||||||
#define DEBUG_VAR2(X) printf( "%-20s: 0x%08X (%i)\n", #X, (u32)(X), (int)(X))
|
#define DEBUG_VAR2(X) printf( "%-20s: 0x%08X (%i)\n", #X, (u32)(X), (int)(X))
|
||||||
|
|
Loading…
Reference in New Issue