@@ -149,7 +149,8 @@ DxcCompilationResult dxcCompile(const CHLSLCompiler* compiler, nbl::asset::impl:
149
149
150
150
#include " nbl/asset/utils/waveContext.h"
151
151
152
- std::string CHLSLCompiler::preprocessShader (std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
152
+
153
+ std::string CHLSLCompiler::preprocessShader (std::string&& code, IShader::E_SHADER_STAGE& stage, std::vector<std::string>& dxc_compile_flags_override, const SPreprocessorOptions& preprocessOptions) const
153
154
{
154
155
nbl::wave::context context (code.begin (),code.end (),preprocessOptions.sourceIdentifier .data (),{preprocessOptions});
155
156
context.add_macro_definition (" __HLSL_VERSION" );
@@ -192,12 +193,22 @@ std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
192
193
}
193
194
}
194
195
196
+ if (context.get_hooks ().m_dxc_compile_flags_override .size () != 0 )
197
+ dxc_compile_flags_override = context.get_hooks ().m_dxc_compile_flags_override ;
198
+
195
199
if (context.get_hooks ().m_pragmaStage != IShader::ESS_UNKNOWN)
196
200
stage = context.get_hooks ().m_pragmaStage ;
197
201
202
+
203
+
198
204
return resolvedString;
199
205
}
200
206
207
+ // std::string CHLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADER_STAGE& stage, const SPreprocessorOptions& preprocessOptions) const
208
+ // {
209
+ // std::vector<LPCWSTR> extra_dxc_compile_flags = {};
210
+ // return preprocessShader(code, stage, extra_dxc_compile_flags, preprocessOptions);
211
+ // }
201
212
202
213
core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV (const char * code, const IShaderCompiler::SCompilerOptions& options) const
203
214
{
@@ -208,9 +219,9 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
208
219
hlslOptions.preprocessorOptions .logger .log (" code is nullptr" , system::ILogger::ELL_ERROR);
209
220
return nullptr ;
210
221
}
211
-
222
+ std::vector<std::string> dxc_compile_flags = {};
212
223
auto stage = hlslOptions.stage ;
213
- auto newCode = preprocessShader (code, stage, hlslOptions.preprocessorOptions );
224
+ auto newCode = preprocessShader (code, stage, dxc_compile_flags, hlslOptions.preprocessorOptions );
214
225
215
226
// Suffix is the shader model version
216
227
// TODO: Figure out a way to get the shader model version automatically
@@ -227,36 +238,44 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
227
238
// Set profile two letter prefix based on stage
228
239
switch (stage)
229
240
{
230
- case asset::IShader::ESS_VERTEX:
231
- targetProfile.replace (0 , 2 , L" vs" );
232
- break ;
233
- case asset::IShader::ESS_TESSELLATION_CONTROL:
234
- targetProfile.replace (0 , 2 , L" ds" );
235
- break ;
236
- case asset::IShader::ESS_TESSELLATION_EVALUATION:
237
- targetProfile.replace (0 , 2 , L" hs" );
238
- break ;
239
- case asset::IShader::ESS_GEOMETRY:
240
- targetProfile.replace (0 , 2 , L" gs" );
241
- break ;
242
- case asset::IShader::ESS_FRAGMENT:
243
- targetProfile.replace (0 , 2 , L" ps" );
244
- break ;
245
- case asset::IShader::ESS_COMPUTE:
246
- targetProfile.replace (0 , 2 , L" cs" );
247
- break ;
248
- case asset::IShader::ESS_TASK:
249
- targetProfile.replace (0 , 2 , L" as" );
250
- break ;
251
- case asset::IShader::ESS_MESH:
252
- targetProfile.replace (0 , 2 , L" ms" );
253
- break ;
254
- default :
255
- hlslOptions.preprocessorOptions .logger .log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
256
- return nullptr ;
241
+ case asset::IShader::ESS_VERTEX:
242
+ targetProfile.replace (0 , 2 , L" vs" );
243
+ break ;
244
+ case asset::IShader::ESS_TESSELLATION_CONTROL:
245
+ targetProfile.replace (0 , 2 , L" ds" );
246
+ break ;
247
+ case asset::IShader::ESS_TESSELLATION_EVALUATION:
248
+ targetProfile.replace (0 , 2 , L" hs" );
249
+ break ;
250
+ case asset::IShader::ESS_GEOMETRY:
251
+ targetProfile.replace (0 , 2 , L" gs" );
252
+ break ;
253
+ case asset::IShader::ESS_FRAGMENT:
254
+ targetProfile.replace (0 , 2 , L" ps" );
255
+ break ;
256
+ case asset::IShader::ESS_COMPUTE:
257
+ targetProfile.replace (0 , 2 , L" cs" );
258
+ break ;
259
+ case asset::IShader::ESS_TASK:
260
+ targetProfile.replace (0 , 2 , L" as" );
261
+ break ;
262
+ case asset::IShader::ESS_MESH:
263
+ targetProfile.replace (0 , 2 , L" ms" );
264
+ break ;
265
+ default :
266
+ hlslOptions.preprocessorOptions .logger .log (" invalid shader stage %i" , system::ILogger::ELL_ERROR, stage);
267
+ return nullptr ;
257
268
};
258
269
259
- std::vector<LPCWSTR> arguments = {
270
+
271
+ std::vector<LPCWSTR> arguments;
272
+ if (dxc_compile_flags.size ()) {
273
+ arguments = {};
274
+ for (size_t i = 0 ; i < dxc_compile_flags.size (); i++)
275
+ arguments.push_back (LPCWSTR (dxc_compile_flags[i].c_str ()));
276
+ }
277
+ else {
278
+ arguments = {
260
279
L" -spirv" ,
261
280
L" -HV" , L" 202x" ,
262
281
L" -T" , targetProfile.c_str (),
@@ -267,31 +286,31 @@ core::smart_refctd_ptr<ICPUShader> CHLSLCompiler::compileToSPIRV(const char* cod
267
286
L" -Wno-c++1z-extensions" ,
268
287
L" -Wno-gnu-static-float-init" ,
269
288
L" -fspv-target-env=vulkan1.3"
270
- };
289
+ };
290
+ // If a custom SPIR-V optimizer is specified, use that instead of DXC's spirv-opt.
291
+ // This is how we can get more optimizer options.
292
+ //
293
+ // Optimization is also delegated to SPIRV-Tools. Right now there are no difference between
294
+ // optimization levels greater than zero; they will all invoke the same optimization recipe.
295
+ // https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#optimization
296
+ if (hlslOptions.spirvOptimizer )
297
+ {
298
+ arguments.push_back (L" -O0" );
299
+ }
271
300
272
- // If a custom SPIR-V optimizer is specified, use that instead of DXC's spirv-opt.
273
- // This is how we can get more optimizer options.
274
- //
275
- // Optimization is also delegated to SPIRV-Tools. Right now there are no difference between
276
- // optimization levels greater than zero; they will all invoke the same optimization recipe.
277
- // https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#optimization
278
- if (hlslOptions.spirvOptimizer )
279
- {
280
- arguments.push_back (L" -O0" );
301
+ // Debug only values
302
+ if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_FILE_BIT))
303
+ arguments.push_back (L" -fspv-debug=file" );
304
+ if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT))
305
+ arguments.push_back (L" -fspv-debug=source" );
306
+ if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT))
307
+ arguments.push_back (L" -fspv-debug=line" );
308
+ if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT))
309
+ arguments.push_back (L" -fspv-debug=tool" );
310
+ if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_NON_SEMANTIC_BIT))
311
+ arguments.push_back (L" -fspv-debug=vulkan-with-source" );
281
312
}
282
313
283
- // Debug only values
284
- if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_FILE_BIT))
285
- arguments.push_back (L" -fspv-debug=file" );
286
- if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_SOURCE_BIT))
287
- arguments.push_back (L" -fspv-debug=source" );
288
- if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT))
289
- arguments.push_back (L" -fspv-debug=line" );
290
- if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_TOOL_BIT))
291
- arguments.push_back (L" -fspv-debug=tool" );
292
- if (hlslOptions.debugInfoFlags .hasFlags (E_DEBUG_INFO_FLAGS::EDIF_NON_SEMANTIC_BIT))
293
- arguments.push_back (L" -fspv-debug=vulkan-with-source" );
294
-
295
314
auto compileResult = dxcCompile (
296
315
this ,
297
316
m_dxcCompilerTypes,
0 commit comments