diff --git a/frontend/drivers/platform_wiiu.c b/frontend/drivers/platform_wiiu.c index 49fdeead2f..7325e3ab6f 100644 --- a/frontend/drivers/platform_wiiu.c +++ b/frontend/drivers/platform_wiiu.c @@ -48,6 +48,7 @@ #include #include +#include #include #include #include @@ -383,6 +384,16 @@ void SaveCallback() OSSavesDone_ReadyToRelease(); } +static bool swap_is_pending(void* start_time) +{ + uint32_t swap_count, flip_count; + OSTime last_flip , last_vsync; + + GX2GetSwapStatus(&swap_count, &flip_count, &last_flip, &last_vsync); + + return last_vsync < *(OSTime*)start_time; +} + int main(int argc, char **argv) { #if 1 @@ -447,12 +458,20 @@ int main(int argc, char **argv) do { unsigned sleep_ms = 0; + + if(video_driver_get_ptr(false)) + { + OSTime start_time = OSGetSystemTime(); + task_queue_wait(swap_is_pending, &start_time); + } + else + task_queue_wait(NULL, NULL); + int ret = runloop_iterate(&sleep_ms); if (ret == 1 && sleep_ms > 0) retro_sleep(sleep_ms); - task_queue_wait(); if (ret == -1) break; diff --git a/gfx/drivers/wiiu_gfx.c b/gfx/drivers/wiiu_gfx.c index 980473cd6e..58b08cd458 100644 --- a/gfx/drivers/wiiu_gfx.c +++ b/gfx/drivers/wiiu_gfx.c @@ -502,12 +502,6 @@ static bool wiiu_gfx_frame(void* data, const void* frame, wiiu_video_t* wiiu = (wiiu_video_t*) data; - if (!width || !height) - { - GX2WaitForVsync(); - return true; - } - if(wiiu->vsync) { uint32_t swap_count; @@ -527,6 +521,10 @@ static bool wiiu_gfx_frame(void* data, const void* frame, } GX2WaitForFlip(); + + if (!width || !height) + return true; + static u32 lastTick , currentTick; currentTick = OSGetSystemTick(); u32 diff = currentTick - lastTick; diff --git a/libretro-common/include/queues/task_queue.h b/libretro-common/include/queues/task_queue.h index 5910c15dd6..28322ad6be 100644 --- a/libretro-common/include/queues/task_queue.h +++ b/libretro-common/include/queues/task_queue.h @@ -57,6 +57,8 @@ typedef void (*retro_task_queue_msg_t)(const char *msg, typedef bool (*retro_task_retriever_t)(retro_task_t *task, void *data); +typedef bool (*retro_task_condition_fn_t)(void *data); + typedef struct { char *source_file; @@ -200,9 +202,12 @@ void task_queue_check(void); * The task will start as soon as possible. */ void task_queue_push(retro_task_t *task); -/* Blocks until all tasks have finished. +/* Blocks until all tasks have finished + * will return early if cond is not NULL + * and cond(data) returns false. * This must only be called from the main thread. */ -void task_queue_wait(void); +void task_queue_wait(retro_task_condition_fn_t cond, void* data); + /* Sends a signal to terminate all the tasks. * diff --git a/libretro-common/queues/task_queue.c b/libretro-common/queues/task_queue.c index b8782e8399..bc92e7b3f9 100644 --- a/libretro-common/queues/task_queue.c +++ b/libretro-common/queues/task_queue.c @@ -47,7 +47,7 @@ struct retro_task_impl void (*push_running)(retro_task_t *); void (*cancel)(void *); void (*reset)(void); - void (*wait)(void); + void (*wait)(retro_task_condition_fn_t, void *); void (*gather)(void); bool (*find)(retro_task_finder_t, void*); void (*retrieve)(task_retriever_data_t *data); @@ -189,9 +189,9 @@ static void retro_task_regular_gather(void) retro_task_internal_gather(); } -static void retro_task_regular_wait(void) +static void retro_task_regular_wait(retro_task_condition_fn_t cond, void* data) { - while (tasks_running.front) + while (tasks_running.front && (!cond || cond(data))) retro_task_regular_gather(); } @@ -373,7 +373,7 @@ static void retro_task_threaded_gather(void) slock_unlock(property_lock); } -static void retro_task_threaded_wait(void) +static void retro_task_threaded_wait(retro_task_condition_fn_t cond, void* data) { bool wait = false; @@ -382,7 +382,8 @@ static void retro_task_threaded_wait(void) retro_task_threaded_gather(); slock_lock(running_lock); - wait = (tasks_running.front != NULL); + wait = (tasks_running.front != NULL) && + (!cond || cond(data)); slock_unlock(running_lock); } while (wait); } @@ -637,9 +638,9 @@ void task_queue_push(retro_task_t *task) impl_current->push_running(task); } -void task_queue_wait(void) +void task_queue_wait(retro_task_condition_fn_t cond, void* data) { - impl_current->wait(); + impl_current->wait(cond, data); } void task_queue_reset(void)