Skip to content

Commit 69cd5d2

Browse files
committed
restructured integration
1 parent b252d96 commit 69cd5d2

File tree

4 files changed

+90
-93
lines changed

4 files changed

+90
-93
lines changed

include/nbl/video/IAPIConnection.h

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

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

1615
namespace nbl::video
1716
{
@@ -61,25 +60,32 @@ class NBL_API2 IAPIConnection : public core::IReferenceCounted
6160

6261
const SFeatures& getEnabledFeatures() const { return m_enabledFeatures; }
6362

64-
enum DebuggerType
63+
enum SDebuggerType
6564
{
6665
EDT_NONE,
6766
EDT_RENDERDOC,
6867
EDT_NGFX
6968
};
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-
}
69+
const SDebuggerType isRunningInGraphicsDebugger() const { return m_debuggerType; }
7470
virtual bool startCapture() = 0;
7571
virtual bool endCapture() = 0;
7672

7773
protected:
7874
IAPIConnection(const SFeatures& enabledFeatures);
7975

8076
std::vector<std::unique_ptr<IPhysicalDevice>> m_physicalDevices;
77+
SDebuggerType m_debuggerType;
8178
renderdoc_api_t* m_rdoc_api;
79+
80+
struct SNGFXIntegration {
81+
bool useNGFX;
82+
83+
bool injectNGFXToProcess();
84+
bool executeNGFXCommand();
85+
};
86+
using ngfx_api_t = SNGFXIntegration;
8287
ngfx_api_t m_ngfx_api;
88+
8389
SFeatures m_enabledFeatures = {};
8490
};
8591

include/nbl/video/utilities/ngfx.h

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/nbl/video/CVulkanConnection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ bool CVulkanConnection::startCapture()
339339
if (debugType == EDT_RENDERDOC)
340340
m_rdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
341341
else
342-
executeNGFXCommand();
342+
m_ngfx_api.executeNGFXCommand();
343343
return true;
344344
}
345345

@@ -360,6 +360,7 @@ bool CVulkanConnection::endCapture()
360360
if (debugType == EDT_RENDERDOC)
361361
m_rdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
362362
// no equivalent end frame capture for ngfx, ends captures on next frame delimiter
363+
// see https://www.reddit.com/r/GraphicsProgramming/comments/w0hl9o/graphics_debugger_record_before_first_frame/
363364
flag.clear();
364365
return true;
365366
}

src/nbl/video/IAPIConnection.cpp

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
#include "nbl/video/utilities/renderdoc.h"
55
#include "nbl/video/utilities/ngfx.h"
66

7+
// TODO: temporary hopefully
8+
#include "C:\Program Files\NVIDIA Corporation\Nsight Graphics 2024.1.0\SDKs\NsightGraphicsSDK\0.8.0\include\NGFX_Injection.h"
9+
710
#if defined(_NBL_POSIX_API_)
811
#include <dlfcn.h>
912
#endif
1013

1114
namespace nbl::video
1215
{
1316

17+
1418
std::span<IPhysicalDevice* const> IAPIConnection::getPhysicalDevices() const
1519
{
1620
static_assert(sizeof(std::unique_ptr<IPhysicalDevice>) == sizeof(void*));
@@ -46,8 +50,79 @@ IAPIConnection::IAPIConnection(const SFeatures& enabledFeatures)
4650
#endif
4751

4852
// probably is platform agnostic, for now
49-
injectNGFXToProcess(m_ngfx_api);
53+
m_ngfx_api.injectNGFXToProcess();
54+
55+
m_debuggerType = m_ngfx_api.useNGFX ? EDT_NGFX : // ngfx takes priority?
56+
m_rdoc_api ? EDT_RENDERDOC : EDT_NONE;
57+
}
58+
}
59+
60+
bool IAPIConnection::SNGFXIntegration::injectNGFXToProcess()
61+
{
62+
uint32_t numInstallations = 0;
63+
auto result = NGFX_Injection_EnumerateInstallations(&numInstallations, nullptr);
64+
if (numInstallations == 0 || NGFX_INJECTION_RESULT_OK != result)
65+
{
66+
useNGFX = false;
67+
return false;
68+
}
69+
70+
std::vector<NGFX_Injection_InstallationInfo> installations(numInstallations);
71+
result = NGFX_Injection_EnumerateInstallations(&numInstallations, installations.data());
72+
if (numInstallations == 0 || NGFX_INJECTION_RESULT_OK != result)
73+
{
74+
useNGFX = false;
75+
return false;
76+
}
77+
78+
// get latest installation
79+
NGFX_Injection_InstallationInfo versionInfo = installations.back();
80+
81+
uint32_t numActivities = 0;
82+
result = NGFX_Injection_EnumerateActivities(&versionInfo, &numActivities, nullptr);
83+
if (numActivities == 0 || NGFX_INJECTION_RESULT_OK != result)
84+
{
85+
useNGFX = false;
86+
return false;
5087
}
88+
89+
std::vector<NGFX_Injection_Activity> activities(numActivities);
90+
result = NGFX_Injection_EnumerateActivities(&versionInfo, &numActivities, activities.data());
91+
if (NGFX_INJECTION_RESULT_OK != result)
92+
{
93+
useNGFX = false;
94+
return false;
95+
}
96+
97+
const NGFX_Injection_Activity* pActivityToInject = nullptr;
98+
for (const NGFX_Injection_Activity& activity : activities)
99+
{
100+
if (activity.type == NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER) // only want frame debugger
101+
{
102+
pActivityToInject = &activity;
103+
break;
104+
}
105+
}
106+
107+
if (!pActivityToInject) {
108+
useNGFX = false;
109+
return false;
110+
}
111+
112+
result = NGFX_Injection_InjectToProcess(&versionInfo, pActivityToInject);
113+
if (NGFX_INJECTION_RESULT_OK != result)
114+
{
115+
useNGFX = false;
116+
return false;
117+
}
118+
119+
useNGFX = true;
120+
return true;
121+
}
122+
123+
bool IAPIConnection::SNGFXIntegration::executeNGFXCommand()
124+
{
125+
return NGFX_Injection_ExecuteActivityCommand() == NGFX_INJECTION_RESULT_OK;
51126
}
52127

53128
}

0 commit comments

Comments
 (0)