Skip to content

Commit 2d27211

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 7cd4b73 + 41df49e commit 2d27211

File tree

8 files changed

+133
-52
lines changed

8 files changed

+133
-52
lines changed

examples_tests

Submodule examples_tests updated 105 files

include/nbl/builtin/hlsl/limits.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ struct numeric_limits : impl::numeric_limits<T> {};
262262

263263

264264
template<class T>
265-
struct numeric_limits : std::numeric_limits<T>
265+
struct numeric_limits : std::conditional_t<std::is_same_v<T,float16_t>,IMATH_INTERNAL_NAMESPACE::limits<T>,std::numeric_limits<T>>
266266
{
267-
using base = std::numeric_limits<T>;
267+
using base = std::conditional_t<std::is_same_v<T,float16_t>,IMATH_INTERNAL_NAMESPACE::limits<T>,std::numeric_limits<T>>;
268268
using uint_type = std::remove_cvref_t<decltype(impl::num_traits<T>::infinity)>;
269269

270270
NBL_CONSTEXPR_STATIC_INLINE T min = base::min();

include/nbl/system/CApplicationAndroid.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "nbl/system/IApplicationFramework.h"
77
#include "nbl/system/CStdoutLoggerAndroid.h"
88

9+
// TODO: move to .cpp file
910
#ifdef _NBL_PLATFORM_ANDROID_
1011
#include <android_native_app_glue.h>
1112
#include <android/sensor.h>
@@ -15,7 +16,7 @@
1516
namespace nbl::system
1617
{
1718
#ifdef _NBL_PLATFORM_ANDROID_
18-
19+
// TODO: fill rewrite of this thing, also rename to `IApplicationAndroid`
1920
class CApplicationAndroid : public IApplicationFramework
2021
{
2122
public:
@@ -140,6 +141,11 @@ class CApplicationAndroid : public IApplicationFramework
140141
bool keepPolling() const { return eventPoller.continuePredicate(); }
141142
};
142143

144+
#define NBL_MAIN_FUNC(AppClass, ...) void android_main(android_app* app) \
145+
{\
146+
nbl::system::IApplicationFramework::main<AppClass>(app __VA_OPT__(,) __VA_ARGS__);\
147+
}
148+
143149
#endif
144150
}
145151

include/nbl/system/CColoredStdoutLoggerANSI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace nbl::system
99
{
1010

1111
// logging using ANSI escape codes
12-
class NBL_API2 CColoredStdoutLoggerANSI : public IThreadsafeLogger
12+
class CColoredStdoutLoggerANSI : public IThreadsafeLogger
1313
{
1414
public:
15-
CColoredStdoutLoggerANSI(core::bitflag<E_LOG_LEVEL> logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask) {}
15+
inline CColoredStdoutLoggerANSI(core::bitflag<E_LOG_LEVEL> logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask) {}
1616

1717
private:
1818
// more info about how this works: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

include/nbl/system/IApplicationFramework.h

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,29 @@
77
#include "nbl/system/declarations.h"
88
#include "nbl/system/definitions.h"
99

10+
#if defined(_NBL_PLATFORM_WINDOWS_)
11+
#include "nbl/system/CColoredStdoutLoggerWin32.h"
12+
#elif defined(_NBL_PLATFORM_ANDROID_)
13+
#include "nbl/system/CStdoutLoggerAndroid.h"
14+
#endif
15+
#include "nbl/system/CSystemAndroid.h"
16+
#include "nbl/system/CSystemLinux.h"
17+
#include "nbl/system/CSystemWin32.h"
1018

1119
namespace nbl::system
1220
{
1321

14-
class IApplicationFramework
22+
class IApplicationFramework : public core::IReferenceCounted
1523
{
1624
public:
25+
// this is safe to call multiple times
1726
static void GlobalsInit()
1827
{
1928
#ifdef _NBL_PLATFORM_WINDOWS_
2029
#ifdef NBL_CPACK_PACKAGE_DXC_DLL_DIR
21-
const HRESULT dxcLoad = CSystemWin32::delayLoadDLL("dxcompiler.dll", { system::path(_DXC_DLL_).parent_path(), NBL_CPACK_PACKAGE_DXC_DLL_DIR });
30+
const HRESULT dxcLoad = CSystemWin32::delayLoadDLL("dxcompiler.dll", { path(_DXC_DLL_).parent_path(), NBL_CPACK_PACKAGE_DXC_DLL_DIR });
2231
#else
23-
const HRESULT dxcLoad = CSystemWin32::delayLoadDLL("dxcompiler.dll", { system::path(_DXC_DLL_).parent_path() });
32+
const HRESULT dxcLoad = CSystemWin32::delayLoadDLL("dxcompiler.dll", { path(_DXC_DLL_).parent_path() });
2433
#endif
2534

2635
//assert(SUCCEEDED(dxcLoad)); // no clue why this fails to find the dll
@@ -43,39 +52,63 @@ class IApplicationFramework
4352
#endif
4453
}
4554

55+
// we take the derived class as Curiously Recurring Template Parameter
56+
template<class CRTP> requires std::is_base_of_v<IApplicationFramework,CRTP>
57+
static int main(int argc, char** argv)
58+
{
59+
path CWD = system::path(argv[0]).parent_path().generic_string() + "/";
60+
auto app = core::make_smart_refctd_ptr<CRTP>(CWD/"../../media/",CWD/"../../tmp/",CWD/"../",CWD);
61+
for (auto i=0; i<argc; i++)
62+
app->argv.emplace_back(argv[i]);
63+
64+
if (!app->onAppInitialized(nullptr))
65+
return -1;
66+
while (app->keepRunning())
67+
app->workLoopBody();
68+
return app->onAppTerminated() ? 0:(-2);
69+
}
70+
71+
static nbl::core::smart_refctd_ptr<ISystem> createSystem()
72+
{
73+
GlobalsInit();
74+
#ifdef _NBL_PLATFORM_WINDOWS_
75+
return nbl::core::make_smart_refctd_ptr<CSystemWin32>();
76+
#elif defined(_NBL_PLATFORM_ANDROID_)
77+
return nullptr;
78+
#endif
79+
return nullptr;
80+
}
81+
4682
IApplicationFramework(
47-
const system::path& _localInputCWD,
48-
const system::path& _localOutputCWD,
49-
const system::path& _sharedInputCWD,
50-
const system::path& _sharedOutputCWD) :
83+
const path& _localInputCWD,
84+
const path& _localOutputCWD,
85+
const path& _sharedInputCWD,
86+
const path& _sharedOutputCWD) :
5187
localInputCWD(_localInputCWD), localOutputCWD(_localOutputCWD), sharedInputCWD(_sharedInputCWD), sharedOutputCWD(_sharedOutputCWD)
5288
{
5389
GlobalsInit();
5490
}
5591

56-
virtual void setSystem(core::smart_refctd_ptr<nbl::system::ISystem>&& system) = 0;
92+
// DEPRECATED
93+
virtual void setSystem(core::smart_refctd_ptr<ISystem>&& system) {}
5794

58-
void onAppInitialized()
59-
{
60-
return onAppInitialized_impl();
61-
}
62-
void onAppTerminated()
63-
{
64-
return onAppTerminated_impl();
65-
}
95+
// Some platforms are weird, and you can't really do anything with the system unless you have some magical object that gets passed to the platform's entry point.
96+
// Therefore the specific `CPLATFORMSystem` is uncreatable out of thin air so you need to take an outside provided one
97+
virtual bool onAppInitialized(core::smart_refctd_ptr<ISystem>&& system=nullptr) {onAppInitialized_impl(std::move(system)); return true;}
98+
virtual bool onAppTerminated() {return true;}
6699

67100
virtual void workLoopBody() = 0;
68101
virtual bool keepRunning() = 0;
69102

70-
// TODO: refactor/hide
71-
std::vector<std::string> argv;
72-
73103
protected:
74104
~IApplicationFramework() {}
75105

76-
// TODO: why aren't these pure virtual, and why do we even need a `_impl()`suffix?
77-
virtual void onAppInitialized_impl() {}
78-
virtual void onAppTerminated_impl() {}
106+
// DEPRECATED
107+
virtual void onAppInitialized_impl(core::smart_refctd_ptr<ISystem>&& system) {assert(false);}
108+
virtual void onAppTerminated_impl() {assert(false);}
109+
110+
// for platforms with cmdline args
111+
core::vector<std::string> argv;
79112

80113
/*
81114
****************** Current Working Directories ********************
@@ -90,24 +123,34 @@ class IApplicationFramework
90123
91124
To add files to your assets directory, create an "assets" directory in your app's source directory
92125
*/
93-
system::path localInputCWD;
126+
path localInputCWD;
94127

95128
/*
96129
This is a CWD used to output app-local data e.g. screenshots
97130
*/
98-
system::path localOutputCWD;
131+
path localOutputCWD;
99132

100133
/*
101134
The CWD for input data that can be shared among apps, like the "examples_tests/media" directory for Nabla examples
102135
*/
103-
system::path sharedInputCWD;
136+
path sharedInputCWD;
104137

105138
/*
106139
This CWD is used to output data that can be shared between apps e.g. quantization cache
107140
*/
108-
system::path sharedOutputCWD;
141+
path sharedOutputCWD;
109142
};
110143

111144
}
112145

146+
// get the correct entry point to declate
147+
#ifdef _NBL_PLATFORM_ANDROID_
148+
#include "nbl/system/CApplicationAndroid.h"
149+
#else
150+
#define NBL_MAIN_FUNC(AppClass) int main(int argc, char** argv) \
151+
{\
152+
return AppClass::main<AppClass>(argc,argv);\
153+
}
154+
#endif
155+
113156
#endif

include/nbl/system/IAsyncQueueDispatcher.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,34 @@ class IAsyncQueueDispatcherBase
232232
}
233233

234234
//!
235-
inline explicit operator bool()
235+
inline explicit operator bool() const
236236
{
237237
return m_future;
238238
}
239-
inline bool operator!()
239+
inline bool operator!() const
240240
{
241241
return !m_future;
242242
}
243243

244244
//!
245-
inline T* operator->() const
245+
inline const T* operator->() const
246246
{
247247
if (m_future)
248248
return m_future->getStorage();
249249
return nullptr;
250250
}
251+
inline T* operator->()
252+
{
253+
if (m_future)
254+
return m_future->getStorage();
255+
return nullptr;
256+
}
257+
258+
//!
259+
template<typename U=T> requires (std::is_same_v<U,T> && !std::is_void_v<U>)
260+
inline const U& operator*() const {return *operator->();}
251261
template<typename U=T> requires (std::is_same_v<U,T> && !std::is_void_v<U>)
252-
inline U& operator*() const {return *operator->();}
262+
inline U& operator*() {return *operator->();}
253263

254264
//! Can only be called once!
255265
inline void discard()

include/nbl/system/IThreadsafeLogger.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ namespace nbl::system
99
{
1010
class IThreadsafeLogger : public ILogger
1111
{
12-
mutable std::mutex m_mutex;
13-
public:
14-
IThreadsafeLogger(core::bitflag<E_LOG_LEVEL> logLevelMask) : ILogger(logLevelMask) {}
15-
// Inherited via ILogger
16-
void log_impl(const std::string_view& fmtString, E_LOG_LEVEL logLevel, va_list args) override final
17-
{
18-
auto l = lock();
19-
threadsafeLog_impl(fmtString, logLevel, args);
20-
}
21-
private:
22-
virtual void threadsafeLog_impl(const std::string_view&, E_LOG_LEVEL logLevel, va_list args) = 0;
12+
mutable std::mutex m_mutex;
13+
public:
14+
inline IThreadsafeLogger(core::bitflag<E_LOG_LEVEL> logLevelMask) : ILogger(logLevelMask) {}
15+
// Inherited via ILogger
16+
inline void log_impl(const std::string_view& fmtString, E_LOG_LEVEL logLevel, va_list args) override final
17+
{
18+
auto l = lock();
19+
threadsafeLog_impl(fmtString, logLevel, args);
20+
}
21+
private:
22+
virtual void threadsafeLog_impl(const std::string_view&, E_LOG_LEVEL logLevel, va_list args) = 0;
2323

24-
std::unique_lock<std::mutex> lock() const
25-
{
26-
return std::unique_lock<std::mutex>(m_mutex);
27-
}
24+
inline std::unique_lock<std::mutex> lock() const
25+
{
26+
return std::unique_lock<std::mutex>(m_mutex);
27+
}
2828

2929
};
3030
}

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include <iterator>
2222
#include <codecvt>
2323

24+
#include <boost/wave.hpp>
25+
#include <boost/wave/cpplexer/cpp_lex_token.hpp>
26+
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
27+
2428
#define TCPP_IMPLEMENTATION
2529
#include <tcpp/source/tcppLibrary.hpp>
2630
#undef TCPP_IMPLEMENTATION
@@ -225,6 +229,24 @@ DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::hlsl:
225229

226230
std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
227231
{
232+
using lex_token_t = boost::wave::cpplexer::lex_token<>;
233+
using lex_iterator_t = boost::wave::cpplexer::lex_iterator<lex_token_t>;
234+
using wave_context_t = boost::wave::context<
235+
core::string::iterator,
236+
lex_iterator_t,
237+
boost::wave::iteration_context_policies::load_file_to_string/*,
238+
TODO: OurCustomDirectiveHooks -> for pragmas and includes!
239+
*/
240+
>;
241+
242+
// TODO: change `code` to `const core::string&` because its supposed to be immutable
243+
wave_context_t context(code.begin(),code.end(),preprocessOptions.sourceIdentifier.data()/*,TODO: instance of OurCustomDirectiveHooks*/);
244+
// context.add_include_path
245+
// context.add_sysinclude_path <- for dem builtins! / preprocessOptions.includeFinder?
246+
// context.add_macro_definition from preprocessOptions.extraDefines
247+
core::string resolvedString;
248+
// TODO: fill `resolvedString` with `[context.begin(),context.end()]`
249+
228250
// Line 1 comes before all the extra defines in the main shader
229251
insertIntoStart(code, std::ostringstream(std::string(IShaderCompiler::PREPROC_DIRECTIVE_ENABLER) + "line 1\n"));
230252

@@ -309,7 +331,7 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
309331
return std::string("");
310332
});
311333

312-
auto resolvedString = proc.Process();
334+
resolvedString = proc.Process();
313335
IShaderCompiler::reenableDirectives(resolvedString);
314336

315337
// for debugging cause MSVC doesn't like to show more than 21k LoC in TextVisualizer

0 commit comments

Comments
 (0)