@@ -54,12 +54,12 @@ CHLSLCompiler::~CHLSLCompiler()
5454}
5555
5656static tcpp::IInputStream* getInputStreamInclude (
57- const IShaderCompiler::CIncludeFinder* _inclFinder ,
58- const system::ISystem* _fs ,
59- uint32_t _maxInclCnt ,
60- const char * _requesting_source ,
61- const char * _requested_source ,
62- bool _type , // true for #include "string"; false for #include <string>
57+ const IShaderCompiler::CIncludeFinder* inclFinder ,
58+ const system::ISystem* fs ,
59+ uint32_t maxInclCnt ,
60+ const char * requestingSource ,
61+ const char * requestedSource ,
62+ bool isRelative , // true for #include "string"; false for #include <string>
6363 uint32_t lexerLineIndex,
6464 uint32_t leadingLinesImports,
6565 std::vector<std::pair<uint32_t , std::string>>& includeStack
@@ -68,25 +68,25 @@ static tcpp::IInputStream* getInputStreamInclude(
6868 std::string res_str;
6969
7070 std::filesystem::path relDir;
71- const bool reqFromBuiltin = builtin::hasPathPrefix (_requesting_source );
72- const bool reqBuiltin = builtin::hasPathPrefix (_requested_source );
71+ const bool reqFromBuiltin = builtin::hasPathPrefix (requestingSource );
72+ const bool reqBuiltin = builtin::hasPathPrefix (requestedSource );
7373 if (!reqFromBuiltin && !reqBuiltin)
7474 {
7575 // While #includ'ing a builtin, one must specify its full path (starting with "nbl/builtin" or "/nbl/builtin").
7676 // This rule applies also while a builtin is #includ`ing another builtin.
7777 // While including a filesystem file it must be either absolute path (or relative to any search dir added to asset::iIncludeHandler; <>-type),
7878 // or path relative to executable's working directory (""-type).
79- relDir = std::filesystem::path (_requesting_source ).parent_path ();
79+ relDir = std::filesystem::path (requestingSource ).parent_path ();
8080 }
81- std::filesystem::path name = _type ? (relDir / _requested_source ) : (_requested_source );
81+ std::filesystem::path name = isRelative ? (relDir / requestedSource ) : (requestedSource );
8282
8383 if (std::filesystem::exists (name) && !reqBuiltin)
8484 name = std::filesystem::absolute (name);
8585
86- if (_type )
87- res_str = _inclFinder ->getIncludeRelative (relDir, _requested_source );
86+ if (isRelative )
87+ res_str = inclFinder ->getIncludeRelative (relDir, requestedSource );
8888 else // shaderc_include_type_standard
89- res_str = _inclFinder ->getIncludeStandard (relDir, _requested_source );
89+ res_str = inclFinder ->getIncludeStandard (relDir, requestedSource );
9090
9191 if (!res_str.size ()) {
9292 return new tcpp::StringInputStream (" #error File not found" );
@@ -100,11 +100,11 @@ static tcpp::IInputStream* getInputStreamInclude(
100100 (includeStack.size () > 1 ? leadingLinesImports : 0 );
101101
102102 IShaderCompiler::disableAllDirectivesExceptIncludes (res_str);
103- res_str = IShaderCompiler::encloseWithinExtraInclGuards (std::move (res_str), _maxInclCnt , name.string ().c_str ());
103+ res_str = IShaderCompiler::encloseWithinExtraInclGuards (std::move (res_str), maxInclCnt , name.string ().c_str ());
104104 res_str = res_str + " \n " +
105105 IShaderCompiler::PREPROC_DIRECTIVE_DISABLER + " line " + std::to_string (lineGoBackTo) + " \" " + includeStack.back ().second + " \"\n " ;
106106
107- // HACK: tcpp is having issues parsing the string, so this is a hack/mitigation that could be removed once tcpp is fixed
107+ // avoid warnings about improperly escaping
108108 std::string identifier = name.string ().c_str ();
109109 std::replace (identifier.begin (), identifier.end (), ' \\ ' , ' /' );
110110
@@ -199,10 +199,8 @@ DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::hlsl:
199199
200200std::string CHLSLCompiler::preprocessShader (std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
201201{
202- std::ostringstream insertion;
203- insertion << IShaderCompiler::PREPROC_DIRECTIVE_ENABLER;
204- insertion << " line 1\n " ;
205- insertIntoStart (code, std::move (insertion));
202+ // Line 1 comes before all the extra defines in the main shader
203+ insertIntoStart (code, std::ostringstream (std::string (IShaderCompiler::PREPROC_DIRECTIVE_ENABLER) + " line 1\n " ));
206204
207205 uint32_t defineLeadingLinesMain = 0 ;
208206 uint32_t leadingLinesImports = IShaderCompiler::encloseWithinExtraInclGuardsLeadingLines (preprocessOptions.maxSelfInclusionCount + 1u );
@@ -285,7 +283,6 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
285283 auto resolvedString = proc.Process ();
286284 IShaderCompiler::reenableDirectives (resolvedString);
287285
288- printf (" Resolved string:\n\n %s\n " , resolvedString.c_str ());
289286 return resolvedString;
290287}
291288
0 commit comments