SpiecsEngine
 
Loading...
Searching...
No Matches
NsightPerfGPUProfilerReportGenerator.cpp
Go to the documentation of this file.
1/**
2* @file NsightPerfGPUProfilerReportGenerator.h
3* @brief The NsightPerfGPUProfilerReportGenerator Class Definitions.
4* @author Spices
5*/
6
7#include "Pchheader.h"
10
11namespace Spices {
12
14
17 , m_CapturedThisFrame(false)
18 {
20
21 /**
22 * @brief Initiate collection with the following call.
23 */
24 m_NvPerf.outputOptions.directoryName = SPICES_GPUPROFILEREPORT_PATH;
25 m_NvPerf.outputOptions.writeCounterConfigImage = true;
26 m_NvPerf.outputOptions.writeCounterDataImage = true;
27 m_NvPerf.outputOptions.appendDateTimeToDirName = nv::perf::AppendDateTime::yes;
28 m_NvPerf.outputOptions.enableCsvReport = false;
29
30 /**
31 * @brief Initialize the report generator any time after VkDevice initialization. This step determines the list
32 * of counters. Specify additionalMetrics before calling InitializeReportGenerator. This is also a
33 * good time to decide whether a frame-level range is desirable.
34 */
35 m_NvPerf.additionalMetrics = {
36 "zrop__cycles_elapsed",
37 "lts__t_sector_hit_rate",
38 "crop__write_throughput"
39 };
40 NSPERF_CHECK(m_NvPerf.InitializeReportGenerator(state.m_Instance, state.m_PhysicalDevice, state.m_Device))
41 m_NvPerf.SetFrameLevelRangeName("Frame");
42 m_NvPerf.SetNumNestingLevels(10);
43 m_NvPerf.SetMaxNumRanges(100);
44 m_NvPerf.SetOpenReportDirectoryAfterCollection(true);
45
46 /**
47 * @brief VulkanLoadDriver() must be called first, which is taken care of by InitializeReportGenerator().
48 */
49 m_ClockStatus = nv::perf::VulkanGetDeviceClockState(
50 state.m_Instance ,
51 state.m_PhysicalDevice ,
52 state.m_Device
53 );
54
55 NSPERF_CHECK(nv::perf::VulkanSetDeviceClockState(
56 state.m_Instance ,
57 state.m_PhysicalDevice ,
58 state.m_Device ,
59 NVPW_DEVICE_CLOCK_SETTING_LOCK_TO_RATED_TDP
60 ))
61 }
62
64 {
66
67 if (!m_NsightPerfGPUProfilerReportGenerator)
68 {
69 m_NsightPerfGPUProfilerReportGenerator = std::make_shared<NsightPerfGPUProfilerReportGenerator>(state);
70 }
71 }
72
74 {
76
77 NSPERF_CHECK(m_NvPerf.OnFrameEnd())
78
79 if (m_NvPerf.IsCollectingReport())
80 {
81 /**
82 * @brief Wait for all device task over.
83 * @note take frmame counts: 98 * SetNumNestingLevels().
84 * @todo slate infobar.
85 */
86 VK_CHECK(vkDeviceWaitIdle(state.m_Device))
87 SPICES_CORE_INFO("Nsight Perf: Report Generator is sampling.");
88 }
89 else if (m_NvPerf.GetInitStatus() != nv::perf::profiler::ReportGeneratorInitStatus::Succeeded)
90 {
91 SPICES_CORE_ERROR("Nsight Perf: Report Generator UnKnown failed.");
92 }
93 }
94
95 void NsightPerfGPUProfilerReportGenerator::BeginFrame(VkQueue queue, uint32_t queueFamilyIndex)
96 {
98
100 NSPERF_CHECK(m_NvPerf.OnFrameStart(queue, queueFamilyIndex))
101 }
102
103 void NsightPerfGPUProfilerReportGenerator::PushRange(VkCommandBuffer commandBuffer, const std::string& pRangeName) const
104 {
106
107 NSPERF_CHECK(m_NvPerf.rangeCommands.PushRange(commandBuffer, pRangeName.c_str()))
108 }
109
110 void NsightPerfGPUProfilerReportGenerator::PopRange(VkCommandBuffer commandBuffer) const
111 {
113
114 NSPERF_CHECK(m_NvPerf.rangeCommands.PopRange(commandBuffer))
115 }
116
118 {
120
121 m_NvPerf.Reset();
122 NSPERF_CHECK(nv::perf::VulkanSetDeviceClockState(state.m_Instance, state.m_PhysicalDevice, state.m_Device, m_ClockStatus))
123 }
124
126 {
128
130 {
131 NSPERF_CHECK(m_NvPerf.StartCollectionOnNextFrame())
132 m_CapturedThisFrame = false;
133 }
134 }
135}
#define NSPERF_CHECK(val)
#define SPICES_PROFILE_ZONE
#define VK_CHECK(expr)
Vulkan Check macro. Verify Vulkan API Effectiveness.
Definition VulkanUtils.h:68
static std::shared_ptr< NsightPerfGPUProfilerReportGenerator > m_NsightPerfGPUProfilerReportGenerator
This Single Instance.
void BeginFrame(VkQueue queue, uint32_t queueFamilyIndex)
Begin a Frame. OnFrameStart and OnFrameEnd will not perform any operation until collection is initiat...
void EndFrame(VulkanState &state)
End a Frame. The vkQueueWaitIdle() call in the code sequence above is a workaround for a driver/OS is...
void CollectionNextFrame()
Capture next frame and generate report.
static void CreateInstance(VulkanState &state)
Create this Single Instance.
void PushRange(VkCommandBuffer commandBuffer, const std::string &pRangeName) const
Struct VulkanRangeCommands provides a reliable set of function pointers, that are safe to call on any...
NsightPerfGPUProfilerReportGenerator(VulkanState &state)
Constructor Function.
void PopRange(VkCommandBuffer commandBuffer) const
Pop Range.
Wrapper of Nvidia NsightPerf GPU Performance ReportGenerator.
This struct contains all Vulkan object in used global.
Definition VulkanUtils.h:74