Skip to content

Commit d03952a

Browse files
jglines-nvidiabaldurk
authored andcommitted
Fix crash in NVIDIA HasCounter() called without EnumerateCounters()
This fix avoids a NULL-pointer dereference when HasCounter() is called without a preceding call to EnumerateCounters() for NVIDIA Nsight Perf SDK counters.
1 parent 8c97cfb commit d03952a

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

renderdoc/driver/ihv/nv/nv_d3d11_counters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ bool NVD3D11Counters::HasCounter(GPUCounter counterID) const
296296
{
297297
return counterID == GPUCounter::FirstNvidia;
298298
}
299+
if(!m_Impl->CounterEnumerator)
300+
{
301+
return false;
302+
}
299303
return m_Impl->CounterEnumerator->HasCounter(counterID);
300304
}
301305

renderdoc/driver/ihv/nv/nv_d3d12_counters.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ rdcarray<GPUCounter> NVD3D12Counters::EnumerateCounters(WrappedID3D12Device &dev
293293
{
294294
return {GPUCounter::FirstNvidia};
295295
}
296+
// NOTE: Nsight Perf SDK needs access to a D3D12 device handle and command
297+
// queue in order to determine which counters are available on a
298+
// particular NVIDIA device. However, since the D3D12 command queue is
299+
// not available at the time NVD3D12Counters::Init() is called this
300+
// determination must be deferred until the first time
301+
// NVD3D12Counters::EnumerateCounters() is called.
296302
if(!m_Impl->InitCounterEnumerator(device))
297303
{
298304
return {GPUCounter::FirstNvidia};
@@ -306,6 +312,10 @@ bool NVD3D12Counters::HasCounter(GPUCounter counterID) const
306312
{
307313
return counterID == GPUCounter::FirstNvidia;
308314
}
315+
if(!m_Impl->CounterEnumerator)
316+
{
317+
return false;
318+
}
309319
return m_Impl->CounterEnumerator->HasCounter(counterID);
310320
}
311321

renderdoc/driver/ihv/nv/nv_gl_counters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ bool NVGLCounters::HasCounter(GPUCounter counterID) const
292292
{
293293
return counterID == GPUCounter::FirstNvidia;
294294
}
295+
if(!m_Impl->CounterEnumerator)
296+
{
297+
return false;
298+
}
295299
return m_Impl->CounterEnumerator->HasCounter(counterID);
296300
}
297301

renderdoc/driver/ihv/nv/nv_vk_counters.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ bool NVVulkanCounters::HasCounter(GPUCounter counterID) const
282282
{
283283
return counterID == GPUCounter::FirstNvidia;
284284
}
285+
if(!m_Impl->CounterEnumerator)
286+
{
287+
return false;
288+
}
285289
return m_Impl->CounterEnumerator->HasCounter(counterID);
286290
}
287291

0 commit comments

Comments
 (0)