score
Home
Classes
Namespaces
Files
Loading...
Searching...
No Matches
GpuTiming.hpp
1
#pragma once
2
#include <score_plugin_gfx_export.h>
3
4
#include <QtGui/private/qrhi_p.h>
5
6
#include <array>
7
#include <cstdint>
8
#include <mutex>
9
#include <string>
10
#include <vector>
11
12
namespace
score::gfx
13
{
37
class
SCORE_PLUGIN_GFX_EXPORT
GpuTimings
38
{
39
public
:
40
static
constexpr
int
kHistorySize = 64;
41
42
struct
Entry
43
{
44
std::string name;
45
double
last_ms{0.0};
46
double
mean_ms{0.0};
47
double
max_ms{0.0};
48
std::array<double, kHistorySize> history{};
49
int
history_index{0};
50
int
sample_count{0};
// capped at kHistorySize; used to avoid cold-start bias
51
int
frames_since_observed{0};
52
};
53
54
GpuTimings
() =
default
;
55
GpuTimings
(
const
GpuTimings
&) =
delete
;
56
GpuTimings
& operator=(
const
GpuTimings
&) =
delete
;
57
65
void
record(std::string_view name,
double
ms)
noexcept
;
66
71
void
tickFrame() noexcept;
72
79
std
::vector<
Entry
> snapshot() const;
80
84
void
reset() noexcept;
85
86
private:
87
static constexpr
int
kStaleThreshold = 120;
// drop entries after 2s at 60fps
88
89
mutable
std
::mutex m_mutex;
90
std
::vector<
Entry
> m_entries;
91
};
92
108
class SCORE_PLUGIN_GFX_EXPORT
ScopedGpuTimer
109
{
110
public
:
111
ScopedGpuTimer
(
112
QRhiCommandBuffer& cb,
GpuTimings
& timings, std::string_view name);
113
~ScopedGpuTimer
();
114
115
ScopedGpuTimer
(
const
ScopedGpuTimer
&) =
delete
;
116
ScopedGpuTimer
& operator=(
const
ScopedGpuTimer
&) =
delete
;
117
118
private
:
119
QRhiCommandBuffer& m_cb;
120
GpuTimings
& m_timings;
121
std::string m_name;
122
};
123
124
}
// namespace score::gfx
score::gfx::GpuTimings
Named-bucket GPU timing collector.
Definition
GpuTiming.hpp:38
score::gfx::ScopedGpuTimer
RAII helper that brackets a named pass region for GPU frame-debug.
Definition
GpuTiming.hpp:109
score::gfx
Graphics rendering pipeline for ossia score.
Definition
Filter/PreviewWidget.hpp:11
std
STL namespace.
score::gfx::GpuTimings::Entry
Definition
GpuTiming.hpp:43