@@ -60,22 +60,40 @@ class ShaderCompiler final : public system::IApplicationFramework
60
60
{
61
61
if (argv[i] == " -no-nbl-builtins" )
62
62
{
63
+ // unmount builtins
63
64
m_logger->log (" Unmounting builtins." );
64
65
m_system->unmountBuiltins ();
65
66
no_nbl_builtins = true ;
66
67
m_arguments.erase (m_arguments.begin () + i - 1 );
67
68
}
68
69
else if (argv[i] == " -Fo" )
69
70
{
71
+ // get filepath to save output to
70
72
if (i + 1 < argc) {
71
73
i++;
72
74
output_filepath = argv[i];
73
- m_logger->log (" Saving compiled shader code to " + output_filepath);
75
+ m_logger->log (" Compiled shader code will be saved to " + output_filepath);
74
76
}
75
77
else {
76
78
m_logger->log (" Incorrect arguments. Expecting filename after -Fo." , ILogger::ELL_ERROR);
77
79
}
78
80
}
81
+ else if (argv[i] == " -HV" )
82
+ {
83
+ // find the -HV parameter and upgrade it to 2021 if below 2021 and not equal to 202x
84
+ if (i + 1 < argc) {
85
+ i++;
86
+ auto version = argv[i];
87
+ if (version.length () >= 4 && (version[2 ] < ' 2' || (version[2 ] == ' 2' && version[3 ] <= ' 0' ))) {
88
+ m_logger->log (" -HV " + version + " is lower than minimal required by Nabla. Forcibly setting the parameter to -HV 2021" , ILogger::ELL_WARNING);
89
+ argv[i] = " 2021" ;
90
+ }
91
+ }
92
+ else {
93
+ m_logger->log (" Incorrect arguments. Expecting version after -HV." , ILogger::ELL_ERROR);
94
+ }
95
+ }
96
+
79
97
}
80
98
81
99
#ifndef NBL_EMBED_BUILTIN_RESOURCES
@@ -134,9 +152,9 @@ class ShaderCompiler final : public system::IApplicationFramework
134
152
options.preprocessorOptions .includeFinder = includeFinder.get ();
135
153
136
154
std::vector<std::string> dxc_compile_flags_from_pragma = {};
137
- auto shaderStage = asset::IShader::E_SHADER_STAGE::ESS_UNKNOWN;
155
+ auto shaderStageOverride = asset::IShader::E_SHADER_STAGE::ESS_UNKNOWN;
138
156
139
- auto preprocessed_shader_code = hlslcompiler->preprocessShader (std::move (shader_code), shaderStage , dxc_compile_flags_from_pragma, options.preprocessorOptions );
157
+ auto preprocessed_shader_code = hlslcompiler->preprocessShader (std::move (shader_code), shaderStageOverride , dxc_compile_flags_from_pragma, options.preprocessorOptions );
140
158
141
159
142
160
// override arguments from command line to ones listed in pragma
@@ -145,8 +163,8 @@ class ShaderCompiler final : public system::IApplicationFramework
145
163
146
164
add_required_arguments_if_not_present ();
147
165
148
- if (shaderStage )
149
- add_shader_stage (shaderStage );
166
+ if (! try_upgrade_shader_stage () && shaderStageOverride )
167
+ add_shader_stage (shaderStageOverride );
150
168
151
169
// convert string arguments to wstring arguments
152
170
int arg_size = m_arguments.size () - 1 ; // skip input file argument
@@ -198,9 +216,30 @@ class ShaderCompiler final : public system::IApplicationFramework
198
216
199
217
}
200
218
219
+ // returns false if shader stage is not present in arguments
220
+ // returns true otherwise, and upgrades to 6.7 if needed
221
+ bool try_upgrade_shader_stage () {
222
+
223
+ auto foundShaderStageArgument = std::find (m_arguments.begin (), m_arguments.end (), " -T" );
224
+ if (foundShaderStageArgument != m_arguments.end ()) {
225
+ auto foundShaderStageArgumentValueIdx = foundShaderStageArgument - m_arguments.begin () + 1 ;
226
+ std::string targetProfile = m_arguments[foundShaderStageArgumentValueIdx];
227
+ if (targetProfile.length () >= 6 ) {
228
+ int version = (targetProfile[3 ] - ' 0' ) * 10 + (targetProfile[5 ] - ' 0' );
229
+ if (version < 67 )
230
+ {
231
+ m_logger->log (" -T %s is lower than required by Nabla. Forcibly setting it to version 6.7" , ILogger::ELL_WARNING, targetProfile);
232
+ targetProfile.replace (3 , 3 , " 6_7" );
233
+ m_arguments[foundShaderStageArgumentValueIdx] = targetProfile;
234
+ }
235
+ }
236
+ return true ;
237
+ }
238
+ return false ;
239
+ }
240
+
241
+
201
242
void add_shader_stage (asset::IShader::E_SHADER_STAGE shaderStage) {
202
- if (std::find (m_arguments.begin (), m_arguments.end (), " -T" ) != m_arguments.end ())
203
- return ; // Flag is already passed as argument
204
243
205
244
std::string targetProfile (" XX_6_7" );
206
245
0 commit comments