diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 06aa5045f1..afda2d1327 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -44,7 +44,9 @@ #include "../../configuration.h" #include "../../record/record_driver.h" +#ifdef PERF_ENABLE #include "../../performance_counters.h" +#endif #include "../../retroarch.h" #include "../../verbosity.h" @@ -688,10 +690,12 @@ static INLINE void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { +#ifdef PERF_ENABLE static struct retro_perf_counter copy_frame = {0}; performance_counter_init(copy_frame, "copy_frame"); performance_counter_start_plus(video_info->is_perfcnt_enable, copy_frame); +#endif #if defined(HAVE_PSGL) { @@ -821,7 +825,9 @@ static INLINE void gl_copy_frame(gl_t *gl, glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } #endif +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, copy_frame); +#endif } static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx) @@ -1091,14 +1097,16 @@ static bool gl_frame(void *data, const void *frame, video_shader_ctx_params_t params; struct video_tex_info feedback_info; video_shader_ctx_info_t shader_info; - static struct - retro_perf_counter frame_run = {0}; gl_t *gl = (gl_t*)data; unsigned width = video_info->width; unsigned height = video_info->height; +#ifdef PERF_ENABLE + static struct + retro_perf_counter frame_run = {0}; performance_counter_init(frame_run, "frame_run"); performance_counter_start_plus(video_info->is_perfcnt_enable, frame_run); +#endif if (!gl) return false; @@ -1289,7 +1297,9 @@ static bool gl_frame(void *data, const void *frame, video_context_driver_update_window_title(video_info); +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, frame_run); +#endif #ifdef HAVE_FBO /* Reset state which could easily mess up libretro core. */ @@ -1347,11 +1357,14 @@ static bool gl_frame(void *data, const void *frame, #ifdef HAVE_GL_SYNC if (video_info->hard_sync && gl->have_sync) { +#ifdef PERF_ENABLE static struct retro_perf_counter gl_fence = {0}; performance_counter_init(gl_fence, "gl_fence"); performance_counter_start_plus(video_info->is_perfcnt_enable, gl_fence); +#endif + glClear(GL_COLOR_BUFFER_BIT); gl->fences[gl->fence_count++] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); @@ -1367,8 +1380,10 @@ static bool gl_frame(void *data, const void *frame, gl->fence_count * sizeof(GLsync)); } +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, gl_fence); +#endif } #endif diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index cf45ae5b8a..76c8f47a51 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -43,7 +43,9 @@ #include "../../driver.h" #include "../../configuration.h" #include "../../record/record_driver.h" +#ifdef PERF_ENABLE #include "../../performance_counters.h" +#endif #include "../../retroarch.h" #include "../../verbosity.h" @@ -1581,6 +1583,7 @@ static bool vulkan_frame(void *data, const void *frame, VkSemaphore signal_semaphores[2]; vk_t *vk = (vk_t*)data; struct vk_per_frame *chain = NULL; +#ifdef PERF_ENABLE static struct retro_perf_counter frame_run = {0}; static struct retro_perf_counter begin_cmd = {0}; static struct retro_perf_counter build_cmd = {0}; @@ -1588,6 +1591,7 @@ static bool vulkan_frame(void *data, const void *frame, static struct retro_perf_counter copy_frame = {0}; static struct retro_perf_counter swapbuffers = {0}; static struct retro_perf_counter queue_submit = {0}; +#endif bool waits_for_semaphores = false; unsigned width = video_info->width; unsigned height = video_info->height; @@ -1602,6 +1606,7 @@ static bool vulkan_frame(void *data, const void *frame, unsigned frame_index = vk->context->current_swapchain_index; +#ifdef PERF_ENABLE performance_counter_init(frame_run, "frame_run"); performance_counter_init(copy_frame, "copy_frame"); performance_counter_init(swapbuffers, "swapbuffers"); @@ -1611,6 +1616,7 @@ static bool vulkan_frame(void *data, const void *frame, performance_counter_init(end_cmd, "end_command"); performance_counter_start_plus(video_info->is_perfcnt_enable, frame_run); +#endif /* Bookkeeping on start of frame. */ chain = &vk->swapchain[frame_index]; @@ -1620,14 +1626,18 @@ static bool vulkan_frame(void *data, const void *frame, vulkan_buffer_chain_discard(&chain->vbo); vulkan_buffer_chain_discard(&chain->ubo); +#ifdef PERF_ENABLE performance_counter_start_plus(video_info->is_perfcnt_enable, begin_cmd); +#endif /* Start recording the command buffer. */ vk->cmd = chain->cmd; begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; vkResetCommandBuffer(vk->cmd, 0); vkBeginCommandBuffer(vk->cmd, &begin_info); +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, begin_cmd); +#endif memset(&vk->tracker, 0, sizeof(vk->tracker)); @@ -1652,7 +1662,9 @@ static bool vulkan_frame(void *data, const void *frame, } /* Upload texture */ +#ifdef PERF_ENABLE performance_counter_start_plus(video_info->is_perfcnt_enable, copy_frame); +#endif if (frame && !vk->hw.enable) { unsigned y; @@ -1703,13 +1715,17 @@ static bool vulkan_frame(void *data, const void *frame, vk->last_valid_index = frame_index; } +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, copy_frame); +#endif /* Notify filter chain about the new sync index. */ vulkan_filter_chain_notify_sync_index((vulkan_filter_chain_t*)vk->filter_chain, frame_index); vulkan_filter_chain_set_frame_count((vulkan_filter_chain_t*)vk->filter_chain, frame_count); +#ifdef PERF_ENABLE performance_counter_start_plus(video_info->is_perfcnt_enable, build_cmd); +#endif /* Render offscreen filter chain passes. */ { /* Set the source texture in the filter chain */ @@ -1838,7 +1854,9 @@ static bool vulkan_frame(void *data, const void *frame, if (vk->overlay.enable) vulkan_render_overlay(vk, video_info); #endif +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, build_cmd); +#endif /* End the render pass. We're done rendering to backbuffer now. */ vkCmdEndRenderPass(vk->cmd); @@ -1907,9 +1925,13 @@ static bool vulkan_frame(void *data, const void *frame, vk->context->graphics_queue_index, vk->hw.src_queue_family); } +#ifdef PERF_ENABLE performance_counter_start_plus(video_info->is_perfcnt_enable, end_cmd); +#endif vkEndCommandBuffer(vk->cmd); +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, end_cmd); +#endif /* Submit command buffers to GPU. */ @@ -1951,9 +1973,11 @@ static bool vulkan_frame(void *data, const void *frame, } submit_info.pSignalSemaphores = submit_info.signalSemaphoreCount ? signal_semaphores : NULL; +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, frame_run); performance_counter_start_plus(video_info->is_perfcnt_enable, queue_submit); +#endif #ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); @@ -1963,11 +1987,17 @@ static bool vulkan_frame(void *data, const void *frame, #ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); #endif - performance_counter_stop_plus(video_info->is_perfcnt_enable, queue_submit); +#ifdef PERF_ENABLE + performance_counter_stop_plus(video_info->is_perfcnt_enable, queue_submit); performance_counter_start_plus(video_info->is_perfcnt_enable, swapbuffers); +#endif + video_context_driver_swap_buffers(video_info); + +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, swapbuffers); +#endif if (!vk->context->swap_interval_emulation_lock) video_context_driver_update_window_title(video_info); diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index dbc7e90c21..729cc35186 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -26,7 +26,9 @@ #include "font_driver.h" #include "video_shader_driver.h" +#ifdef PERF_ENABLE #include "../performance_counters.h" +#endif #include "../runloop.h" #include "../verbosity.h" @@ -713,7 +715,9 @@ static bool video_thread_frame(void *data, const void *frame_, unsigned pitch, const char *msg, video_frame_info_t *video_info) { unsigned copy_stride; +#ifdef PERF_ENABLE static struct retro_perf_counter thr_frame = {0}; +#endif const uint8_t *src = NULL; uint8_t *dst = NULL; thread_video_t *thr = (thread_video_t*)data; @@ -730,8 +734,10 @@ static bool video_thread_frame(void *data, const void *frame_, return false; } +#ifdef PERF_ENABLE performance_counter_init(thr_frame, "thr_frame"); performance_counter_start_plus(video_info->is_perfcnt_enable, thr_frame); +#endif copy_stride = width * (thr->info.rgb32 ? sizeof(uint32_t) : sizeof(uint16_t)); @@ -800,7 +806,9 @@ static bool video_thread_frame(void *data, const void *frame_, slock_unlock(thr->lock); +#ifdef PERF_ENABLE performance_counter_stop_plus(video_info->is_perfcnt_enable, thr_frame); +#endif thr->last_time = cpu_features_get_time_usec(); return true;