@@ -41,7 +41,7 @@ class ShaderCompiler final : public system::IApplicationFramework
41
41
auto argc = argv.size ();
42
42
43
43
// expect the first argument to be
44
- // nsc .exe
44
+ // .exe
45
45
// second the filename of a shader to compile
46
46
if (argc < 2 ) {
47
47
m_logger->log (" Insufficient arguments." , ILogger::ELL_ERROR);
@@ -76,6 +76,14 @@ class ShaderCompiler final : public system::IApplicationFramework
76
76
}
77
77
}
78
78
}
79
+
80
+ #ifndef NBL_EMBED_BUILTIN_RESOURCES
81
+ if (!no_nbl_builtins) {
82
+ m_system->unmountBuiltins ();
83
+ no_nbl_builtins = true ;
84
+ m_logger->log (" ndt.exe was compiled with builtin resources disabled. Force enabling -no-nbl-builtins." , ILogger::ELL_WARNING);
85
+ }
86
+ #endif
79
87
string shader_code = open_shader_file (file_to_compile);
80
88
auto compilation_result = compile_shader (shader_code, file_to_compile);
81
89
@@ -88,15 +96,7 @@ class ShaderCompiler final : public system::IApplicationFramework
88
96
else {
89
97
m_logger->log (" Shader compilation failed." , ILogger::ELL_ERROR);
90
98
}
91
- /* std::string command = "dxc.exe";
92
- for (std::string arg : arguments)
93
- {
94
- command.append(" ").append(arg);
95
- }
96
99
97
- int execute = std::system(command.c_str());*/
98
-
99
- // std::cout << "-no-nbl-builtins - " << no_nbl_builtins;
100
100
101
101
102
102
return true ;
@@ -116,10 +116,9 @@ class ShaderCompiler final : public system::IApplicationFramework
116
116
const string WorkgroupSizeAsStr = std::to_string (WorkgroupSize);
117
117
const IShaderCompiler::SPreprocessorOptions::SMacroDefinition WorkgroupSizeDefine = { " WORKGROUP_SIZE" ,WorkgroupSizeAsStr };
118
118
119
- smart_refctd_ptr<CHLSLCompiler> hlslcompiler = make_smart_refctd_ptr<CHLSLCompiler>(std::move (m_system));
119
+ smart_refctd_ptr<CHLSLCompiler> hlslcompiler = make_smart_refctd_ptr<CHLSLCompiler>(smart_refctd_ptr (m_system));
120
120
121
121
CHLSLCompiler::SOptions options = {};
122
- options.stage = asset::IShader::E_SHADER_STAGE::ESS_UNKNOWN; // probably not needed, requires guessing -T target profile
123
122
// want as much debug as possible
124
123
options.debugInfoFlags = IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT;
125
124
// this lets you source-level debug/step shaders in renderdoc
@@ -130,18 +129,24 @@ class ShaderCompiler final : public system::IApplicationFramework
130
129
options.preprocessorOptions .logger = m_logger.get ();
131
130
options.preprocessorOptions .extraDefines = { &WorkgroupSizeDefine,&WorkgroupSizeDefine + 1 };
132
131
133
- auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(m_system);
132
+ auto includeFinder = make_smart_refctd_ptr<IShaderCompiler::CIncludeFinder>(smart_refctd_ptr ( m_system) );
134
133
options.preprocessorOptions .includeFinder = includeFinder.get ();
135
134
136
135
std::vector<std::string> dxc_compile_flags_from_pragma = {};
137
- auto preprocessed_shader_code = hlslcompiler->preprocessShader (std::move (shader_code), options.stage , dxc_compile_flags_from_pragma, options.preprocessorOptions );
136
+ auto shaderStage = asset::IShader::E_SHADER_STAGE::ESS_UNKNOWN;
137
+
138
+ auto preprocessed_shader_code = hlslcompiler->preprocessShader (std::move (shader_code), shaderStage, dxc_compile_flags_from_pragma, options.preprocessorOptions );
138
139
140
+
139
141
// override arguments from command line to ones listed in pragma
140
142
if (dxc_compile_flags_from_pragma.size ())
141
143
m_arguments = dxc_compile_flags_from_pragma;
142
144
143
145
add_required_arguments_if_not_present ();
144
146
147
+ if (shaderStage)
148
+ add_shader_stage (shaderStage);
149
+
145
150
// convert string arguments to wstring arguments
146
151
int arg_size = m_arguments.size () - 1 ; // skip input file argument
147
152
LPCWSTR* arguments = new LPCWSTR[arg_size]; // array of pointers
@@ -192,6 +197,46 @@ class ShaderCompiler final : public system::IApplicationFramework
192
197
193
198
}
194
199
200
+ void add_shader_stage (asset::IShader::E_SHADER_STAGE shaderStage) {
201
+ if (std::find (m_arguments.begin (), m_arguments.end (), " -T" ) != m_arguments.end ())
202
+ return ; // Flag is already passed as argument
203
+
204
+ std::string targetProfile (" XX_6_7" );
205
+
206
+ switch (shaderStage)
207
+ {
208
+ case asset::IShader::ESS_VERTEX:
209
+ targetProfile.replace (0 , 2 , " vs" );
210
+ break ;
211
+ case asset::IShader::ESS_TESSELLATION_CONTROL:
212
+ targetProfile.replace (0 , 2 , " ds" );
213
+ break ;
214
+ case asset::IShader::ESS_TESSELLATION_EVALUATION:
215
+ targetProfile.replace (0 , 2 , " hs" );
216
+ break ;
217
+ case asset::IShader::ESS_GEOMETRY:
218
+ targetProfile.replace (0 , 2 , " gs" );
219
+ break ;
220
+ case asset::IShader::ESS_FRAGMENT:
221
+ targetProfile.replace (0 , 2 , " ps" );
222
+ break ;
223
+ case asset::IShader::ESS_COMPUTE:
224
+ targetProfile.replace (0 , 2 , " cs" );
225
+ break ;
226
+ case asset::IShader::ESS_TASK:
227
+ targetProfile.replace (0 , 2 , " as" );
228
+ break ;
229
+ case asset::IShader::ESS_MESH:
230
+ targetProfile.replace (0 , 2 , " ms" );
231
+ break ;
232
+ default :
233
+ m_logger->log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, shaderStage);
234
+ };
235
+ m_arguments.push_back (" -T" );
236
+ m_arguments.push_back (targetProfile);
237
+ m_logger->log (" Shader stage pragma found, adding argument -T " + targetProfile);
238
+ }
239
+
195
240
196
241
std::string open_shader_file (std::string& filepath) {
197
242
std::ifstream stream (filepath);
0 commit comments