Skip to content

Commit 2dfc2e8

Browse files
committed
HLSL-Preprocessor: add newlines after shader_stage pragmas
Signed-off-by: Ali Cheraghi <[email protected]>
1 parent edd7e62 commit 2dfc2e8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <combaseapi.h>
1818
#include <sstream>
1919
#include <dxc/dxcapi.h>
20+
#include <boost/algorithm/string/predicate.hpp>
2021

2122
using namespace nbl;
2223
using namespace nbl::asset;
@@ -328,8 +329,19 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
328329
try
329330
{
330331
std::stringstream stream = std::stringstream();
331-
for (auto i=context.begin(); i!=context.end(); i++)
332+
int32_t emit_nl_after = 0;
333+
for (auto i=context.begin(); i!=context.end(); i++) {
334+
auto value = i->get_value();
332335
stream << i->get_value();
336+
337+
// TODO: replace this hack with `support_option_emit_contnewlines` flag when Boost::Wave respect it
338+
// See also https://github.com/Devsh-Graphics-Programming/Nabla/issues/746
339+
if (emit_nl_after != -1) {
340+
emit_nl_after--;
341+
if (emit_nl_after == 0) stream << "\n";
342+
}
343+
if (boost::ends_with(stream.str(), "#pragma shader_stage(")) emit_nl_after = 2;
344+
}
333345
resolvedString = stream.str();
334346
}
335347
catch (boost::wave::preprocess_exception& e)

0 commit comments

Comments
 (0)