@@ -60,22 +60,40 @@ class ShaderCompiler final : public system::IApplicationFramework
6060 {
6161 if (argv[i] == " -no-nbl-builtins" )
6262 {
63+ // unmount builtins
6364 m_logger->log (" Unmounting builtins." );
6465 m_system->unmountBuiltins ();
6566 no_nbl_builtins = true ;
6667 m_arguments.erase (m_arguments.begin () + i - 1 );
6768 }
6869 else if (argv[i] == " -Fo" )
6970 {
71+ // get filepath to save output to
7072 if (i + 1 < argc) {
7173 i++;
7274 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);
7476 }
7577 else {
7678 m_logger->log (" Incorrect arguments. Expecting filename after -Fo." , ILogger::ELL_ERROR);
7779 }
7880 }
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+
7997 }
8098
8199#ifndef NBL_EMBED_BUILTIN_RESOURCES
@@ -134,9 +152,9 @@ class ShaderCompiler final : public system::IApplicationFramework
134152 options.preprocessorOptions .includeFinder = includeFinder.get ();
135153
136154 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;
138156
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 );
140158
141159
142160 // override arguments from command line to ones listed in pragma
@@ -145,8 +163,8 @@ class ShaderCompiler final : public system::IApplicationFramework
145163
146164 add_required_arguments_if_not_present ();
147165
148- if (shaderStage )
149- add_shader_stage (shaderStage );
166+ if (! try_upgrade_shader_stage () && shaderStageOverride )
167+ add_shader_stage (shaderStageOverride );
150168
151169 // convert string arguments to wstring arguments
152170 int arg_size = m_arguments.size () - 1 ; // skip input file argument
@@ -198,9 +216,30 @@ class ShaderCompiler final : public system::IApplicationFramework
198216
199217 }
200218
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+
201242 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
204243
205244 std::string targetProfile (" XX_6_7" );
206245
0 commit comments