Modules/Graphics/public/GpuTimer.hpp
Шурупов Илья Викторович 37a650b1e8 Add frame profiling, GPU timers and input recording to the libraries
Profiler (Modules) collects per-frame wall and thread CPU time, named
inclusive sections, counters and GPU durations. It is off by default, so
a disabled scope costs one branch. Application, WidgetApplication,
VulkanContext and Canvas mark the frame phases (process, dispatch,
advance, draw, paint, UI flush, acquire, submit, present).

GpuTimer wraps Vulkan timestamp queries in a small ring that is read
without stalling; the window frame and any RenderBuffer that asks for it
report GPU time into the profiler.

InputRecording stores raw window input with exact timing, pen pressure
and tilt as a line-based text file, and InputRecorder captures it
through a new raw tap in the InputCoalescer that sees every platform
event before coalescing.
2026-10-15 20:03:20 +03:00

42 lines
902 B
C++

#pragma once
#include "Profiler.hpp"
#include <vulkan/vulkan.h>
#include <cstdint>
#include <vector>
namespace tp {
class GpuTimer {
public:
static constexpr uint32_t kSlots = 8;
GpuTimer(VkDevice device, VkPhysicalDevice physicalDevice, uint32_t queueFamily, const char* name);
~GpuTimer();
GpuTimer(const GpuTimer&) = delete;
GpuTimer& operator=(const GpuTimer&) = delete;
[[nodiscard]] bool isSupported() const { return mPool != VK_NULL_HANDLE; }
void begin(VkCommandBuffer commandBuffer);
void end(VkCommandBuffer commandBuffer);
void collect();
[[nodiscard]] double lastMs() const { return mLastMs; }
private:
VkDevice mDevice;
VkQueryPool mPool = VK_NULL_HANDLE;
double mTickNs = 1;
uint64_t mValidMask = ~0ull;
ProfileId mSection;
std::vector<bool> mPending;
uint32_t mNextSlot = 0;
uint32_t mOpenSlot = UINT32_MAX;
double mLastMs = 0;
};
}