|
17 | 17 | #include <combaseapi.h>
|
18 | 18 | #include <sstream>
|
19 | 19 | #include <dxc/dxcapi.h>
|
| 20 | +#include <boost/algorithm/string/predicate.hpp> |
| 21 | +#include <boost/algorithm/string/trim.hpp> |
20 | 22 |
|
21 | 23 | using namespace nbl;
|
22 | 24 | using namespace nbl::asset;
|
@@ -311,6 +313,19 @@ static DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset
|
311 | 313 |
|
312 | 314 | std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions, std::vector<std::string>& dxc_compile_flags_override, std::vector<CCache::SEntry::SPreprocessingDependency>* dependencies) const
|
313 | 315 | {
|
| 316 | + // HACK: we do a pre-pre-process here to add \n after every #pragma to neutralize boost::wave's actions |
| 317 | + // See https://github.com/Devsh-Graphics-Programming/Nabla/issues/746 |
| 318 | + size_t line_index = 0; |
| 319 | + for (size_t i = 0; i < code.size(); i++) { |
| 320 | + if (code[i] == '\n') { |
| 321 | + auto line = code.substr(line_index, i - line_index); |
| 322 | + boost::trim(line); |
| 323 | + if (boost::starts_with(line, "#pragma")) |
| 324 | + code.insert(i++, 1, '\n'); |
| 325 | + line_index = i; |
| 326 | + } |
| 327 | + } |
| 328 | + |
314 | 329 | nbl::wave::context context(code.begin(),code.end(),preprocessOptions.sourceIdentifier.data(),{preprocessOptions});
|
315 | 330 | // If dependencies were passed, we assume we want caching
|
316 | 331 | context.set_caching(bool(dependencies));
|
@@ -385,6 +400,7 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV_impl(const std:
|
385 | 400 | std::vector<std::string> dxc_compile_flags = {};
|
386 | 401 | IShader::E_SHADER_STAGE stage = options.stage;
|
387 | 402 | auto newCode = preprocessShader(std::string(code), stage, hlslOptions.preprocessorOptions, dxc_compile_flags, dependencies);
|
| 403 | + if (newCode.empty()) return nullptr; |
388 | 404 |
|
389 | 405 | // Suffix is the shader model version
|
390 | 406 | std::wstring targetProfile(SHADER_MODEL_PROFILE);
|
|
0 commit comments