Skip to content

Commit 812398c

Browse files
authored
Merge pull request #948 from Devsh-Graphics-Programming/vkinfoUpdates
Vkinfo updates
2 parents 00363cc + 0168ad7 commit 812398c

File tree

11 files changed

+330
-229
lines changed

11 files changed

+330
-229
lines changed

3rdparty/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,6 @@ nbl_install_dir(imath/src/Imath)
543543

544544
nbl_install_file(blake/c/blake3.h)
545545

546-
nbl_install_file_spec(nlohmann_json/include/nlohmann/json_fwd.hpp nlohmann)
547-
nbl_install_file_spec(nlohmann_json/include/nlohmann/detail/abi_macros.hpp nlohmann/detail)
548-
549546
nbl_install_dir(boost/superproject/libs/preprocessor/include/boost)
550547

551548
nbl_install_file_spec(renderdoc/renderdoc_app.h renderdoc)

include/nbl/asset/utils/IShaderCompiler.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#include "nbl/asset/IShader.h"
1414
#include "nbl/asset/utils/ISPIRVOptimizer.h"
15-
16-
// Less leakage than "nlohmann/json.hpp" only forward declarations
17-
#include "nlohmann/json_fwd.hpp"
15+
#include "nbl/system/json.h"
1816

1917
#include "nbl/builtin/hlsl/enums.hlsl"
2018

@@ -111,11 +109,10 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
111109
//
112110
struct SMacroDefinition
113111
{
114-
friend void to_json(nlohmann::json&, const SMacroDefinition&);
115-
friend void from_json(const nlohmann::json&, SMacroDefinition&);
116-
117112
std::string_view identifier;
118113
std::string_view definition;
114+
115+
friend struct system::json::adl_serializer<SMacroDefinition>;
119116
};
120117

121118
//
@@ -216,9 +213,8 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
216213
inline SPreprocessingDependency() {}
217214

218215
private:
219-
friend void to_json(nlohmann::json& j, const SEntry::SPreprocessingDependency& dependency);
220-
friend void from_json(const nlohmann::json& j, SEntry::SPreprocessingDependency& dependency);
221216
friend class CCache;
217+
friend struct system::json::adl_serializer<SEntry::SPreprocessingDependency>;
222218

223219
// path or identifier
224220
system::path requestingSourceDir = "";
@@ -252,8 +248,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
252248
friend class SCompilerArgs;
253249
friend class SEntry;
254250
friend class CCache;
255-
friend void to_json(nlohmann::json&, const SPreprocessorArgs&);
256-
friend void from_json(const nlohmann::json&, SPreprocessorArgs&);
251+
friend struct system::json::adl_serializer<SPreprocessorArgs>;
257252

258253
// Default constructor needed for json serialization of SCompilerArgs
259254
SPreprocessorArgs() {};
@@ -295,8 +290,7 @@ class NBL_API2 IShaderCompiler : public core::IReferenceCounted
295290
private:
296291
friend class SEntry;
297292
friend class CCache;
298-
friend void to_json(nlohmann::json&, const SCompilerArgs&);
299-
friend void from_json(const nlohmann::json&, SCompilerArgs&);
293+
friend struct system::json::adl_serializer<SCompilerArgs>;
300294

301295
// Default constructor needed for json serialization of SEntry
302296
SCompilerArgs() {}

include/nbl/system/json.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef _NBL_SYSTEM_JSON_H_INCLUDED_
2+
#define _NBL_SYSTEM_JSON_H_INCLUDED_
3+
4+
namespace nbl::system::json {
5+
template<typename T, typename SFINAE = void> struct adl_serializer;
6+
}
7+
8+
#define NBL_JSON_IMPL_BIND_ADL_SERIALIZER(T) \
9+
namespace nlohmann { \
10+
template<> \
11+
struct adl_serializer<typename T::value_t> \
12+
: T {}; \
13+
}
14+
15+
#endif // _NBL_SYSTEM_JSON_H_INCLUDED_

smoke/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ find_package(Nabla REQUIRED CONFIG
2828

2929
add_executable(smoke main.cpp pch.hpp cdb.ps1)
3030
target_link_libraries(smoke PRIVATE Nabla::Nabla)
31+
target_compile_definitions(smoke PRIVATE _AFXDLL)
3132
target_precompile_headers(smoke PRIVATE pch.hpp)
3233

3334
set(CMAKE_CTEST_ARGUMENTS --verbose)

smoke/main.cpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <afxwin.h>
2+
13
#define ENABLE_SMOKE
24

35
using namespace nbl;
@@ -36,45 +38,86 @@ class Smoke final : public system::IApplicationFramework
3638
return false;
3739
}
3840

39-
exportGpuProfiles();
41+
if (!AfxWinInit(GetModuleHandle(nullptr), nullptr, GetCommandLineA(), 0))
42+
{
43+
std::cerr << "[ERROR]: Could not init AFX, terminating!\n";
44+
return false;
45+
}
46+
47+
try {
48+
createAfxDummyWindow(320, 240, nullptr, _T("Dummy 1"));
49+
exportGpuProfiles();
50+
createAfxDummyWindow(320, 240, nullptr, _T("Dummy 2"));
51+
}
52+
catch (const std::exception& e) {
53+
std::cerr << "[ERROR]: " << e.what() << '\n';
54+
return false;
55+
}
56+
catch (...) {
57+
std::cerr << "[ERROR]: Unknown exception!\n";
58+
return false;
59+
}
4060

4161
return true;
4262
}
4363

4464
void workLoopBody() override {}
4565
bool keepRunning() override { return false; }
4666

67+
bool onAppTerminated() override
68+
{
69+
AfxWinTerm();
70+
return true;
71+
}
72+
4773
private:
4874
static void exportGpuProfiles()
4975
{
50-
std::string arg2 = "-o";
51-
std::string buf;
52-
std::string arg1;
53-
std::string arg3;
76+
std::string buf, arg1, arg2 = "-o", arg3;
5477

5578
for (size_t i = 0;; i++)
5679
{
57-
auto stringifiedIndex = std::to_string(i);
58-
arg1 = "--json=" + stringifiedIndex;
59-
arg3 = "device_" + stringifiedIndex + ".json";
60-
std::array<const char*, 3> args = { arg1.data(), arg2.data(), arg3.data() };
80+
auto six = std::to_string(i);
81+
arg1 = "--json=" + six;
82+
arg3 = "device_" + six + ".json";
6183

84+
auto args = std::to_array<const char*>({ arg1.data(), arg2.data(), arg3.data()});
6285
int code = nbl::video::vulkaninfo(args);
6386

6487
if (code != 0)
6588
break;
6689

67-
// print out file content
6890
std::ifstream input(arg3);
6991

7092
while (std::getline(input, buf))
71-
{
7293
std::cout << buf << "\n";
73-
}
7494

7595
std::cout << "\n\n";
7696
}
7797
}
98+
99+
static bool createAfxDummyWindow(int w, int h, HWND parent, LPCTSTR windowName)
100+
{
101+
CWnd wnd;
102+
LPCTSTR cls = AfxRegisterWndClass(0, ::LoadCursor(nullptr, IDC_ARROW));
103+
if (!cls) return false;
104+
105+
if (!wnd.CreateEx(0, cls, windowName, WS_POPUP | WS_VISIBLE, 0, 0, w, h, parent, nullptr))
106+
return false;
107+
108+
MSG msg {};
109+
const ULONGLONG end = GetTickCount64() + 1000;
110+
while (GetTickCount64() < end) {
111+
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
112+
TranslateMessage(&msg);
113+
DispatchMessage(&msg);
114+
}
115+
Sleep(1);
116+
}
117+
118+
wnd.DestroyWindow();
119+
return true;
120+
}
78121
};
79122

80123
NBL_MAIN_FUNC(Smoke)

0 commit comments

Comments
 (0)