Skip to content

Commit aecf0f3

Browse files
committed
added variadics support and extra defines to preprocessor
1 parent a7b71f8 commit aecf0f3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

include/nbl/video/ILogicalDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
572572
const ptrdiff_t pos = pool.tellp();
573573
m_extraShaderDefines.push_back(reinterpret_cast<const char*>(pos));
574574
pool << define << " ";
575-
((pool << std::forward<Args>(args)), ...);
575+
((pool << (std::is_same<uint8_t, Args>::value ? static_cast<uint32_t>(std::forward<Args>(args)) : std::forward<Args>(args))), ...);
576576
}
577577
inline void finalizeShaderDefinePool(std::ostringstream&& pool)
578578
{

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#include <boost/wave/cpplexer/cpp_lex_token.hpp>
2626
#include <boost/wave/cpplexer/cpp_lex_iterator.hpp>
2727

28-
//#define TCPP_IMPLEMENTATION
29-
//#include <tcpp/source/tcppLibrary.hpp>
30-
//#undef TCPP_IMPLEMENTATION
31-
3228
using namespace nbl;
3329
using namespace nbl::asset;
3430
using Microsoft::WRL::ComPtr;
@@ -332,14 +328,23 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
332328
hlsl::impl::custom_preprocessing_hooks hooks(preprocessOptions, stage);
333329
std::string startingFileIdentifier = std::string("../") + preprocessOptions.sourceIdentifier.data();
334330
wave_context_t context(code.begin(), code.end(), startingFileIdentifier.data(), hooks);
335-
331+
context.set_language(boost::wave::support_cpp20);
332+
context.add_macro_definition("__HLSL_VERSION");
336333
//TODO fix bad syntax and uncomment
337334
// instead of defining extraDefines as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D 32768",
338335
// now define them as "NBL_GLSL_LIMIT_MAX_IMAGE_DIMENSION_1D=32768"
339336
// to match boost wave syntax
340337
// https://www.boost.org/doc/libs/1_82_0/libs/wave/doc/class_reference_context.html#:~:text=Maintain%20defined%20macros-,add_macro_definition,-bool%20add_macro_definition
341-
/* for (auto iter = preprocessOptions.extraDefines.begin(); iter != preprocessOptions.extraDefines.end(); iter++)
342-
context.add_macro_definition(*iter); */
338+
for (auto iter = preprocessOptions.extraDefines.begin(); iter != preprocessOptions.extraDefines.end(); iter++)
339+
{
340+
std::string s = *iter;
341+
size_t firstParenthesis = s.find(')');
342+
if (firstParenthesis == -1) firstParenthesis = 0;
343+
size_t firstWhitespace = s.find(' ', firstParenthesis);
344+
if (firstWhitespace != -1)
345+
s[firstWhitespace] = '=';
346+
context.add_macro_definition(s);
347+
}
343348

344349
// preprocess
345350
std::stringstream stream = std::stringstream();

0 commit comments

Comments
 (0)