2021-12-12 11:34:05 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "VulkanLoader.h"
|
|
|
|
|
|
|
|
|
|
// Simple scoped based profiler, initially meant for instant one-time tasks like texture uploads
|
|
|
|
|
// etc. Supports recursive scopes. Scopes are not yet tracked separately for each command buffer.
|
|
|
|
|
// For the pass profiler in VulkanQueueRunner, a purpose-built separate profiler that can take only
|
|
|
|
|
// one measurement between each pass makes more sense.
|
|
|
|
|
//
|
|
|
|
|
// Put the whole thing in a FrameData to allow for overlap.
|
|
|
|
|
|
|
|
|
|
struct ProfilerScope {
|
2022-12-01 11:39:20 +01:00
|
|
|
char name[52]; // to make a struct size of 64, just because
|
2021-12-12 19:44:45 +01:00
|
|
|
int startQueryId;
|
|
|
|
|
int endQueryId;
|
2021-12-12 11:34:05 +01:00
|
|
|
int level;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class VulkanContext;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VulkanProfiler {
|
|
|
|
|
public:
|
|
|
|
|
void Init(VulkanContext *vulkan);
|
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
|
|
void BeginFrame(VulkanContext *vulkan, VkCommandBuffer firstCommandBuffer);
|
|
|
|
|
|
2021-12-19 19:39:15 +01:00
|
|
|
void Begin(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage, const char *fmt, ...)
|
|
|
|
|
#ifdef __GNUC__
|
2021-12-19 14:56:50 -08:00
|
|
|
__attribute__((format(printf, 4, 5)))
|
2021-12-19 19:39:15 +01:00
|
|
|
#endif
|
|
|
|
|
;
|
2021-12-12 11:56:29 +01:00
|
|
|
void End(VkCommandBuffer cmdBuf, VkPipelineStageFlagBits stage);
|
2021-12-12 11:34:05 +01:00
|
|
|
|
2021-12-19 22:49:42 +01:00
|
|
|
void SetEnabledPtr(bool *enabledPtr) {
|
|
|
|
|
enabledPtr_ = enabledPtr;
|
|
|
|
|
}
|
2021-12-12 11:34:05 +01:00
|
|
|
private:
|
|
|
|
|
VulkanContext *vulkan_;
|
|
|
|
|
|
|
|
|
|
VkQueryPool queryPool_ = VK_NULL_HANDLE;
|
|
|
|
|
std::vector<ProfilerScope> scopes_;
|
|
|
|
|
int numQueries_ = 0;
|
|
|
|
|
bool firstFrame_ = true;
|
2021-12-19 22:49:42 +01:00
|
|
|
bool *enabledPtr_ = nullptr;
|
2022-12-15 10:45:45 +01:00
|
|
|
int validBits_ = 0;
|
2021-12-12 11:34:05 +01:00
|
|
|
|
|
|
|
|
std::vector<size_t> scopeStack_;
|
|
|
|
|
|
|
|
|
|
const int MAX_QUERY_COUNT = 1024;
|
|
|
|
|
};
|