@@ -54,12 +54,12 @@ CHLSLCompiler::~CHLSLCompiler()
54
54
}
55
55
56
56
static 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>
63
63
uint32_t lexerLineIndex,
64
64
uint32_t leadingLinesImports,
65
65
std::vector<std::pair<uint32_t , std::string>>& includeStack
@@ -68,25 +68,25 @@ static tcpp::IInputStream* getInputStreamInclude(
68
68
std::string res_str;
69
69
70
70
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 );
73
73
if (!reqFromBuiltin && !reqBuiltin)
74
74
{
75
75
// While #includ'ing a builtin, one must specify its full path (starting with "nbl/builtin" or "/nbl/builtin").
76
76
// This rule applies also while a builtin is #includ`ing another builtin.
77
77
// While including a filesystem file it must be either absolute path (or relative to any search dir added to asset::iIncludeHandler; <>-type),
78
78
// 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 ();
80
80
}
81
- std::filesystem::path name = _type ? (relDir / _requested_source ) : (_requested_source );
81
+ std::filesystem::path name = isRelative ? (relDir / requestedSource ) : (requestedSource );
82
82
83
83
if (std::filesystem::exists (name) && !reqBuiltin)
84
84
name = std::filesystem::absolute (name);
85
85
86
- if (_type )
87
- res_str = _inclFinder ->getIncludeRelative (relDir, _requested_source );
86
+ if (isRelative )
87
+ res_str = inclFinder ->getIncludeRelative (relDir, requestedSource );
88
88
else // shaderc_include_type_standard
89
- res_str = _inclFinder ->getIncludeStandard (relDir, _requested_source );
89
+ res_str = inclFinder ->getIncludeStandard (relDir, requestedSource );
90
90
91
91
if (!res_str.size ()) {
92
92
return new tcpp::StringInputStream (" #error File not found" );
@@ -100,11 +100,11 @@ static tcpp::IInputStream* getInputStreamInclude(
100
100
(includeStack.size () > 1 ? leadingLinesImports : 0 );
101
101
102
102
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 ());
104
104
res_str = res_str + " \n " +
105
105
IShaderCompiler::PREPROC_DIRECTIVE_DISABLER + " line " + std::to_string (lineGoBackTo) + " \" " + includeStack.back ().second + " \"\n " ;
106
106
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
108
108
std::string identifier = name.string ().c_str ();
109
109
std::replace (identifier.begin (), identifier.end (), ' \\ ' , ' /' );
110
110
@@ -199,10 +199,8 @@ DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::hlsl:
199
199
200
200
std::string CHLSLCompiler::preprocessShader (std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
201
201
{
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 " ));
206
204
207
205
uint32_t defineLeadingLinesMain = 0 ;
208
206
uint32_t leadingLinesImports = IShaderCompiler::encloseWithinExtraInclGuardsLeadingLines (preprocessOptions.maxSelfInclusionCount + 1u );
@@ -285,7 +283,6 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
285
283
auto resolvedString = proc.Process ();
286
284
IShaderCompiler::reenableDirectives (resolvedString);
287
285
288
- printf (" Resolved string:\n\n %s\n " , resolvedString.c_str ());
289
286
return resolvedString;
290
287
}
291
288
0 commit comments