Files
LibretroAdmin 2495414cab Stutter stats: what generating and emitting shaders costs
The stats build counts the cycles generating GX shader text and in
rslc, and the words rslc emits. The gate holds the words against the
baseline and the parent, and reports each state's cycles in text, rslc,
the workers and the driver.
2026-11-09 03:05:26 +01:00

69 lines
1.7 KiB
C

/* Copyright 2026 Dolphin Emulator Project
* SPDX-License-Identifier: GPL-2.0-or-later */
#ifdef HAVE_STUTTER_STATS
#include <retro_atomic.h>
#include "VideoCommon/StutterStats.h"
#if defined(_MSC_VER)
#define STUTTER_THREAD_LOCAL __declspec(thread)
#else
#define STUTTER_THREAD_LOCAL __thread
#endif
static retro_atomic_size_t s_counts[STUTTER_STAT_COUNT];
static retro_atomic_size_t s_cycles[STUTTER_STAT_COUNT];
/* how deep this thread is in building for a draw */
static STUTTER_THREAD_LOCAL unsigned s_draw_depth;
void stutter_stat_add(enum stutter_stat stat, retro_perf_tick_t cycles)
{
retro_atomic_fetch_add_size(&s_counts[stat], 1);
if (cycles)
retro_atomic_fetch_add_size(&s_cycles[stat], (size_t)cycles);
}
void stutter_draw_enter(void)
{
s_draw_depth++;
}
void stutter_draw_leave(void)
{
s_draw_depth--;
}
void stutter_driver_pipeline(retro_perf_tick_t cycles)
{
stutter_stat_add(STUTTER_DRIVER_PIPELINE, cycles);
if (s_draw_depth)
stutter_stat_add(STUTTER_DRAW_DRIVER_PIPELINE, cycles);
}
void stutter_shader_emit(retro_perf_tick_t cycles, unsigned long words)
{
stutter_stat_add(STUTTER_SHADER_EMIT, cycles);
retro_atomic_fetch_add_size(&s_counts[STUTTER_SHADER_WORDS], (size_t)words);
}
RETRO_API unsigned parallel_gx1_stutter_stats(unsigned long long *counts,
unsigned long long *cycles, unsigned n)
{
unsigned i;
for (i = 0; i < n && i < STUTTER_STAT_COUNT; i++)
{
counts[i] = retro_atomic_load_acquire_size(&s_counts[i]);
cycles[i] = retro_atomic_load_acquire_size(&s_cycles[i]);
}
return STUTTER_STAT_COUNT;
}
#else
/* a translation unit is never empty */
typedef int stutter_stats_none;
#endif