Add outputting shader source code in Editor to text file when compilation fails for debugging

This commit is contained in:
Wojtek Figat
2023-10-12 18:57:27 +02:00
parent 5b5f43714e
commit 6f7f22eb47

View File

@@ -143,9 +143,20 @@ bool ShadersCompilation::Compile(ShaderCompilationOptions& options)
#endif
}
// Print info if succeed
if (result == false)
if (result)
{
// Output shader source to easily investigate errors (eg. for generated shaders like materials or particles)
const String outputSourceFolder = Globals::ProjectCacheFolder / TEXT("/Shaders/Source");
const String outputSourcePath = outputSourceFolder / options.TargetName + TEXT(".hlsl");
if (!FileSystem::DirectoryExists(outputSourceFolder))
FileSystem::CreateDirectory(outputSourceFolder);
File::WriteAllBytes(outputSourcePath, (const byte*)options.Source, options.SourceLength);
LOG(Error, "Shader compilation '{0}' failed (profile: {1})", options.TargetName, ::ToString(options.Profile));
LOG(Error, "Source: {0}", outputSourcePath);
}
else
{
// Success
const DateTime endTime = DateTime::NowUTC();
LOG(Info, "Shader compilation '{0}' succeed in {1} ms (profile: {2})", options.TargetName, Math::CeilToInt(static_cast<float>((endTime - startTime).GetTotalMilliseconds())), ::ToString(options.Profile));
}