mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-08 15:51:01 +00:00
Show errors from NvPerfUtility in the RenderDoc UI
Errors related to collecting NVIDIA hardware counters are now shown in the "Errors and Warnings" window of the Renderdoc UI. Previously, these errors were only visible in stderr. This includes errors for device compatibility, resource availability, and insufficient privileges.
This commit is contained in:
committed by
Baldur Karlsson
parent
a362e42124
commit
588d205279
@@ -176,7 +176,7 @@ void D3D12Replay::CreateResources()
|
||||
NVD3D12Counters *countersNV = new NVD3D12Counters();
|
||||
|
||||
bool initSuccess = false;
|
||||
if(countersNV && countersNV->Init(m_pDevice->GetReal()))
|
||||
if(countersNV && countersNV->Init(*m_pDevice))
|
||||
{
|
||||
m_pNVCounters = countersNV;
|
||||
initSuccess = true;
|
||||
|
||||
@@ -370,7 +370,7 @@ void GLReplay::SetReplayData(GLWindowingData data)
|
||||
}
|
||||
|
||||
#if DISABLED(RDOC_ANDROID) && DISABLED(RDOC_APPLE)
|
||||
if(countersNV && countersNV->Init())
|
||||
if(countersNV && countersNV->Init(m_pDriver))
|
||||
{
|
||||
m_pNVCounters = countersNV;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,24 @@ struct NVD3D11Counters::Impl
|
||||
CounterEnumerator = NULL;
|
||||
}
|
||||
|
||||
static void LogNvPerfAsDebugMessage(const char *pPrefix, const char *pDate, const char *pTime,
|
||||
const char *pFunctionName, const char *pMessage, void *pData)
|
||||
{
|
||||
WrappedID3D11Device *device = (WrappedID3D11Device *)pData;
|
||||
rdcstr message =
|
||||
StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s%s\n%s", pPrefix, pFunctionName, pMessage);
|
||||
device->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
static void LogDebugMessage(const char *pFunctionName, const char *pMessage,
|
||||
WrappedID3D11Device *device)
|
||||
{
|
||||
rdcstr message = StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s\n%s", pFunctionName, pMessage);
|
||||
device->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
bool TryInitializePerfSDK(WrappedID3D11Device *device)
|
||||
{
|
||||
if(!NVCounterEnumerator::InitializeNvPerf())
|
||||
@@ -60,13 +78,15 @@ struct NVD3D11Counters::Impl
|
||||
|
||||
if(!nv::perf::D3D11LoadDriver())
|
||||
{
|
||||
RDCERR("NvPerf failed to load D3D11 driver");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf failed to load D3D11 driver", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!nv::perf::profiler::D3D11IsGpuSupported(device->GetReal()))
|
||||
{
|
||||
RDCERR("NvPerf does not support profiling on this GPU");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf does not support profiling on this GPU", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -74,7 +94,8 @@ struct NVD3D11Counters::Impl
|
||||
nv::perf::D3D11GetDeviceIdentifiers(device->GetReal());
|
||||
if(!deviceIdentifiers.pChipName)
|
||||
{
|
||||
RDCERR("NvPerf could not determine chip name");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine chip name", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -82,7 +103,9 @@ struct NVD3D11Counters::Impl
|
||||
nv::perf::D3D11CalculateMetricsEvaluatorScratchBufferSize(deviceIdentifiers.pChipName);
|
||||
if(!scratchBufferSize)
|
||||
{
|
||||
RDCERR("NvPerf could not determine scratch buffer size for metrics evaluation");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine scratch buffer size for metrics evaluation",
|
||||
device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -92,7 +115,8 @@ struct NVD3D11Counters::Impl
|
||||
scratchBuffer.data(), scratchBuffer.size(), deviceIdentifiers.pChipName);
|
||||
if(!pMetricsEvaluator)
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -101,7 +125,8 @@ struct NVD3D11Counters::Impl
|
||||
CounterEnumerator = new NVCounterEnumerator;
|
||||
if(!CounterEnumerator->Init(std::move(metricsEvaluator)))
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", device);
|
||||
delete CounterEnumerator;
|
||||
return false;
|
||||
}
|
||||
@@ -177,6 +202,9 @@ bool NVD3D11Counters::Init(WrappedID3D11Device *device)
|
||||
if(!m_Impl)
|
||||
return false;
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVD3D11Counters::Impl::LogNvPerfAsDebugMessage, (void *)device);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
const bool initSuccess = m_Impl->TryInitializePerfSDK(device);
|
||||
if(!initSuccess)
|
||||
{
|
||||
@@ -227,6 +255,9 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
return {};
|
||||
}
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVD3D11Counters::Impl::LogNvPerfAsDebugMessage, (void *)device);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
ID3D11Device *d3dDevice = device->GetReal();
|
||||
ID3D11DeviceContext *d3dImmediateContext = immediateContext->GetReal();
|
||||
|
||||
@@ -249,7 +280,8 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.BeginSession(d3dImmediateContext, sessionOptions))
|
||||
{
|
||||
RDCERR("NvPerf failed to start profiling session");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to start profiling session", device);
|
||||
return {}; // Failure
|
||||
}
|
||||
auto sessionGuard = nv::perf::ScopeExitGuard([&rangeProfiler]() { rangeProfiler.EndSession(); });
|
||||
@@ -275,7 +307,8 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.EnqueueCounterCollection(setConfigParams))
|
||||
{
|
||||
RDCERR("NvPerf failed to schedule counter collection");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to schedule counter collection", device);
|
||||
return {}; // Failure
|
||||
}
|
||||
|
||||
@@ -285,7 +318,8 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
{
|
||||
if(!rangeProfiler.BeginPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to start counter collection pass");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to start counter collection pass", device);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
@@ -295,14 +329,16 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.EndPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to end counter collection pass!");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to end counter collection pass!", device);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
nv::perf::profiler::DecodeResult decodeResult;
|
||||
if(!rangeProfiler.DecodeCounters(decodeResult))
|
||||
{
|
||||
RDCERR("NvPerf failed to decode counters in collection pass");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to decode counters in collection pass", device);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
@@ -322,14 +358,16 @@ rdcarray<CounterResult> NVD3D11Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(counterDataImage.empty())
|
||||
{
|
||||
RDCERR("No data found in NvPerf counter data image");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"No data found in NvPerf counter data image", device);
|
||||
return {}; // Failure
|
||||
}
|
||||
|
||||
if(!m_Impl->CounterEnumerator->EvaluateMetrics(counterDataImage.data(), counterDataImage.size(),
|
||||
results))
|
||||
{
|
||||
RDCERR("NvPerf failed to evaluate metrics from counter data");
|
||||
Impl::LogDebugMessage("NVD3D11Counters::FetchCounters",
|
||||
"NvPerf failed to evaluate metrics from counter data", device);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,25 @@ struct NVD3D12Counters::Impl
|
||||
CounterEnumerator = NULL;
|
||||
}
|
||||
|
||||
bool TryInitializePerfSDK(ID3D12Device *device)
|
||||
static void LogNvPerfAsDebugMessage(const char *pPrefix, const char *pDate, const char *pTime,
|
||||
const char *pFunctionName, const char *pMessage, void *pData)
|
||||
{
|
||||
WrappedID3D12Device *device = (WrappedID3D12Device *)pData;
|
||||
rdcstr message =
|
||||
StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s%s\n%s", pPrefix, pFunctionName, pMessage);
|
||||
device->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
static void LogDebugMessage(const char *pFunctionName, const char *pMessage,
|
||||
WrappedID3D12Device &device)
|
||||
{
|
||||
rdcstr message = StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s\n%s", pFunctionName, pMessage);
|
||||
device.AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
bool TryInitializePerfSDK(WrappedID3D12Device &device)
|
||||
{
|
||||
if(!NVCounterEnumerator::InitializeNvPerf())
|
||||
{
|
||||
@@ -63,20 +81,24 @@ struct NVD3D12Counters::Impl
|
||||
|
||||
if(!nv::perf::D3D12LoadDriver())
|
||||
{
|
||||
RDCERR("NvPerf failed to load D3D12 driver");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf failed to load D3D12 driver", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!nv::perf::profiler::D3D12IsGpuSupported(device))
|
||||
if(!nv::perf::profiler::D3D12IsGpuSupported(device.GetReal()))
|
||||
{
|
||||
RDCERR("NvPerf does not support profiling on this GPU");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf does not support profiling on this GPU", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
nv::perf::DeviceIdentifiers deviceIdentifiers = nv::perf::D3D12GetDeviceIdentifiers(device);
|
||||
nv::perf::DeviceIdentifiers deviceIdentifiers =
|
||||
nv::perf::D3D12GetDeviceIdentifiers(device.GetReal());
|
||||
if(!deviceIdentifiers.pChipName)
|
||||
{
|
||||
RDCERR("NvPerf could not determine chip name");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine chip name", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -84,7 +106,9 @@ struct NVD3D12Counters::Impl
|
||||
nv::perf::D3D12CalculateMetricsEvaluatorScratchBufferSize(deviceIdentifiers.pChipName);
|
||||
if(!scratchBufferSize)
|
||||
{
|
||||
RDCERR("NvPerf could not determine the scratch buffer size for metrics evaluation");
|
||||
Impl::LogDebugMessage(
|
||||
"NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine the scratch buffer size for metrics evaluation", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -94,7 +118,8 @@ struct NVD3D12Counters::Impl
|
||||
scratchBuffer.data(), scratchBuffer.size(), deviceIdentifiers.pChipName);
|
||||
if(!pMetricsEvaluator)
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", device);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,7 +128,8 @@ struct NVD3D12Counters::Impl
|
||||
CounterEnumerator = new NVCounterEnumerator;
|
||||
if(!CounterEnumerator->Init(std::move(metricsEvaluator)))
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", device);
|
||||
delete CounterEnumerator;
|
||||
return false;
|
||||
}
|
||||
@@ -149,13 +175,16 @@ NVD3D12Counters::~NVD3D12Counters()
|
||||
m_Impl = NULL;
|
||||
}
|
||||
|
||||
bool NVD3D12Counters::Init(ID3D12Device *device)
|
||||
bool NVD3D12Counters::Init(WrappedID3D12Device &device)
|
||||
{
|
||||
m_Impl = new Impl;
|
||||
|
||||
if(!m_Impl)
|
||||
return false;
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVD3D12Counters::Impl::LogNvPerfAsDebugMessage, (void *)&device);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
bool initSuccess = m_Impl->TryInitializePerfSDK(device);
|
||||
if(!initSuccess)
|
||||
{
|
||||
@@ -265,6 +294,9 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
return {};
|
||||
}
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVD3D12Counters::Impl::LogNvPerfAsDebugMessage, (void *)&device);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
uint32_t maxEID = device.GetQueue()->GetMaxEID();
|
||||
ID3D12Device *d3dDevice = device.GetReal();
|
||||
|
||||
@@ -316,7 +348,8 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.BeginSession(d3dQueue, sessionOptions))
|
||||
{
|
||||
RDCERR("NvPerf failed to start profiling session");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to start profiling session", device);
|
||||
continue; // Try the next command queue
|
||||
}
|
||||
auto sessionGuard = nv::perf::ScopeExitGuard([&rangeProfiler]() { rangeProfiler.EndSession(); });
|
||||
@@ -343,7 +376,8 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.EnqueueCounterCollection(setConfigParams))
|
||||
{
|
||||
RDCERR("NvPerf failed to schedule counter collection");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to schedule counter collection", device);
|
||||
continue; // Try the next command queue
|
||||
}
|
||||
|
||||
@@ -354,7 +388,8 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
{
|
||||
if(!rangeProfiler.BeginPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to start counter collection pass");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to start counter collection pass", device);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -364,7 +399,8 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(!rangeProfiler.EndPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to end counter collection pass!");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to end counter collection pass!", device);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -373,7 +409,8 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
nv::perf::profiler::DecodeResult decodeResult;
|
||||
if(!rangeProfiler.DecodeCounters(decodeResult))
|
||||
{
|
||||
RDCERR("NvPerf failed to decode counters in collection pass");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to decode counters in collection pass", device);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -385,21 +422,24 @@ rdcarray<CounterResult> NVD3D12Counters::FetchCounters(const rdcarray<GPUCounter
|
||||
|
||||
if(replayPass >= maxNumReplayPasses - 1)
|
||||
{
|
||||
RDCERR("NvPerf exceeded the maximum expected number of replay passes");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf exceeded the maximum expected number of replay passes", device);
|
||||
break; // Failure
|
||||
}
|
||||
}
|
||||
|
||||
if(counterDataImage.empty())
|
||||
{
|
||||
RDCERR("No data found in NvPerf counter data image");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"No data found in NvPerf counter data image", device);
|
||||
return {};
|
||||
}
|
||||
|
||||
if(!m_Impl->CounterEnumerator->EvaluateMetrics(counterDataImage.data(), counterDataImage.size(),
|
||||
results))
|
||||
{
|
||||
RDCERR("NvPerf failed to evaluate metrics from counter data");
|
||||
Impl::LogDebugMessage("NVD3D12Counters::FetchCounters",
|
||||
"NvPerf failed to evaluate metrics from counter data", device);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "api/replay/rdcarray.h"
|
||||
#include "api/replay/replay_enums.h"
|
||||
|
||||
struct ID3D12Device;
|
||||
class WrappedID3D12Device;
|
||||
|
||||
class NVD3D12Counters final
|
||||
@@ -37,7 +36,7 @@ public:
|
||||
NVD3D12Counters();
|
||||
~NVD3D12Counters();
|
||||
|
||||
bool Init(ID3D12Device *device);
|
||||
bool Init(WrappedID3D12Device &device);
|
||||
|
||||
rdcarray<GPUCounter> EnumerateCounters() const;
|
||||
bool HasCounter(GPUCounter counterID) const;
|
||||
|
||||
@@ -37,6 +37,23 @@ struct NVGLCounters::Impl
|
||||
NVCounterEnumerator *CounterEnumerator;
|
||||
bool LibraryNotFound = false;
|
||||
|
||||
static void LogNvPerfAsDebugMessage(const char *pPrefix, const char *pDate, const char *pTime,
|
||||
const char *pFunctionName, const char *pMessage, void *pData)
|
||||
{
|
||||
WrappedOpenGL *driver = (WrappedOpenGL *)pData;
|
||||
rdcstr message =
|
||||
StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s%s\n%s", pPrefix, pFunctionName, pMessage);
|
||||
driver->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
static void LogDebugMessage(const char *pFunctionName, const char *pMessage, WrappedOpenGL *driver)
|
||||
{
|
||||
rdcstr message = StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s\n%s", pFunctionName, pMessage);
|
||||
driver->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
Impl() : CounterEnumerator(NULL) {}
|
||||
~Impl()
|
||||
{
|
||||
@@ -44,7 +61,7 @@ struct NVGLCounters::Impl
|
||||
CounterEnumerator = NULL;
|
||||
}
|
||||
|
||||
bool TryInitializePerfSDK()
|
||||
bool TryInitializePerfSDK(WrappedOpenGL *driver)
|
||||
{
|
||||
if(!NVCounterEnumerator::InitializeNvPerf())
|
||||
{
|
||||
@@ -58,20 +75,23 @@ struct NVGLCounters::Impl
|
||||
|
||||
if(!nv::perf::OpenGLLoadDriver())
|
||||
{
|
||||
RDCERR("NvPerf failed to load OpenGL driver");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf failed to load OpenGL driver", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!nv::perf::profiler::OpenGLIsGpuSupported())
|
||||
{
|
||||
RDCERR("NvPerf does not support profiling on this GPU");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf does not support profiling on this GPU", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
nv::perf::DeviceIdentifiers deviceIdentifiers = nv::perf::OpenGLGetDeviceIdentifiers();
|
||||
if(!deviceIdentifiers.pChipName)
|
||||
{
|
||||
RDCERR("NvPerf could not determine chip name");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine chip name", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,7 +99,9 @@ struct NVGLCounters::Impl
|
||||
nv::perf::OpenGLCalculateMetricsEvaluatorScratchBufferSize(deviceIdentifiers.pChipName);
|
||||
if(!scratchBufferSize)
|
||||
{
|
||||
RDCERR("NvPerf could not determine scratch buffer size for metrics evaluation");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine scratch buffer size for metrics evaluation",
|
||||
driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,7 +111,8 @@ struct NVGLCounters::Impl
|
||||
scratchBuffer.data(), scratchBuffer.size(), deviceIdentifiers.pChipName);
|
||||
if(!pMetricsEvaluator)
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,7 +121,8 @@ struct NVGLCounters::Impl
|
||||
CounterEnumerator = new NVCounterEnumerator;
|
||||
if(!CounterEnumerator->Init(std::move(metricsEvaluator)))
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVGLCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", driver);
|
||||
delete CounterEnumerator;
|
||||
return false;
|
||||
}
|
||||
@@ -168,13 +192,16 @@ NVGLCounters::~NVGLCounters()
|
||||
m_Impl = NULL;
|
||||
}
|
||||
|
||||
bool NVGLCounters::Init()
|
||||
bool NVGLCounters::Init(WrappedOpenGL *driver)
|
||||
{
|
||||
m_Impl = new Impl;
|
||||
if(!m_Impl)
|
||||
return false;
|
||||
|
||||
const bool initSuccess = m_Impl->TryInitializePerfSDK();
|
||||
nv::perf::UserLogEnableCustom(NVGLCounters::Impl::LogNvPerfAsDebugMessage, (void *)driver);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
const bool initSuccess = m_Impl->TryInitializePerfSDK(driver);
|
||||
if(!initSuccess)
|
||||
{
|
||||
delete m_Impl;
|
||||
@@ -222,6 +249,9 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
return {};
|
||||
}
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVGLCounters::Impl::LogNvPerfAsDebugMessage, (void *)driver);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
uint32_t maxNumRanges;
|
||||
{
|
||||
uint32_t numEvents = 0u;
|
||||
@@ -241,7 +271,8 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
|
||||
if(!rangeProfiler.BeginSession(sessionOptions))
|
||||
{
|
||||
RDCERR("NvPerf failed to start profiling session");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters", "NvPerf failed to start profiling session",
|
||||
driver);
|
||||
return {}; // Failure
|
||||
}
|
||||
auto sessionGuard = nv::perf::ScopeExitGuard([&rangeProfiler]() { rangeProfiler.EndSession(); });
|
||||
@@ -267,7 +298,8 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
|
||||
if(!rangeProfiler.EnqueueCounterCollection(setConfigParams))
|
||||
{
|
||||
RDCERR("NvPerf failed to schedule counter collection");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf failed to schedule counter collection", driver);
|
||||
return {}; // Failure
|
||||
}
|
||||
|
||||
@@ -276,7 +308,8 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
{
|
||||
if(!rangeProfiler.BeginPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to start counter collection pass");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf failed to start counter collection pass", driver);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
@@ -285,14 +318,16 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
|
||||
if(!rangeProfiler.EndPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to end counter collection pass!");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf failed to end counter collection pass!", driver);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
nv::perf::profiler::DecodeResult decodeResult;
|
||||
if(!rangeProfiler.DecodeCounters(decodeResult))
|
||||
{
|
||||
RDCERR("NvPerf failed to decode counters in collection pass");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf failed to decode counters in collection pass", driver);
|
||||
break; // Failure
|
||||
}
|
||||
|
||||
@@ -304,21 +339,24 @@ rdcarray<CounterResult> NVGLCounters::FetchCounters(const rdcarray<GPUCounter> &
|
||||
|
||||
if(replayPass >= maxNumReplayPasses - 1)
|
||||
{
|
||||
RDCERR("NvPerf exceeded the maximum expected number of replay passes");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf exceeded the maximum expected number of replay passes", driver);
|
||||
break; // Failure
|
||||
}
|
||||
}
|
||||
|
||||
if(counterDataImage.empty())
|
||||
{
|
||||
RDCERR("No data found in NvPerf counter data image");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"No data found in NvPerf counter data image", driver);
|
||||
return {}; // Failure
|
||||
}
|
||||
|
||||
if(!m_Impl->CounterEnumerator->EvaluateMetrics(counterDataImage.data(), counterDataImage.size(),
|
||||
results))
|
||||
{
|
||||
RDCERR("NvPerf failed to evaluate metrics from counter data");
|
||||
Impl::LogDebugMessage("NVGLCounters::FetchCounters",
|
||||
"NvPerf failed to evaluate metrics from counter data", driver);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
NVGLCounters();
|
||||
~NVGLCounters();
|
||||
|
||||
bool Init();
|
||||
bool Init(WrappedOpenGL *driver);
|
||||
|
||||
rdcarray<GPUCounter> EnumerateCounters() const;
|
||||
bool HasCounter(GPUCounter counterID) const;
|
||||
|
||||
@@ -46,6 +46,23 @@ struct NVVulkanCounters::Impl
|
||||
CounterEnumerator = NULL;
|
||||
}
|
||||
|
||||
static void LogNvPerfAsDebugMessage(const char *pPrefix, const char *pDate, const char *pTime,
|
||||
const char *pFunctionName, const char *pMessage, void *pData)
|
||||
{
|
||||
WrappedVulkan *driver = (WrappedVulkan *)pData;
|
||||
rdcstr message =
|
||||
StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s%s\n%s", pPrefix, pFunctionName, pMessage);
|
||||
driver->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
static void LogDebugMessage(const char *pFunctionName, const char *pMessage, WrappedVulkan *driver)
|
||||
{
|
||||
rdcstr message = StringFormat::Fmt("NVIDIA Nsight Perf SDK\n%s\n%s", pFunctionName, pMessage);
|
||||
driver->AddDebugMessage(MessageCategory::Miscellaneous, MessageSeverity::High,
|
||||
MessageSource::RuntimeWarning, message);
|
||||
}
|
||||
|
||||
bool TryInitializePerfSDK(WrappedVulkan *driver)
|
||||
{
|
||||
if(!NVCounterEnumerator::InitializeNvPerf())
|
||||
@@ -60,7 +77,8 @@ struct NVVulkanCounters::Impl
|
||||
|
||||
if(!nv::perf::VulkanLoadDriver(Unwrap(driver->GetInstance())))
|
||||
{
|
||||
RDCERR("NvPerf failed to load Vulkan driver");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf failed to load Vulkan driver", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -69,7 +87,8 @@ struct NVVulkanCounters::Impl
|
||||
ObjDisp(driver->GetInstance())->GetInstanceProcAddr,
|
||||
ObjDisp(driver->GetDev())->GetDeviceProcAddr))
|
||||
{
|
||||
RDCERR("NvPerf does not support profiling on this GPU");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf does not support profiling on this GPU", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,7 +98,8 @@ struct NVVulkanCounters::Impl
|
||||
ObjDisp(driver->GetDev())->GetDeviceProcAddr);
|
||||
if(!deviceIdentifiers.pChipName)
|
||||
{
|
||||
RDCERR("NvPerf could not determine chip name");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine chip name", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,7 +107,9 @@ struct NVVulkanCounters::Impl
|
||||
nv::perf::VulkanCalculateMetricsEvaluatorScratchBufferSize(deviceIdentifiers.pChipName);
|
||||
if(!scratchBufferSize)
|
||||
{
|
||||
RDCERR("NvPerf could not determine scratch buffer size for metrics evaluation");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not determine scratch buffer size for metrics evaluation",
|
||||
driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -97,7 +119,8 @@ struct NVVulkanCounters::Impl
|
||||
scratchBuffer.data(), scratchBuffer.size(), deviceIdentifiers.pChipName);
|
||||
if(!pMetricsEvaluator)
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", driver);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -106,7 +129,8 @@ struct NVVulkanCounters::Impl
|
||||
CounterEnumerator = new NVCounterEnumerator;
|
||||
if(!CounterEnumerator->Init(std::move(metricsEvaluator)))
|
||||
{
|
||||
RDCERR("NvPerf could not initialize metrics evaluator");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::Impl::TryInitializePerfSDK",
|
||||
"NvPerf could not initialize metrics evaluator", driver);
|
||||
delete CounterEnumerator;
|
||||
return false;
|
||||
}
|
||||
@@ -158,6 +182,9 @@ bool NVVulkanCounters::Init(WrappedVulkan *driver)
|
||||
if(!m_Impl)
|
||||
return false;
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVVulkanCounters::Impl::LogNvPerfAsDebugMessage, (void *)driver);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
const bool initSuccess = m_Impl->TryInitializePerfSDK(driver);
|
||||
if(!initSuccess)
|
||||
{
|
||||
@@ -259,6 +286,9 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
return {};
|
||||
}
|
||||
|
||||
nv::perf::UserLogEnableCustom(NVVulkanCounters::Impl::LogNvPerfAsDebugMessage, (void *)driver);
|
||||
auto logGuard = nv::perf::ScopeExitGuard([]() { nv::perf::UserLogDisableCustom(); });
|
||||
|
||||
uint32_t maxEID = driver->GetMaxEID();
|
||||
|
||||
uint32_t maxNumRanges = 0;
|
||||
@@ -287,7 +317,8 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
ObjDisp(driver->GetInstance())->GetInstanceProcAddr,
|
||||
ObjDisp(driver->GetDev())->GetDeviceProcAddr))
|
||||
{
|
||||
RDCERR("NvPerf failed to start profiling session");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to start profiling session", driver);
|
||||
return {}; // Failure
|
||||
}
|
||||
auto sessionGuard = nv::perf::ScopeExitGuard([&rangeProfiler]() { rangeProfiler.EndSession(); });
|
||||
@@ -318,7 +349,8 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
|
||||
if(!rangeProfiler.EnqueueCounterCollection(setConfigParams))
|
||||
{
|
||||
RDCERR("NvPerf failed to schedule counter collection");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to schedule counter collection", driver);
|
||||
return {}; // Failure
|
||||
}
|
||||
|
||||
@@ -329,7 +361,8 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
{
|
||||
if(!rangeProfiler.BeginPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to start counter collection pass");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to start counter collection pass", driver);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -339,7 +372,8 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
|
||||
if(!rangeProfiler.EndPass())
|
||||
{
|
||||
RDCERR("NvPerf failed to end counter collection pass!");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to end counter collection pass!", driver);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -348,7 +382,8 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
nv::perf::profiler::DecodeResult decodeResult;
|
||||
if(!rangeProfiler.DecodeCounters(decodeResult))
|
||||
{
|
||||
RDCERR("NvPerf failed to decode counters in collection pass");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to decode counters in collection pass", driver);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -360,21 +395,24 @@ rdcarray<CounterResult> NVVulkanCounters::FetchCounters(const rdcarray<GPUCounte
|
||||
|
||||
if(replayPass >= maxNumReplayPasses - 1)
|
||||
{
|
||||
RDCERR("NvPerf exceeded the maximum expected number of replay passes");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf exceeded the maximum expected number of replay passes", driver);
|
||||
break; // Failure
|
||||
}
|
||||
}
|
||||
|
||||
if(counterDataImage.empty())
|
||||
{
|
||||
RDCERR("No data found in NvPerf counter data image");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"No data found in NvPerf counter data image", driver);
|
||||
return {};
|
||||
}
|
||||
|
||||
if(!m_Impl->CounterEnumerator->EvaluateMetrics(counterDataImage.data(), counterDataImage.size(),
|
||||
results))
|
||||
{
|
||||
RDCERR("NvPerf failed to evaluate metrics from counter data");
|
||||
Impl::LogDebugMessage("NVVulkanCounters::FetchCounters",
|
||||
"NvPerf failed to evaluate metrics from counter data", driver);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user