Skip to content

Commit 7df72fe

Browse files
committed
ngfx integration
1 parent de62785 commit 7df72fe

File tree

4 files changed

+105
-6
lines changed

4 files changed

+105
-6
lines changed

include/nbl/video/IAPIConnection.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "nbl/video/debug/IDebugCallback.h"
1212

1313
#include "nbl/video/utilities/renderdoc.h"
14-
14+
#include "nbl/video/utilities/ngfx.h"
1515

1616
namespace nbl::video
1717
{
@@ -61,7 +61,16 @@ class NBL_API2 IAPIConnection : public core::IReferenceCounted
6161

6262
const SFeatures& getEnabledFeatures() const { return m_enabledFeatures; }
6363

64-
const bool isRunningInRenderdoc() const { return m_rdoc_api; }
64+
enum DebuggerType
65+
{
66+
EDT_NONE,
67+
EDT_RENDERDOC,
68+
EDT_NGFX
69+
};
70+
const DebuggerType isRunningInGraphicsDebugger() const {
71+
return m_ngfx_api.useNGFX ? EDT_NGFX : // ngfx takes priority?
72+
m_rdoc_api ? EDT_RENDERDOC : EDT_NONE;
73+
}
6574
virtual bool startCapture() = 0;
6675
virtual bool endCapture() = 0;
6776

@@ -70,6 +79,7 @@ class NBL_API2 IAPIConnection : public core::IReferenceCounted
7079

7180
std::vector<std::unique_ptr<IPhysicalDevice>> m_physicalDevices;
7281
renderdoc_api_t* m_rdoc_api;
82+
ngfx_api_t m_ngfx_api;
7383
SFeatures m_enabledFeatures = {};
7484
};
7585

include/nbl/video/utilities/ngfx.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef _NBL_VIDEO_UTILITIES_NGFX_H_INCLUDED_
2+
#define _NBL_VIDEO_UTILITIES_NGFX_H_INCLUDED_
3+
4+
#include "C:\Program Files\NVIDIA Corporation\Nsight Graphics 2024.1.0\SDKs\NsightGraphicsSDK\0.8.0\include\NGFX_Injection.h"
5+
6+
namespace nbl::video
7+
{
8+
struct SNGFXIntegration
9+
{
10+
bool useNGFX;
11+
NGFX_Injection_InstallationInfo versionInfo;
12+
};
13+
14+
bool injectNGFXToProcess(SNGFXIntegration& api)
15+
{
16+
uint32_t numInstallations = 0;
17+
auto result = NGFX_Injection_EnumerateInstallations(&numInstallations, nullptr);
18+
if (numInstallations == 0 || NGFX_INJECTION_RESULT_OK != result)
19+
{
20+
api.useNGFX = false;
21+
return false;
22+
}
23+
24+
std::vector<NGFX_Injection_InstallationInfo> installations(numInstallations);
25+
result = NGFX_Injection_EnumerateInstallations(&numInstallations, installations.data());
26+
if (numInstallations == 0 || NGFX_INJECTION_RESULT_OK != result)
27+
{
28+
api.useNGFX = false;
29+
return false;
30+
}
31+
32+
// get latest installation
33+
api.versionInfo = installations.back();
34+
35+
uint32_t numActivities = 0;
36+
result = NGFX_Injection_EnumerateActivities(&api.versionInfo, &numActivities, nullptr);
37+
if (numActivities == 0 || NGFX_INJECTION_RESULT_OK != result)
38+
{
39+
api.useNGFX = false;
40+
return false;
41+
}
42+
43+
std::vector<NGFX_Injection_Activity> activities(numActivities);
44+
result = NGFX_Injection_EnumerateActivities(&api.versionInfo, &numActivities, activities.data());
45+
if (NGFX_INJECTION_RESULT_OK != result)
46+
{
47+
api.useNGFX = false;
48+
return false;
49+
}
50+
51+
const NGFX_Injection_Activity* pActivityToInject = nullptr;
52+
for (const NGFX_Injection_Activity& activity : activities)
53+
{
54+
if (activity.type == NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER) // only want frame debugger
55+
{
56+
pActivityToInject = &activity;
57+
break;
58+
}
59+
}
60+
61+
if (!pActivityToInject) {
62+
api.useNGFX = false;
63+
return false;
64+
}
65+
66+
result = NGFX_Injection_InjectToProcess(&api.versionInfo, pActivityToInject);
67+
if (NGFX_INJECTION_RESULT_OK != result)
68+
{
69+
api.useNGFX = false;
70+
return false;
71+
}
72+
73+
return true;
74+
}
75+
76+
using ngfx_api_t = SNGFXIntegration;
77+
}
78+
79+
#endif //_NBL_VIDEO_UTILITIES_NGFX_H_INCLUDED_

src/nbl/video/CVulkanConnection.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ CVulkanConnection::~CVulkanConnection()
323323

324324
bool CVulkanConnection::startCapture()
325325
{
326-
if (!isRunningInRenderdoc())
326+
auto debugType = isRunningInGraphicsDebugger();
327+
if (debugType == EDT_NONE)
327328
return false;
328329
if (flag.test())
329330
{
@@ -335,13 +336,17 @@ bool CVulkanConnection::startCapture()
335336
}
336337

337338
flag.test_and_set();
338-
m_rdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
339+
if (debugType == EDT_RENDERDOC)
340+
m_rdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
341+
else
342+
NGFX_Injection_ExecuteActivityCommand();
339343
return true;
340344
}
341345

342346
bool CVulkanConnection::endCapture()
343347
{
344-
if (!isRunningInRenderdoc())
348+
auto debugType = isRunningInGraphicsDebugger();
349+
if (debugType == EDT_NONE)
345350
return false;
346351
if (!flag.test())
347352
{
@@ -352,7 +357,9 @@ bool CVulkanConnection::endCapture()
352357
return false;
353358
}
354359

355-
m_rdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
360+
if (debugType == EDT_RENDERDOC)
361+
m_rdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
362+
// no equivalent end frame capture for ngfx, ends captures on next frame delimiter
356363
flag.clear();
357364
return true;
358365
}

src/nbl/video/IAPIConnection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ IAPIConnection::IAPIConnection(const SFeatures& enabledFeatures)
4343
int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api);
4444
assert(ret == 1);
4545
#endif
46+
47+
// probably is platform agnostic, for now
48+
injectNGFXToProcess(m_ngfx_api);
4649
}
4750
}
4851

0 commit comments

Comments
 (0)