-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathProfiler.h
87 lines (71 loc) · 2.9 KB
/
Profiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
# Copyright (c) 2021-2023, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
**************************************************************************/
#pragma once
#include <nvrhi/nvrhi.h>
#include <array>
#include <memory>
#include "ProfilerSections.h"
class RenderTargets;
namespace donut::app
{
class DeviceManager;
}
class Profiler
{
public:
explicit Profiler(donut::app::DeviceManager& deviceManager);
bool IsEnabled() const;
void EnableProfiler(bool enable);
void EnableAccumulation(bool enable);
void ResetAccumulation();
void ResolvePreviousFrame();
void BeginFrame(nvrhi::ICommandList* commandList);
void EndFrame(nvrhi::ICommandList* commandList);
void BeginSection(nvrhi::ICommandList* commandList, ProfilerSection::Enum section);
void EndSection(nvrhi::ICommandList* commandList, ProfilerSection::Enum section);
void SetRenderTargets(const std::shared_ptr<RenderTargets>& renderTargets);
double GetTimer(ProfilerSection::Enum section);
double GetRayCount(ProfilerSection::Enum section);
double GetHitCount(ProfilerSection::Enum section);
int GetMaterialReadback();
void BuildUI(bool enableRayCounts);
std::string GetAsText();
[[nodiscard]] nvrhi::IBuffer* GetRayCountBuffer() const;
private:
bool m_enabled = true;
bool m_isAccumulating = false;
uint32_t m_accumulatedFrames = 0;
uint32_t m_activeBank = 0;
std::array<nvrhi::TimerQueryHandle, ProfilerSection::Count * 2> m_timerQueries;
std::array<double, ProfilerSection::Count> m_timerValues{};
std::array<size_t, ProfilerSection::Count> m_rayCounts{};
std::array<size_t, ProfilerSection::Count> m_hitCounts{};
std::array<bool, ProfilerSection::Count * 2> m_timersUsed{};
donut::app::DeviceManager& m_deviceManager;
nvrhi::DeviceHandle m_device;
nvrhi::BufferHandle m_rayCountBuffer;
std::array<nvrhi::BufferHandle, 2> m_rayCountReadback;
std::weak_ptr<RenderTargets> m_renderTargets;
};
class ProfilerScope
{
public:
ProfilerScope(Profiler& profiler, nvrhi::ICommandList* commandList, ProfilerSection::Enum section);
~ProfilerScope();
// Non-copyable and non-movable
ProfilerScope(const ProfilerScope&) = delete;
ProfilerScope(const ProfilerScope&&) = delete;
ProfilerScope& operator=(const ProfilerScope&) = delete;
ProfilerScope& operator=(const ProfilerScope&&) = delete;
private:
Profiler& m_Profiler;
nvrhi::ICommandList* m_CommandList;
ProfilerSection::Enum m_Section;
};