diff --git a/audio/audio_driver.c b/audio/audio_driver.c index 7e20f384e1..a12827e48a 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -511,6 +511,7 @@ void audio_driver_set_nonblocking_state(bool enable) static bool audio_driver_flush(const int16_t *data, size_t samples) { struct resampler_data src_data; + bool is_perfcnt_enable = false; bool is_paused = false; bool is_idle = false; bool is_slowmotion = false; @@ -530,18 +531,19 @@ static bool audio_driver_flush(const int16_t *data, size_t samples) if (recording_data) recording_push_audio(data, samples); - runloop_get_status(&is_paused, &is_idle, &is_slowmotion); + runloop_get_status(&is_paused, &is_idle, &is_slowmotion, + &is_perfcnt_enable); if (is_paused || settings->audio.mute_enable) return true; if (!audio_driver_active || !audio_driver_input_data) return false; - performance_counter_init(&audio_convert_s16, "audio_convert_s16"); - performance_counter_start(&audio_convert_s16); + performance_counter_init(audio_convert_s16, "audio_convert_s16"); + performance_counter_start_plus(is_perfcnt_enable, audio_convert_s16); convert_s16_to_float(audio_driver_input_data, data, samples, audio_driver_volume_gain); - performance_counter_stop(&audio_convert_s16); + performance_counter_stop_plus(is_perfcnt_enable, audio_convert_s16); src_data.data_in = audio_driver_input_data; src_data.input_frames = samples >> 1; @@ -560,10 +562,10 @@ static bool audio_driver_flush(const int16_t *data, size_t samples) dsp_data.input = audio_driver_input_data; dsp_data.input_frames = samples >> 1; - performance_counter_init(&audio_dsp, "audio_dsp"); - performance_counter_start(&audio_dsp); + performance_counter_init(audio_dsp, "audio_dsp"); + performance_counter_start_plus(is_perfcnt_enable, audio_dsp); retro_dsp_filter_process(audio_driver_dsp, &dsp_data); - performance_counter_stop(&audio_dsp); + performance_counter_stop_plus(is_perfcnt_enable, audio_dsp); if (dsp_data.output) { @@ -607,11 +609,11 @@ static bool audio_driver_flush(const int16_t *data, size_t samples) if (is_slowmotion) src_data.ratio *= settings->slowmotion_ratio; - performance_counter_init(&resampler_proc, "resampler_proc"); - performance_counter_start(&resampler_proc); + performance_counter_init(resampler_proc, "resampler_proc"); + performance_counter_start_plus(is_perfcnt_enable, resampler_proc); audio_driver_resampler->process(audio_driver_resampler_data, &src_data); - performance_counter_stop(&resampler_proc); + performance_counter_stop_plus(is_perfcnt_enable, resampler_proc); output_data = audio_driver_output_samples_buf; output_frames = src_data.output_frames; @@ -620,11 +622,11 @@ static bool audio_driver_flush(const int16_t *data, size_t samples) { static struct retro_perf_counter audio_convert_float = {0}; - performance_counter_init(&audio_convert_float, "audio_convert_float"); - performance_counter_start(&audio_convert_float); + performance_counter_init(audio_convert_float, "audio_convert_float"); + performance_counter_start_plus(is_perfcnt_enable, audio_convert_float); convert_float_to_s16(audio_driver_output_samples_conv_buf, (const float*)output_data, output_frames * 2); - performance_counter_stop(&audio_convert_float); + performance_counter_stop_plus(is_perfcnt_enable, audio_convert_float); output_data = audio_driver_output_samples_conv_buf; output_size = sizeof(int16_t); diff --git a/audio/drivers/ctr_csnd_audio.c b/audio/drivers/ctr_csnd_audio.c index e7b2115549..7b7e8452d1 100644 --- a/audio/drivers/ctr_csnd_audio.c +++ b/audio/drivers/ctr_csnd_audio.c @@ -176,8 +176,8 @@ static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size) (void)samples_played; (void)current_tick; - performance_counter_init(&ctraudio_f, "ctraudio_f"); - performance_counter_start(&ctraudio_f); + performance_counter_init(ctraudio_f, "ctraudio_f"); + performance_counter_start(ctraudio_f); ctr_csnd_audio_update_playpos(ctr); @@ -209,7 +209,7 @@ static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size) GSPGPU_FlushDataCache(ctr->l, CTR_CSND_AUDIO_SIZE); GSPGPU_FlushDataCache(ctr->r, CTR_CSND_AUDIO_SIZE); - performance_counter_stop(&ctraudio_f); + performance_counter_stop(ctraudio_f); return size; } diff --git a/audio/drivers/ctr_dsp_audio.c b/audio/drivers/ctr_dsp_audio.c index 66578bba5c..d04b840915 100644 --- a/audio/drivers/ctr_dsp_audio.c +++ b/audio/drivers/ctr_dsp_audio.c @@ -116,8 +116,8 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size) } } - performance_counter_init(&ctraudio_dsp_f, "ctraudio_dsp_f"); - performance_counter_start(&ctraudio_dsp_f); + performance_counter_init(ctraudio_dsp_f, "ctraudio_dsp_f"); + performance_counter_start(ctraudio_dsp_f); pos = ctr->pos << 2; @@ -140,7 +140,7 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size) ctr->pos += size >> 2; ctr->pos &= CTR_DSP_AUDIO_COUNT_MASK; - performance_counter_stop(&ctraudio_dsp_f); + performance_counter_stop(ctraudio_dsp_f); return size; } diff --git a/audio/drivers/wiiu_audio.c b/audio/drivers/wiiu_audio.c index 93e6fa97da..6cdc7ab333 100644 --- a/audio/drivers/wiiu_audio.c +++ b/audio/drivers/wiiu_audio.c @@ -205,8 +205,8 @@ static ssize_t ax_audio_write(void* data, const void* buf, size_t size) return 0; /* Measure copy performance from here */ - performance_counter_init(&ax_audio_write_perf, "ax_audio_write"); - performance_counter_start(&ax_audio_write_perf); + performance_counter_init(ax_audio_write_perf, "ax_audio_write"); + performance_counter_start(ax_audio_write_perf); if(count > AX_AUDIO_MAX_FREE) count = AX_AUDIO_MAX_FREE; @@ -286,7 +286,7 @@ static ssize_t ax_audio_write(void* data, const void* buf, size_t size) ax_audio_start(ax, false); /* Done copying new data */ - performance_counter_stop(&ax_audio_write_perf); + performance_counter_stop(ax_audio_write_perf); /* return what was actually copied */ return (count << 2); diff --git a/camera/drivers/video4linux2.c b/camera/drivers/video4linux2.c index a73a47b588..e616fae073 100644 --- a/camera/drivers/video4linux2.c +++ b/camera/drivers/video4linux2.c @@ -70,10 +70,10 @@ static void process_image(video4linux_t *v4l, const uint8_t *buffer_yuv) { static struct retro_perf_counter yuv_convert_direct = {0}; - performance_counter_init(&yuv_convert_direct, "yuv_convert_direct"); - performance_counter_start(&yuv_convert_direct); + performance_counter_init(yuv_convert_direct, "yuv_convert_direct"); + performance_counter_start(yuv_convert_direct); scaler_ctx_scale(&v4l->scaler, v4l->buffer_output, buffer_yuv); - performance_counter_stop(&yuv_convert_direct); + performance_counter_stop(yuv_convert_direct); } static int xioctl(int fd, int request, void *args) diff --git a/command.c b/command.c index 7517eb71ee..51c1b8d32e 100644 --- a/command.c +++ b/command.c @@ -2378,8 +2378,10 @@ bool command_event(enum event_command cmd, void *data) bool is_paused = false; bool is_idle = false; bool is_slowmotion = false; + bool is_perfcnt_enable = false; - runloop_get_status(&is_paused, &is_idle, &is_slowmotion); + runloop_get_status(&is_paused, &is_idle, &is_slowmotion, + &is_perfcnt_enable); if (is_paused) { diff --git a/dynamic.c b/dynamic.c index 48b9b4874b..4d18ad1380 100644 --- a/dynamic.c +++ b/dynamic.c @@ -952,6 +952,21 @@ static bool dynamic_verify_hw_context(enum retro_hw_context_type type, return true; } +static void core_performance_counter_start(struct retro_perf_counter *perf) +{ + if (runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL)) + { + perf->call_cnt++; + perf->start = cpu_features_get_perf_counter(); + } +} + +static void core_performance_counter_stop(struct retro_perf_counter *perf) +{ + if (runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL)) + perf->total += cpu_features_get_perf_counter() - perf->start; +} + /** * rarch_environment_cb: * @cmd : Identifier of command. @@ -1410,8 +1425,8 @@ bool rarch_environment_cb(unsigned cmd, void *data) cb->get_perf_counter = cpu_features_get_perf_counter; cb->perf_register = performance_counter_register; - cb->perf_start = performance_counter_start; - cb->perf_stop = performance_counter_stop; + cb->perf_start = core_performance_counter_start; + cb->perf_stop = core_performance_counter_stop; cb->perf_log = retro_perf_log; break; } diff --git a/gfx/common/vulkan_common.c b/gfx/common/vulkan_common.c index 6aebc3e1e0..2d69e891c4 100644 --- a/gfx/common/vulkan_common.c +++ b/gfx/common/vulkan_common.c @@ -2241,10 +2241,10 @@ void vulkan_acquire_next_image(gfx_ctx_vulkan_data_t *vk) { static struct retro_perf_counter fence_wait = {0}; - performance_counter_init(&fence_wait, "fence_wait"); - performance_counter_start(&fence_wait); + performance_counter_init(fence_wait, "fence_wait"); + performance_counter_start(fence_wait); vkWaitForFences(vk->context.device, 1, next_fence, true, UINT64_MAX); - performance_counter_stop(&fence_wait); + performance_counter_stop(fence_wait); vkResetFences(vk->context.device, 1, next_fence); } diff --git a/gfx/drivers/ctr_gfx.c b/gfx/drivers/ctr_gfx.c index 76158f9f81..65d8fbb86c 100644 --- a/gfx/drivers/ctr_gfx.c +++ b/gfx/drivers/ctr_gfx.c @@ -464,6 +464,9 @@ static bool ctr_frame(void* data, const void* frame, uint32_t diff; static uint64_t currentTick,lastTick; touchPosition state_tmp_touch; + extern GSPGPU_FramebufferInfo topFramebufferInfo; + extern u8* gfxSharedMemory; + extern u8 gfxThreadID; uint32_t state_tmp = 0; ctr_video_t *ctr = (ctr_video_t*)data; static float fps = 0.0; @@ -609,8 +612,8 @@ static bool ctr_frame(void* data, const void* frame, #endif fflush(stdout); - performance_counter_init(&ctrframe_f, "ctrframe_f"); - performance_counter_start(&ctrframe_f); + performance_counter_init(ctrframe_f, "ctrframe_f"); + performance_counter_start_plus(video_info->is_perfcnt_enable, ctrframe_f); if (ctr->should_resize) ctr_update_viewport(ctr); @@ -802,38 +805,44 @@ static bool ctr_frame(void* data, const void* frame, /* Swap buffers : */ - extern GSPGPU_FramebufferInfo topFramebufferInfo; - extern u8* gfxSharedMemory; - extern u8 gfxThreadID; - topFramebufferInfo.active_framebuf=ctr->current_buffer_top; - topFramebufferInfo.framebuf0_vaddr=(u32*)gfxTopLeftFramebuffers[ctr->current_buffer_top]; + topFramebufferInfo. + active_framebuf = ctr->current_buffer_top; + topFramebufferInfo. + framebuf0_vaddr = (u32*)gfxTopLeftFramebuffers[ctr->current_buffer_top]; + if(ctr->video_mode == CTR_VIDEO_MODE_800x240) { - topFramebufferInfo.framebuf1_vaddr=(u32*)(gfxTopLeftFramebuffers[ctr->current_buffer_top] + 240 * 3); - topFramebufferInfo.framebuf_widthbytesize = 240 * 3 * 2; + topFramebufferInfo. + framebuf1_vaddr = (u32*)(gfxTopLeftFramebuffers[ctr->current_buffer_top] + 240 * 3); + topFramebufferInfo. + framebuf_widthbytesize = 240 * 3 * 2; } else { - topFramebufferInfo.framebuf1_vaddr=(u32*)gfxTopRightFramebuffers[ctr->current_buffer_top]; - topFramebufferInfo.framebuf_widthbytesize = 240 * 3; + topFramebufferInfo. + framebuf1_vaddr = (u32*)gfxTopRightFramebuffers[ctr->current_buffer_top]; + topFramebufferInfo. + framebuf_widthbytesize = 240 * 3; } - topFramebufferInfo.format=(1<<8)|(1<<5)|GSP_BGR8_OES; - topFramebufferInfo.framebuf_dispselect=ctr->current_buffer_top; - topFramebufferInfo.unk=0x00000000; + topFramebufferInfo.format = (1<<8)|(1<<5)|GSP_BGR8_OES; + topFramebufferInfo. + framebuf_dispselect = ctr->current_buffer_top; + topFramebufferInfo.unk = 0x00000000; - u8* framebufferInfoHeader=gfxSharedMemory+0x200+gfxThreadID*0x80; - GSPGPU_FramebufferInfo* framebufferInfo=(GSPGPU_FramebufferInfo*)&framebufferInfoHeader[0x4]; - framebufferInfoHeader[0x0] ^= 1; + u8* framebufferInfoHeader = gfxSharedMemory+0x200+gfxThreadID*0x80; + GSPGPU_FramebufferInfo* + framebufferInfo = (GSPGPU_FramebufferInfo*)&framebufferInfoHeader[0x4]; + framebufferInfoHeader[0x0] ^= 1; framebufferInfo[framebufferInfoHeader[0x0]] = topFramebufferInfo; - framebufferInfoHeader[0x1]=1; + framebufferInfoHeader[0x1] = 1; - ctr->current_buffer_top ^= 1; - ctr->p3d_event_pending = true; - ctr->ppf_event_pending = true; - performance_counter_stop(&ctrframe_f); + ctr->current_buffer_top ^= 1; + ctr->p3d_event_pending = true; + ctr->ppf_event_pending = true; + performance_counter_stop_plus(video_info->is_perfcnt_enable, ctrframe_f); return true; } diff --git a/gfx/drivers/d3d.cpp b/gfx/drivers/d3d.cpp index 03f1af93d0..a7ad7b53de 100644 --- a/gfx/drivers/d3d.cpp +++ b/gfx/drivers/d3d.cpp @@ -1387,8 +1387,8 @@ static bool d3d_frame(void *data, const void *frame, if (!frame) return true; - performance_counter_init(&d3d_frame, "d3d_frame"); - performance_counter_start(&d3d_frame); + performance_counter_init(d3d_frame, "d3d_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, d3d_frame); /* We cannot recover in fullscreen. */ if (d3d->needs_restore) @@ -1467,7 +1467,7 @@ static bool d3d_frame(void *data, const void *frame, video_context_driver_update_window_title(video_info); - performance_counter_stop(&d3d_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, d3d_frame); video_context_driver_swap_buffers(video_info); diff --git a/gfx/drivers/d3d_renderchains/render_chain_cg.cpp b/gfx/drivers/d3d_renderchains/render_chain_cg.cpp index 7c25bcbf5c..d9141f6fe1 100644 --- a/gfx/drivers/d3d_renderchains/render_chain_cg.cpp +++ b/gfx/drivers/d3d_renderchains/render_chain_cg.cpp @@ -1530,8 +1530,8 @@ static bool cg_d3d9_renderchain_read_viewport(void *data, uint8_t *buffer) video_driver_get_size(&width, &height); - performance_counter_init(&d3d_read_viewport, "d3d_read_viewport"); - performance_counter_start(&d3d_read_viewport); + performance_counter_init(d3d_read_viewport, "d3d_read_viewport"); + performance_counter_start(d3d_read_viewport); (void)data; (void)buffer; @@ -1583,7 +1583,7 @@ static bool cg_d3d9_renderchain_read_viewport(void *data, uint8_t *buffer) ret = false; end: - performance_counter_stop(&d3d_read_viewport); + performance_counter_stop(d3d_read_viewport); if (target) target->Release(); if (dest) diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 31a3c97729..d92615aa75 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -689,8 +689,8 @@ static INLINE void gl_copy_frame(gl_t *gl, { static struct retro_perf_counter copy_frame = {0}; - performance_counter_init(©_frame, "copy_frame"); - performance_counter_start(©_frame); + performance_counter_init(copy_frame, "copy_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, copy_frame); #if defined(HAVE_PSGL) { @@ -820,7 +820,7 @@ static INLINE void gl_copy_frame(gl_t *gl, glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } #endif - performance_counter_stop(©_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, copy_frame); } static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx) @@ -994,8 +994,8 @@ static void gl_pbo_async_readback(gl_t *gl) video_pixel_get_alignment(gl->vp.width * sizeof(uint32_t))); /* Read asynchronously into PBO buffer. */ - performance_counter_init(&async_readback, "async_readback"); - performance_counter_start(&async_readback); + performance_counter_init(async_readback, "async_readback"); + performance_counter_start(async_readback); glReadBuffer(GL_BACK); #ifdef HAVE_OPENGLES3 glReadPixels(gl->vp.x, gl->vp.y, @@ -1006,7 +1006,7 @@ static void gl_pbo_async_readback(gl_t *gl) gl->vp.width, gl->vp.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); #endif - performance_counter_stop(&async_readback); + performance_counter_stop(async_readback); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); } @@ -1101,8 +1101,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width = video_info->width; unsigned height = video_info->height; - performance_counter_init(&frame_run, "frame_run"); - performance_counter_start(&frame_run); + performance_counter_init(frame_run, "frame_run"); + performance_counter_start_plus(video_info->is_perfcnt_enable, frame_run); if (!gl) return false; @@ -1293,7 +1293,7 @@ static bool gl_frame(void *data, const void *frame, video_context_driver_update_window_title(video_info); - performance_counter_stop(&frame_run); + performance_counter_stop_plus(video_info->is_perfcnt_enable, frame_run); #ifdef HAVE_FBO /* Reset state which could easily mess up libretro core. */ @@ -1353,8 +1353,9 @@ static bool gl_frame(void *data, const void *frame, { static struct retro_perf_counter gl_fence = {0}; - performance_counter_init(&gl_fence, "gl_fence"); - performance_counter_start(&gl_fence); + performance_counter_init(gl_fence, "gl_fence"); + performance_counter_start_plus(video_info->is_perfcnt_enable, + gl_fence); glClear(GL_COLOR_BUFFER_BIT); gl->fences[gl->fence_count++] = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); @@ -1370,7 +1371,8 @@ static bool gl_frame(void *data, const void *frame, gl->fence_count * sizeof(GLsync)); } - performance_counter_stop(&gl_fence); + performance_counter_stop_plus(video_info->is_perfcnt_enable, + gl_fence); } #endif @@ -2371,8 +2373,8 @@ static bool gl_read_viewport(void *data, uint8_t *buffer, bool is_idle) context_bind_hw_render(false); - performance_counter_init(&read_viewport, "read_viewport"); - performance_counter_start(&read_viewport); + performance_counter_init(read_viewport, "read_viewport"); + performance_counter_start(read_viewport); num_pixels = gl->vp.width * gl->vp.height; @@ -2438,7 +2440,7 @@ static bool gl_read_viewport(void *data, uint8_t *buffer, bool is_idle) if (!gl->readback_buffer_screenshot) { - performance_counter_stop(&read_viewport); + performance_counter_stop(read_viewport); goto error; } @@ -2454,7 +2456,7 @@ static bool gl_read_viewport(void *data, uint8_t *buffer, bool is_idle) gl->readback_buffer_screenshot = NULL; } - performance_counter_stop(&read_viewport); + performance_counter_stop(read_viewport); context_bind_hw_render(true); return true; diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 05f132b229..c72670cf7f 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -1451,8 +1451,8 @@ static bool gx_frame(void *data, const void *frame, fps_text_buf[0] = '\0'; - performance_counter_init(&gx_frame, "gx_frame"); - performance_counter_start(&gx_frame); + performance_counter_init(gx_frame, "gx_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, gx_frame); if(!gx || (!frame && !gx->menu_texture_enable)) return true; @@ -1487,8 +1487,8 @@ static bool gx_frame(void *data, const void *frame, { static struct retro_perf_counter gx_frame_convert = {0}; - performance_counter_init(&gx_frame_convert, "gx_frame_convert"); - performance_counter_start(&gx_frame_convert); + performance_counter_init(gx_frame_convert, "gx_frame_convert"); + performance_counter_start_plus(video_info->is_perfcnt_enable, gx_frame_convert); if (gx->rgb32) convert_texture32(frame, g_tex.data, width, height, pitch); @@ -1498,7 +1498,7 @@ static bool gx_frame(void *data, const void *frame, convert_texture16(frame, g_tex.data, width, height, pitch); DCFlushRange(g_tex.data, height * (width << (gx->rgb32 ? 2 : 1))); - performance_counter_stop(&gx_frame_convert); + performance_counter_stop_plus(video_info->is_perfcnt_enable, gx_frame_convert); } if (gx->menu_texture_enable && gx->menu_data) @@ -1580,7 +1580,7 @@ static bool gx_frame(void *data, const void *frame, VIDEO_SetNextFramebuffer(gx->framebuf[g_current_framebuf]); VIDEO_Flush(); - performance_counter_stop(&gx_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, gx_frame); return true; } diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index 8dbc974eb4..09893d8628 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -534,8 +534,8 @@ static bool psp_frame(void *data, const void *frame, psp->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers()); - performance_counter_init(&psp_frame_run, "psp_frame_run"); - performance_counter_start(&psp_frame_run); + performance_counter_init(psp_frame_run, "psp_frame_run"); + performance_counter_start_plus(video_info->is_perfcnt_enable, psp_frame_run); if (psp->should_resize) psp_update_viewport(psp, video_info); @@ -568,7 +568,7 @@ static bool psp_frame(void *data, const void *frame, sceGuFinish(); - performance_counter_stop(&psp_frame_run); + performance_counter_stop_plus(video_info->is_perfcnt_enable, psp_frame_run); #ifdef HAVE_MENU menu_driver_frame(video_info); diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 222c74d976..58d0f6a837 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -349,8 +349,8 @@ static void sdl_refresh_input_size(sdl2_video_t *vid, bool menu, bool rgb32, sdl_tex_zero(target); - performance_counter_init(&sdl_create_texture, "sdl_create_texture"); - performance_counter_start(&sdl_create_texture); + performance_counter_init(sdl_create_texture, "sdl_create_texture"); + performance_counter_start(sdl_create_texture); if (menu) format = rgb32 ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_RGBA4444; @@ -364,7 +364,7 @@ static void sdl_refresh_input_size(sdl2_video_t *vid, bool menu, bool rgb32, target->tex = SDL_CreateTexture(vid->renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height); - performance_counter_stop(&sdl_create_texture); + performance_counter_stop(sdl_create_texture); if (!target->tex) { @@ -513,12 +513,12 @@ static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width, sdl_refresh_input_size(vid, false, vid->video.rgb32, width, height, pitch); - performance_counter_init(&sdl_copy_frame, "sdl_copy_frame"); - performance_counter_start(&sdl_copy_frame); + performance_counter_init(sdl_copy_frame, "sdl_copy_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, sdl_copy_frame); SDL_UpdateTexture(vid->frame.tex, NULL, frame, pitch); - performance_counter_stop(&sdl_copy_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, sdl_copy_frame); } SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE); @@ -632,8 +632,8 @@ static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle) sdl2_video_t *vid = (sdl2_video_t*)data; static struct retro_perf_counter sdl2_gfx_read_viewport = {0}; - performance_counter_init(&sdl2_gfx_read_viewport, "sdl2_gfx_read_viewport"); - performance_counter_start(&sdl2_gfx_read_viewport); + performance_counter_init(sdl2_gfx_read_viewport, "sdl2_gfx_read_viewport"); + performance_counter_start(sdl2_gfx_read_viewport); if (!is_idle) video_driver_cached_frame(); @@ -649,7 +649,7 @@ static bool sdl2_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle) memcpy(buffer, bgr24->pixels, bgr24->h * bgr24->pitch); - performance_counter_stop(&sdl2_gfx_read_viewport); + performance_counter_stop(sdl2_gfx_read_viewport); return true; } @@ -709,12 +709,12 @@ static void sdl2_poke_set_texture_frame(void *data, const void *frame, bool rgb3 sdl_refresh_input_size(vid, true, rgb32, width, height, width * (rgb32 ? 4 : 2)); - performance_counter_init(©_texture_frame, "copy_texture_frame"); - performance_counter_start(©_texture_frame); + performance_counter_init(copy_texture_frame, "copy_texture_frame"); + performance_counter_start(copy_texture_frame); SDL_UpdateTexture(vid->menu.tex, NULL, frame, vid->menu.pitch); - performance_counter_stop(©_texture_frame); + performance_counter_stop(copy_texture_frame); } } diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 805c15a4e5..7f1f0d829c 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -353,8 +353,8 @@ static bool sdl_gfx_frame(void *data, const void *frame, unsigned width, if (SDL_MUSTLOCK(vid->screen)) SDL_LockSurface(vid->screen); - performance_counter_init(&sdl_scale, "sdl_scale"); - performance_counter_start(&sdl_scale); + performance_counter_init(sdl_scale, "sdl_scale"); + performance_counter_start_plus(video_info->is_perfcnt_enable, sdl_scale); video_frame_scale( &vid->scaler, @@ -367,7 +367,7 @@ static bool sdl_gfx_frame(void *data, const void *frame, unsigned width, width, height, pitch); - performance_counter_stop(&sdl_scale); + performance_counter_stop_plus(video_info->is_perfcnt_enable, sdl_scale); #ifdef HAVE_MENU menu_driver_frame(video_info); diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 6608c5da88..d3802bd60c 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -390,8 +390,8 @@ static bool vg_frame(void *data, const void *frame, unsigned width = video_info->width; unsigned height = video_info->height; - performance_counter_init(&vg_fr, "vg_fr"); - performance_counter_start(&vg_fr); + performance_counter_init(vg_fr, "vg_fr"); + performance_counter_start_plus(video_info->is_perfcnt_enable, vg_fr); if ( frame_width != vg->mRenderWidth || frame_height != vg->mRenderHeight @@ -415,10 +415,10 @@ static bool vg_frame(void *data, const void *frame, vgClear(0, 0, width, height); vgSeti(VG_SCISSORING, VG_TRUE); - performance_counter_init(&vg_image, "vg_image"); - performance_counter_start(&vg_image); + performance_counter_init(vg_image, "vg_image"); + performance_counter_start_plus(video_info->is_perfcnt_enable, vg_image); vg_copy_frame(vg, frame, frame_width, frame_height, pitch); - performance_counter_stop(&vg_image); + performance_counter_stop_plus(video_info->is_perfcnt_enable, vg_image); #ifdef HAVE_MENU menu_driver_frame(video_info); @@ -433,7 +433,7 @@ static bool vg_frame(void *data, const void *frame, video_context_driver_update_window_title(video_info); - performance_counter_stop(&vg_fr); + performance_counter_stop_plus(video_info->is_perfcnt_enable, vg_fr); video_context_driver_swap_buffers(video_info); diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index bf11f453a7..b6f5b0d1ad 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1547,14 +1547,15 @@ static bool vulkan_frame(void *data, const void *frame, unsigned frame_index = vk->context->current_swapchain_index; - performance_counter_init(&frame_run, "frame_run"); - performance_counter_init(©_frame, "copy_frame"); - performance_counter_init(&swapbuffers, "swapbuffers"); - performance_counter_init(&queue_submit, "queue_submit"); - performance_counter_init(&begin_cmd, "begin_command"); - performance_counter_init(&build_cmd, "build_command"); - performance_counter_init(&end_cmd, "end_command"); - performance_counter_start(&frame_run); + performance_counter_init(frame_run, "frame_run"); + performance_counter_init(copy_frame, "copy_frame"); + performance_counter_init(swapbuffers, "swapbuffers"); + performance_counter_init(queue_submit, "queue_submit"); + performance_counter_init(begin_cmd, "begin_command"); + performance_counter_init(build_cmd, "build_command"); + performance_counter_init(end_cmd, "end_command"); + + performance_counter_start_plus(video_info->is_perfcnt_enable, frame_run); /* Bookkeeping on start of frame. */ chain = &vk->swapchain[frame_index]; @@ -1564,14 +1565,14 @@ static bool vulkan_frame(void *data, const void *frame, vulkan_buffer_chain_discard(&chain->vbo); vulkan_buffer_chain_discard(&chain->ubo); - performance_counter_start(&begin_cmd); + performance_counter_start_plus(video_info->is_perfcnt_enable, begin_cmd); /* 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); - performance_counter_stop(&begin_cmd); + performance_counter_stop_plus(video_info->is_perfcnt_enable, begin_cmd); memset(&vk->tracker, 0, sizeof(vk->tracker)); @@ -1596,7 +1597,7 @@ static bool vulkan_frame(void *data, const void *frame, } /* Upload texture */ - performance_counter_start(©_frame); + performance_counter_start_plus(video_info->is_perfcnt_enable, copy_frame); if (frame && !vk->hw.enable) { unsigned y; @@ -1647,13 +1648,13 @@ static bool vulkan_frame(void *data, const void *frame, vk->last_valid_index = frame_index; } - performance_counter_stop(©_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, copy_frame); /* 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); - performance_counter_start(&build_cmd); + performance_counter_start_plus(video_info->is_perfcnt_enable, build_cmd); /* Render offscreen filter chain passes. */ { /* Set the source texture in the filter chain */ @@ -1781,7 +1782,7 @@ static bool vulkan_frame(void *data, const void *frame, if (vk->overlay.enable) vulkan_render_overlay(vk, video_info); #endif - performance_counter_stop(&build_cmd); + performance_counter_stop_plus(video_info->is_perfcnt_enable, build_cmd); /* End the render pass. We're done rendering to backbuffer now. */ vkCmdEndRenderPass(vk->cmd); @@ -1850,9 +1851,9 @@ static bool vulkan_frame(void *data, const void *frame, vk->context->graphics_queue_index, vk->hw.src_queue_family); } - performance_counter_start(&end_cmd); + performance_counter_start_plus(video_info->is_perfcnt_enable, end_cmd); vkEndCommandBuffer(vk->cmd); - performance_counter_stop(&end_cmd); + performance_counter_stop_plus(video_info->is_perfcnt_enable, end_cmd); /* Submit command buffers to GPU. */ @@ -1894,9 +1895,9 @@ static bool vulkan_frame(void *data, const void *frame, } submit_info.pSignalSemaphores = submit_info.signalSemaphoreCount ? signal_semaphores : NULL; - performance_counter_stop(&frame_run); + performance_counter_stop_plus(video_info->is_perfcnt_enable, frame_run); - performance_counter_start(&queue_submit); + performance_counter_start_plus(video_info->is_perfcnt_enable, queue_submit); #ifdef HAVE_THREADS slock_lock(vk->context->queue_lock); @@ -1906,11 +1907,11 @@ static bool vulkan_frame(void *data, const void *frame, #ifdef HAVE_THREADS slock_unlock(vk->context->queue_lock); #endif - performance_counter_stop(&queue_submit); + performance_counter_stop_plus(video_info->is_perfcnt_enable, queue_submit); - performance_counter_start(&swapbuffers); + performance_counter_start_plus(video_info->is_perfcnt_enable, swapbuffers); video_context_driver_swap_buffers(video_info); - performance_counter_stop(&swapbuffers); + performance_counter_stop_plus(video_info->is_perfcnt_enable, swapbuffers); if (!vk->context->swap_interval_emulation_lock) video_context_driver_update_window_title(video_info); @@ -2279,8 +2280,8 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle) if (staging->memory == VK_NULL_HANDLE) return false; - performance_counter_init(&stream_readback, "stream_readback"); - performance_counter_start(&stream_readback); + performance_counter_init(stream_readback, "stream_readback"); + performance_counter_start(stream_readback); buffer += 3 * (vk->vp.height - 1) * vk->vp.width; vkMapMemory(vk->context->device, staging->memory, @@ -2294,7 +2295,7 @@ static bool vulkan_read_viewport(void *data, uint8_t *buffer, bool is_idle) vkUnmapMemory(vk->context->device, staging->memory); - performance_counter_stop(&stream_readback); + performance_counter_stop(stream_readback); } else { diff --git a/gfx/drivers/wiiu_gfx.c b/gfx/drivers/wiiu_gfx.c index fe55563c1f..a07ad7c84a 100644 --- a/gfx/drivers/wiiu_gfx.c +++ b/gfx/drivers/wiiu_gfx.c @@ -617,8 +617,8 @@ static bool wiiu_gfx_frame(void* data, const void* frame, fflush(stdout); static struct retro_perf_counter gfx_frame_perf = {0}; - performance_counter_init(&gfx_frame_perf, "gfx_frame"); - performance_counter_start(&gfx_frame_perf); + performance_counter_init(gfx_frame_perf, "gfx_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, gfx_frame_perf); if (wiiu->should_resize) wiiu_gfx_update_viewport(wiiu); @@ -702,7 +702,7 @@ static bool wiiu_gfx_frame(void* data, const void* frame, GX2SwapScanBuffers(); GX2Flush(); - performance_counter_stop(&gfx_frame_perf); + performance_counter_stop_plus(video_info->is_perfcnt_enable, gfx_frame_perf); return true; } diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 5e9f0eaf09..88d69eb559 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -962,10 +962,11 @@ void video_driver_set_filtering(unsigned index, bool smooth) void video_driver_cached_frame_set(const void *data, unsigned width, unsigned height, size_t pitch) { - video_driver_set_cached_frame_ptr(data); - frame_cache_width = width; - frame_cache_height = height; - frame_cache_pitch = pitch; + if (data) + frame_cache_data = data; + frame_cache_width = width; + frame_cache_height = height; + frame_cache_pitch = pitch; } void video_driver_cached_frame_get(const void **data, unsigned *width, @@ -1094,18 +1095,18 @@ static bool video_driver_frame_filter( { static struct retro_perf_counter softfilter_process = {0}; - performance_counter_init(&softfilter_process, "softfilter_process"); + performance_counter_init(softfilter_process, "softfilter_process"); rarch_softfilter_get_output_size(video_driver_state_filter, output_width, output_height, width, height); *output_pitch = (*output_width) * video_driver_state_out_bpp; - performance_counter_start(&softfilter_process); + performance_counter_start_plus(video_info->is_perfcnt_enable, softfilter_process); rarch_softfilter_process(video_driver_state_filter, video_driver_state_buffer, *output_pitch, data, width, height, pitch); - performance_counter_stop(&softfilter_process); + performance_counter_stop_plus(video_info->is_perfcnt_enable, softfilter_process); if (video_info->post_filter_record && recording_data) recording_dump_frame(video_driver_state_buffer, @@ -2018,89 +2019,6 @@ unsigned video_pixel_get_alignment(unsigned pitch) return 8; } -/** - * video_monitor_get_fps: - * - * Get the amount of frames per seconds. - **/ -static void video_monitor_get_fps(video_frame_info_t *video_info) -{ - static retro_time_t curr_time; - static retro_time_t fps_time; - static float last_fps; - unsigned write_index = 0; - retro_time_t new_time = cpu_features_get_time_usec(); - - if (!video_info->frame_count) - { - curr_time = fps_time = new_time; - strlcpy(video_driver_window_title, - video_driver_title_buf, - sizeof(video_driver_window_title)); - - if (video_info->fps_show) - strlcpy(video_info->fps_text, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), - sizeof(video_info->fps_text)); - - video_driver_window_title_update = true; - return; - } - - write_index = - video_driver_frame_time_count++ & - (MEASURE_FRAME_TIME_SAMPLES_COUNT - 1); - video_driver_frame_time_samples[write_index] = new_time - fps_time; - fps_time = new_time; - - if ((video_info->frame_count % FPS_UPDATE_INTERVAL) == 0) - { - char frames_text[64]; - - fill_pathname_noext(video_driver_window_title, - video_driver_title_buf, - " || ", - sizeof(video_driver_window_title)); - - if (video_info->fps_show) - { - last_fps = TIME_TO_FPS(curr_time, new_time, FPS_UPDATE_INTERVAL); - snprintf(video_info->fps_text, - sizeof(video_info->fps_text), - " FPS: %6.1f || ", last_fps); - strlcat(video_driver_window_title, - video_info->fps_text, - sizeof(video_driver_window_title)); - } - - curr_time = new_time; - - strlcat(video_driver_window_title, - "Frames: ", - sizeof(video_driver_window_title)); - - snprintf(frames_text, - sizeof(frames_text), - STRING_REP_UINT64, - (unsigned long long)video_info->frame_count); - - strlcat(video_driver_window_title, - frames_text, - sizeof(video_driver_window_title)); - - video_driver_window_title_update = true; - } - - if (video_info->fps_show) - snprintf( - video_info->fps_text, - sizeof(video_info->fps_text), - "FPS: %6.1f || %s: " STRING_REP_UINT64, - last_fps, - msg_hash_to_str(MSG_FRAMES), - (unsigned long long)video_info->frame_count); -} - /** * video_driver_frame: * @data : pointer to data of the video frame. @@ -2115,31 +2033,39 @@ void video_driver_frame(const void *data, unsigned width, { static char video_driver_msg[256]; video_frame_info_t video_info; - static struct retro_perf_counter video_frame_conv = {0}; + static retro_time_t curr_time; + static retro_time_t fps_time; + static float last_fps; unsigned output_width = 0; unsigned output_height = 0; unsigned output_pitch = 0; const char *msg = NULL; + retro_time_t new_time = + cpu_features_get_time_usec(); if (!video_driver_active) return; - performance_counter_init(&video_frame_conv, "video_frame_conv"); - performance_counter_start(&video_frame_conv); - if (video_driver_scaler_ptr && data && (video_driver_pix_fmt == RETRO_PIXEL_FORMAT_0RGB1555) && - (data != RETRO_HW_FRAME_BUFFER_VALID) && - video_pixel_frame_scale( - video_driver_scaler_ptr->scaler, - video_driver_scaler_ptr->scaler_out, - data, width, height, pitch)) + (data != RETRO_HW_FRAME_BUFFER_VALID)) { - data = video_driver_scaler_ptr->scaler_out; - pitch = video_driver_scaler_ptr->scaler->out_stride; + static struct retro_perf_counter video_frame_conv = {0}; + + performance_counter_init(video_frame_conv, "video_frame_conv"); + performance_counter_start(video_frame_conv); + + if (video_pixel_frame_scale( + video_driver_scaler_ptr->scaler, + video_driver_scaler_ptr->scaler_out, + data, width, height, pitch)) + { + data = video_driver_scaler_ptr->scaler_out; + pitch = video_driver_scaler_ptr->scaler->out_stride; + } + performance_counter_stop(video_frame_conv); } - performance_counter_stop(&video_frame_conv); if (data) frame_cache_data = data; @@ -2154,7 +2080,78 @@ void video_driver_frame(const void *data, unsigned width, video_driver_frame_count++; video_driver_threaded_unlock(); - video_monitor_get_fps(&video_info); + /* Get the amount of frames per seconds. */ + if (video_info.frame_count) + { + unsigned write_index = + video_driver_frame_time_count++ & + (MEASURE_FRAME_TIME_SAMPLES_COUNT - 1); + video_driver_frame_time_samples[write_index] = new_time - fps_time; + fps_time = new_time; + + if ((video_info.frame_count % FPS_UPDATE_INTERVAL) == 0) + { + char frames_text[64]; + + fill_pathname_noext(video_driver_window_title, + video_driver_title_buf, + " || ", + sizeof(video_driver_window_title)); + + if (video_info.fps_show) + { + last_fps = TIME_TO_FPS(curr_time, new_time, FPS_UPDATE_INTERVAL); + snprintf(video_info.fps_text, + sizeof(video_info.fps_text), + " FPS: %6.1f || ", last_fps); + strlcat(video_driver_window_title, + video_info.fps_text, + sizeof(video_driver_window_title)); + } + + curr_time = new_time; + + strlcat(video_driver_window_title, + "Frames: ", + sizeof(video_driver_window_title)); + + snprintf(frames_text, + sizeof(frames_text), + STRING_REP_UINT64, + (unsigned long long)video_info.frame_count); + + strlcat(video_driver_window_title, + frames_text, + sizeof(video_driver_window_title)); + + video_driver_window_title_update = true; + } + + if (video_info.fps_show) + snprintf( + video_info.fps_text, + sizeof(video_info.fps_text), + "FPS: %6.1f || %s: " STRING_REP_UINT64, + last_fps, + msg_hash_to_str(MSG_FRAMES), + (unsigned long long)video_info.frame_count); + } + else + { + + curr_time = fps_time = new_time; + + strlcpy(video_driver_window_title, + video_driver_title_buf, + sizeof(video_driver_window_title)); + + if (video_info.fps_show) + strlcpy(video_info.fps_text, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), + sizeof(video_info.fps_text)); + + video_driver_window_title_update = true; + } /* Slightly messy code, * but we really need to do processing before blocking on VSync @@ -2253,6 +2250,7 @@ bool video_driver_texture_unload(uintptr_t *id) void video_driver_build_info(video_frame_info_t *video_info) { + bool is_perfcnt_enable = false; bool is_paused = false; bool is_idle = false; bool is_slowmotion = false; @@ -2321,8 +2319,9 @@ void video_driver_build_info(video_frame_info_t *video_info) video_info->menu_wallpaper_opacity = 0.0f; #endif - runloop_get_status(&is_paused, &is_idle, &is_slowmotion); + runloop_get_status(&is_paused, &is_idle, &is_slowmotion, &is_perfcnt_enable); + video_info->is_perfcnt_enable = is_perfcnt_enable; video_info->runloop_is_paused = is_paused; video_info->runloop_is_idle = is_idle; video_info->runloop_is_slowmotion = is_slowmotion; diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 8976558040..7c68056506 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -131,6 +131,7 @@ typedef struct video_frame_info bool runloop_is_slowmotion; bool runloop_is_idle; bool runloop_is_paused; + bool is_perfcnt_enable; bool menu_is_alive; } video_frame_info_t; diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index f24134ccaf..f7d390f9cc 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -729,8 +729,8 @@ static bool video_thread_frame(void *data, const void *frame_, return false; } - performance_counter_init(&thr_frame, "thr_frame"); - performance_counter_start(&thr_frame); + performance_counter_init(thr_frame, "thr_frame"); + performance_counter_start_plus(video_info->is_perfcnt_enable, thr_frame); copy_stride = width * (thr->info.rgb32 ? sizeof(uint32_t) : sizeof(uint16_t)); @@ -799,7 +799,7 @@ static bool video_thread_frame(void *data, const void *frame_, slock_unlock(thr->lock); - performance_counter_stop(&thr_frame); + performance_counter_stop_plus(video_info->is_perfcnt_enable, thr_frame); thr->last_time = cpu_features_get_time_usec(); return true; diff --git a/managers/state_manager.c b/managers/state_manager.c index 731f9f83ee..7b09a94a68 100644 --- a/managers/state_manager.c +++ b/managers/state_manager.c @@ -563,8 +563,8 @@ recheckcapacity:; goto recheckcapacity; } - performance_counter_init(&gen_deltas, "gen_deltas"); - performance_counter_start(&gen_deltas); + performance_counter_init(gen_deltas, "gen_deltas"); + performance_counter_start(gen_deltas); oldb = state->thisblock; newb = state->nextblock; @@ -584,7 +584,7 @@ recheckcapacity:; write_size_t(state->head, compressed-state->data); state->head = compressed; - performance_counter_stop(&gen_deltas); + performance_counter_stop(gen_deltas); } else state->thisblock_valid = true; @@ -765,15 +765,15 @@ bool state_manager_check_rewind(bool pressed, state_manager_push_where(rewind_state.state, &state); - performance_counter_init(&rewind_serialize, "rewind_serialize"); - performance_counter_start(&rewind_serialize); + performance_counter_init(rewind_serialize, "rewind_serialize"); + performance_counter_start(rewind_serialize); serial_info.data = state; serial_info.size = rewind_state.size; core_serialize(&serial_info); - performance_counter_stop(&rewind_serialize); + performance_counter_stop(rewind_serialize); state_manager_push_do(rewind_state.state); } diff --git a/performance_counters.c b/performance_counters.c index 805dd73eb9..48eb3b67bc 100644 --- a/performance_counters.c +++ b/performance_counters.c @@ -24,7 +24,6 @@ #endif #include -#include #include "performance_counters.h" @@ -121,33 +120,6 @@ void retro_perf_log(void) log_counters(perf_counters_libretro, perf_ptr_libretro); } -int performance_counter_init(struct retro_perf_counter *perf, const char *name) -{ - perf->ident = name; - - if (!perf->registered) - rarch_perf_register(perf); - - return 0; -} - -void performance_counter_start(struct retro_perf_counter *perf) -{ - if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf) - return; - - perf->call_cnt++; - perf->start = cpu_features_get_perf_counter(); -} - -void performance_counter_stop(struct retro_perf_counter *perf) -{ - if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf) - return; - - perf->total += cpu_features_get_perf_counter() - perf->start; -} - void rarch_timer_tick(rarch_timer_t *timer) { if (!timer) diff --git a/performance_counters.h b/performance_counters.h index 4ceccb93fb..958c1474f6 100644 --- a/performance_counters.h +++ b/performance_counters.h @@ -22,6 +22,9 @@ #include #include +#include + +#include "runloop.h" RETRO_BEGIN_DECLS @@ -54,7 +57,23 @@ void retro_perf_log(void); void rarch_perf_log(void); -int performance_counter_init(struct retro_perf_counter *perf, const char *name); +void rarch_perf_register(struct retro_perf_counter *perf); + +#define performance_counter_init(perf, name) \ + perf.ident = name; \ + if (!perf.registered) \ + rarch_perf_register(&perf) + +#define performance_counter_start_internal(is_perfcnt_enable, perf) \ + if ((is_perfcnt_enable)) \ + { \ + perf.call_cnt++; \ + perf.start = cpu_features_get_perf_counter(); \ + } + +#define performance_counter_stop_internal(is_perfcnt_enable, perf) \ + if ((is_perfcnt_enable)) \ + perf.total += cpu_features_get_perf_counter() - perf.start /** * performance_counter_start: @@ -62,7 +81,8 @@ int performance_counter_init(struct retro_perf_counter *perf, const char *name); * * Start performance counter. **/ -void performance_counter_start(struct retro_perf_counter *perf); +#define performance_counter_start(perf) performance_counter_start_internal(runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL), perf) +#define performance_counter_start_plus(is_perfcnt_enable, perf) performance_counter_start_internal(is_perfcnt_enable, perf) /** * performance_counter_stop: @@ -70,7 +90,8 @@ void performance_counter_start(struct retro_perf_counter *perf); * * Stop performance counter. **/ -void performance_counter_stop(struct retro_perf_counter *perf); +#define performance_counter_stop(perf) performance_counter_stop_internal(runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL), perf) +#define performance_counter_stop_plus(is_perfcnt_enable, perf) performance_counter_stop_internal(is_perfcnt_enable, perf) void rarch_timer_tick(rarch_timer_t *timer); diff --git a/runloop.c b/runloop.c index b05c863c81..cfa6ba3283 100644 --- a/runloop.c +++ b/runloop.c @@ -205,11 +205,12 @@ static bool rarch_game_specific_options(char **output) } void runloop_get_status(bool *is_paused, bool *is_idle, - bool *is_slowmotion) + bool *is_slowmotion, bool *is_perfcnt_enable) { - *is_paused = runloop_paused; - *is_idle = runloop_idle; - *is_slowmotion = runloop_slowmotion; + *is_paused = runloop_paused; + *is_idle = runloop_idle; + *is_slowmotion = runloop_slowmotion; + *is_perfcnt_enable = runloop_perfcnt_enable; } bool runloop_msg_queue_pull(const char **ret) diff --git a/runloop.h b/runloop.h index 107ad14a1c..a81ac54ecf 100644 --- a/runloop.h +++ b/runloop.h @@ -204,7 +204,8 @@ void runloop_msg_queue_push(const char *msg, unsigned prio, bool runloop_msg_queue_pull(const char **ret); -void runloop_get_status(bool *is_paused, bool *is_idle, bool *is_slowmotion); +void runloop_get_status(bool *is_paused, bool *is_idle, bool *is_slowmotion, + bool *is_perfcnt_enable); bool runloop_ctl(enum runloop_ctl_state state, void *data); diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index 571215dcf5..6a3e465933 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -389,12 +389,13 @@ static bool take_screenshot_choice(const char *name_base, bool savestate, bool take_screenshot(const char *name_base, bool silence) { - bool is_paused = false; - bool is_idle = false; - bool is_slowmotion = false; - bool ret = false; + bool is_paused = false; + bool is_idle = false; + bool is_slowmotion = false; + bool is_perfcnt_enable = false; + bool ret = false; - runloop_get_status(&is_paused, &is_idle, &is_slowmotion); + runloop_get_status(&is_paused, &is_idle, &is_slowmotion, &is_perfcnt_enable); ret = take_screenshot_choice(name_base, silence, is_paused, is_idle);