Skip to content

Commit 12bbe91

Browse files
author
devsh
committed
refactor
1 parent 01dcf66 commit 12bbe91

File tree

5 files changed

+150
-172
lines changed

5 files changed

+150
-172
lines changed

3rdparty/ngfx/ngfx.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ option(NBL_BUILD_WITH_NGFX "Enable NGFX build" OFF)
55
# then you can pick SDK version with "NGFX_SDK_VERSION" cache variable (CMake GUI list supported)
66

77
if(NBL_BUILD_WITH_NGFX)
8-
if(NOT DEFINED ENV{NGFX_SDK})
9-
message(FATAL_ERROR "\"NGFX_SDK\" environment variable must be defined to build with NBL_BUILD_WITH_NGFX enabled!")
8+
if(NOT DEFINED NGFX_SDK)
9+
if(NOT DEFINED ENV{NGFX_SDK})
10+
message(FATAL_ERROR "\"NGFX_SDK\" environment variable must be defined to build with NBL_BUILD_WITH_NGFX enabled!")
11+
endif()
12+
set(NGFX_SDK "$ENV{NGFX_SDK}")
1013
endif()
11-
12-
set(NGFX_SDK "$ENV{NGFX_SDK}")
1314
cmake_path(NORMAL_PATH NGFX_SDK OUTPUT_VARIABLE NGFX_SDK)
1415

1516
if(NOT EXISTS "${NGFX_SDK}")

include/nbl/video/IAPIConnection.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class IPhysicalDevice;
2020
class NBL_API2 IAPIConnection : public core::IReferenceCounted
2121
{
2222
public:
23-
2423
// Equivalent to Instance Extensions and Layers
2524
// Any device feature that has an api connection feature dependency that is not enabled is considered to be unsupported,
2625
// for example you need to enable E_SWAPCHAIN_MODE::ESM_SURFACE in order for the physical device to report support in SPhysicalDeviceFeatures::swapchainMode
@@ -60,39 +59,35 @@ class NBL_API2 IAPIConnection : public core::IReferenceCounted
6059

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

63-
enum SDebuggerType
62+
//
63+
enum class EDebuggerType : uint8_t
6464
{
65-
EDT_NONE,
66-
EDT_RENDERDOC,
67-
EDT_NGFX
65+
None,
66+
Renderdoc,
67+
NSight
6868
};
69-
const SDebuggerType isRunningInGraphicsDebugger() const { return m_debuggerType; }
69+
inline EDebuggerType runningInGraphicsDebugger() const {return m_debugger;}
70+
inline bool isRunningInGraphicsDebugger() const {return m_debugger!=EDebuggerType::None;}
71+
72+
//
7073
virtual bool startCapture() = 0;
7174
virtual bool endCapture() = 0;
7275

7376
protected:
7477
IAPIConnection(const SFeatures& enabledFeatures);
7578

76-
std::vector<std::unique_ptr<IPhysicalDevice>> m_physicalDevices;
77-
SDebuggerType m_debuggerType;
78-
renderdoc_api_t* m_rdoc_api;
79+
bool loadRenderdoc();
7980

80-
struct SNGFXIntegration
81-
{
82-
SNGFXIntegration();
81+
bool loadNGFX() const;
82+
void executeNGFXCommand();
8383

84-
bool useNGFX = false;
8584

86-
bool injectNGFXToProcess();
87-
bool executeNGFXCommand();
88-
inline bool isAPILoaded() { return m_loaded; }
89-
private:
90-
const bool m_loaded;
91-
};
92-
using ngfx_api_t = SNGFXIntegration;
93-
ngfx_api_t m_ngfx_api;
85+
std::vector<std::unique_ptr<IPhysicalDevice>> m_physicalDevices;
9486

9587
SFeatures m_enabledFeatures = {};
88+
89+
EDebuggerType m_debugger = EDebuggerType::None;
90+
renderdoc_api_t* m_rdoc_api = nullptr;
9691
};
9792

9893
}

src/nbl/video/CVulkanConnection.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -323,31 +323,30 @@ CVulkanConnection::~CVulkanConnection()
323323

324324
bool CVulkanConnection::startCapture()
325325
{
326-
auto debugType = isRunningInGraphicsDebugger();
327-
if (debugType == EDT_NONE)
328-
return false;
329-
if (flag.test())
326+
if (flag.test_and_set())
330327
{
331328
auto logger = m_debugCallback->getLogger();
332329
if(logger)
333330
logger->log("Only one capture can be running at a time.", system::ILogger::ELL_ERROR);
334331

335332
return false;
336333
}
337-
338-
flag.test_and_set();
339-
if (debugType == EDT_RENDERDOC)
340-
m_rdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance), NULL);
341-
else
342-
m_ngfx_api.executeNGFXCommand();
334+
switch (runningInGraphicsDebugger())
335+
{
336+
case EDebuggerType::Renderdoc:
337+
m_rdoc_api->StartFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance),NULL);
338+
break;
339+
case EDebuggerType::NSight:
340+
executeNGFXCommand();
341+
break;
342+
default:
343+
return false;
344+
}
343345
return true;
344346
}
345347

346348
bool CVulkanConnection::endCapture()
347349
{
348-
auto debugType = isRunningInGraphicsDebugger();
349-
if (debugType == EDT_NONE)
350-
return false;
351350
if (!flag.test())
352351
{
353352
auto logger = m_debugCallback->getLogger();
@@ -356,11 +355,19 @@ bool CVulkanConnection::endCapture()
356355

357356
return false;
358357
}
359-
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
363-
// see https://www.reddit.com/r/GraphicsProgramming/comments/w0hl9o/graphics_debugger_record_before_first_frame/
358+
switch (runningInGraphicsDebugger())
359+
{
360+
case EDebuggerType::Renderdoc:
361+
m_rdoc_api->EndFrameCapture(RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(m_vkInstance),nullptr);
362+
break;
363+
case EDebuggerType::NSight:
364+
// no equivalent end frame capture for ngfx, ends captures on next frame delimiter
365+
// see https://www.reddit.com/r/GraphicsProgramming/comments/w0hl9o/graphics_debugger_record_before_first_frame/
366+
break;
367+
default:
368+
flag.clear();
369+
return false;
370+
}
364371
flag.clear();
365372
return true;
366373
}

0 commit comments

Comments
 (0)