Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_render_time.hpp
Go to the documentation of this file.
1#pragma once
2
3#if defined(PULP_GPU_RUNTIME)
4// This build's device layer is gpu-runtime's (tools/cmake/PulpGpuRuntime.cmake):
5// these are its types and functions under their Pulp names, so a Pulp object
6// and a gpu-runtime object are one and the same.
7#include <gpu_runtime/gpu_render_time.hpp>
8
9namespace pulp::render {
10using gpu_runtime::gpu_render_ns_to_ms;
11using gpu_runtime::gpu_surface_disabled_toggles;
12using gpu_runtime::GpuFramesInFlight;
13using gpu_runtime::GpuRenderTimeTracker;
14using gpu_runtime::kDawnTimestampQuantizationToggle;
15using gpu_runtime::kGpuRenderNanosecondsPerMillisecond;
16} // namespace pulp::render
17#else // !PULP_GPU_RUNTIME
18
19#include <atomic>
20#include <cstdint>
21#include <optional>
22#include <vector>
23
24namespace pulp::render {
25
46
51inline constexpr double kGpuRenderNanosecondsPerMillisecond = 1.0e6;
52
70inline constexpr const char* kDawnTimestampQuantizationToggle = "timestamp_quantization";
71
76[[nodiscard]] inline std::vector<const char*>
77gpu_surface_disabled_toggles(bool timestamp_query_requested) {
78 std::vector<const char*> disabled;
79 if (timestamp_query_requested) {
80 disabled.push_back(kDawnTimestampQuantizationToggle);
81 }
82 return disabled;
83}
84
92[[nodiscard]] inline std::optional<double>
93gpu_render_ns_to_ms(std::uint64_t elapsed_ns, bool callback_ok) {
94 if (!callback_ok || elapsed_ns == 0) {
95 return std::nullopt;
96 }
97 return static_cast<double>(elapsed_ns) / kGpuRenderNanosecondsPerMillisecond;
98}
99
109public:
113 void store(std::uint64_t elapsed_ns, bool callback_ok) {
114 if (auto ms = gpu_render_ns_to_ms(elapsed_ns, callback_ok)) {
115 last_ms_.store(*ms, std::memory_order_relaxed);
116 have_sample_.store(true, std::memory_order_relaxed);
117 }
118 }
119
122 [[nodiscard]] bool have_sample() const {
123 return have_sample_.load(std::memory_order_relaxed);
124 }
125
128 [[nodiscard]] double last_ms() const {
129 return last_ms_.load(std::memory_order_relaxed);
130 }
131
132private:
133 std::atomic<double> last_ms_{0.0};
134 std::atomic<bool> have_sample_{false};
135};
136
146public:
147 void on_submitted() { count_.fetch_add(1, std::memory_order_relaxed); }
148 void on_finished() {
149 int current = count_.load(std::memory_order_relaxed);
150 while (current > 0 &&
151 !count_.compare_exchange_weak(current, current - 1,
152 std::memory_order_relaxed)) {}
153 }
154 [[nodiscard]] int count() const { return count_.load(std::memory_order_relaxed); }
155
156private:
157 std::atomic<int> count_{0};
158};
159
160} // namespace pulp::render
161
162#endif // PULP_GPU_RUNTIME
Frames whose GPU work has been submitted but has not finished executing.
Definition gpu_render_time.hpp:145
void on_finished()
Definition gpu_render_time.hpp:148
int count() const
Definition gpu_render_time.hpp:154
void on_submitted()
Definition gpu_render_time.hpp:147
Thread-safe holder for the latest GPU render-time sample.
Definition gpu_render_time.hpp:108
bool have_sample() const
True once at least one valid sample has landed.
Definition gpu_render_time.hpp:122
double last_ms() const
The most recent valid GPU render duration in milliseconds (0 until the first sample lands).
Definition gpu_render_time.hpp:128
void store(std::uint64_t elapsed_ns, bool callback_ok)
Store a sample from the finished-with-stats callback.
Definition gpu_render_time.hpp:113
Definition gpu_fwd.hpp:31
constexpr const char * kDawnTimestampQuantizationToggle
Dawn's timestamp_quantization toggle, which defaults to ON in native Dawn (not only in Chrome) and AN...
Definition gpu_render_time.hpp:70
std::optional< double > gpu_render_ns_to_ms(std::uint64_t elapsed_ns, bool callback_ok)
Convert a Graphite GpuStats::elapsedTime sample into a millisecond duration.
Definition gpu_render_time.hpp:93
std::vector< const char * > gpu_surface_disabled_toggles(bool timestamp_query_requested)
Dawn toggles that must be DISABLED for the requested device features.
Definition gpu_render_time.hpp:77
constexpr double kGpuRenderNanosecondsPerMillisecond
Whole-recording GPU render time.
Definition gpu_render_time.hpp:51