Skip to content

Commit 3d37908

Browse files
committed
fixed ndt bugs 2
1 parent 0786239 commit 3d37908

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

src/nbl/asset/utils/CHLSLCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ CHLSLCompiler::SdxcCompileResult CHLSLCompiler::dxcCompile(std::string& source,
131131
else
132132
{
133133
options.preprocessorOptions.logger.log("DXC Compilation Failed:\n%s", system::ILogger::ELL_ERROR, errorMessagesString.c_str());
134-
return { (uint8_t*) result.objectBlob->GetBufferPointer(), result.objectBlob->GetBufferSize() };
134+
return { nullptr, 0 };
135135
}
136136

137137
ComPtr<IDxcBlob> resultingBlob;

src/nbl/system/ISystem.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,15 @@ bool ISystem::ICaller::flushMapping(IFile* file, size_t offset, size_t size)
308308

309309
void ISystem::unmountBuiltins() {
310310

311+
auto removeByKey = [&, this](const char* s) {
312+
auto range = m_cachedArchiveFiles.findRange(s);
313+
for (auto it = range.begin(); it != range.end(); ++it)
314+
{
315+
unmount(it->second.get(), s);
316+
}
317+
};
318+
removeByKey("nbl/builtin");
319+
removeByKey("spirv");
320+
removeByKey("boost");
321+
311322
}

tools/ndt/main.cpp

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ShaderCompiler final : public system::IApplicationFramework
4141
auto argc = argv.size();
4242

4343
// expect the first argument to be
44-
// nsc.exe
44+
// .exe
4545
// second the filename of a shader to compile
4646
if (argc < 2) {
4747
m_logger->log("Insufficient arguments.", ILogger::ELL_ERROR);
@@ -76,6 +76,14 @@ class ShaderCompiler final : public system::IApplicationFramework
7676
}
7777
}
7878
}
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
7987
string shader_code = open_shader_file(file_to_compile);
8088
auto compilation_result = compile_shader(shader_code, file_to_compile);
8189

@@ -88,15 +96,7 @@ class ShaderCompiler final : public system::IApplicationFramework
8896
else {
8997
m_logger->log("Shader compilation failed.", ILogger::ELL_ERROR);
9098
}
91-
/*std::string command = "dxc.exe";
92-
for (std::string arg : arguments)
93-
{
94-
command.append(" ").append(arg);
95-
}
9699

97-
int execute = std::system(command.c_str());*/
98-
99-
//std::cout << "-no-nbl-builtins - " << no_nbl_builtins;
100100

101101

102102
return true;
@@ -116,10 +116,9 @@ class ShaderCompiler final : public system::IApplicationFramework
116116
const string WorkgroupSizeAsStr = std::to_string(WorkgroupSize);
117117
const IShaderCompiler::SPreprocessorOptions::SMacroDefinition WorkgroupSizeDefine = { "WORKGROUP_SIZE",WorkgroupSizeAsStr };
118118

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));
120120

121121
CHLSLCompiler::SOptions options = {};
122-
options.stage = asset::IShader::E_SHADER_STAGE::ESS_UNKNOWN; // probably not needed, requires guessing -T target profile
123122
// want as much debug as possible
124123
options.debugInfoFlags = IShaderCompiler::E_DEBUG_INFO_FLAGS::EDIF_LINE_BIT;
125124
// this lets you source-level debug/step shaders in renderdoc
@@ -130,18 +129,24 @@ class ShaderCompiler final : public system::IApplicationFramework
130129
options.preprocessorOptions.logger = m_logger.get();
131130
options.preprocessorOptions.extraDefines = { &WorkgroupSizeDefine,&WorkgroupSizeDefine + 1 };
132131

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));
134133
options.preprocessorOptions.includeFinder = includeFinder.get();
135134

136135
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);
138139

140+
139141
// override arguments from command line to ones listed in pragma
140142
if (dxc_compile_flags_from_pragma.size())
141143
m_arguments = dxc_compile_flags_from_pragma;
142144

143145
add_required_arguments_if_not_present();
144146

147+
if (shaderStage)
148+
add_shader_stage(shaderStage);
149+
145150
//convert string arguments to wstring arguments
146151
int arg_size = m_arguments.size() - 1; // skip input file argument
147152
LPCWSTR* arguments = new LPCWSTR[arg_size]; //array of pointers
@@ -192,6 +197,46 @@ class ShaderCompiler final : public system::IApplicationFramework
192197

193198
}
194199

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+
195240

196241
std::string open_shader_file(std::string& filepath) {
197242
std::ifstream stream(filepath);

0 commit comments

Comments
 (0)