Add profiler events to shader compiler
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
#include "Engine/Utilities/TextProcessing.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "ShaderFunctionReader.CB.h"
|
||||
#include "ShaderFunctionReader.VS.h"
|
||||
@@ -31,6 +32,7 @@ ShaderProcessing::Parser::~Parser()
|
||||
|
||||
bool ShaderProcessing::Parser::Process(const String& targetName, const char* source, int32 sourceLength, ParserMacros macros, FeatureLevel featureLevel, ShaderMeta* result)
|
||||
{
|
||||
PROFILE_CPU("Shader.Parse");
|
||||
Parser parser(targetName, source, sourceLength, macros, featureLevel);
|
||||
parser.Process(result);
|
||||
return parser.Failed();
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#if COMPILE_WITH_SHADER_COMPILER
|
||||
|
||||
#include "ShaderCompilationContext.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Parser/ShaderMeta.h"
|
||||
#include "Engine/Graphics/Config.h"
|
||||
#include "Config.h"
|
||||
|
||||
void ShaderCompilationContext::OnError(const char* message)
|
||||
{
|
||||
LOG(Error, "Failed to compile '{0}'. {1}", Options->TargetName, String(message));
|
||||
}
|
||||
|
||||
void ShaderCompilationContext::OnCollectDebugInfo(ShaderFunctionMeta& meta, int32 permutationIndex, const char* data, const int32 dataLength)
|
||||
{
|
||||
#ifdef GPU_USE_SHADERS_DEBUG_LAYER
|
||||
|
||||
// Cache data
|
||||
meta.Permutations[permutationIndex].DebugData.Set(data, dataLength);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ShaderCompilationContext::ShaderCompilationContext(const ShaderCompilationOptions* options, ShaderMeta* meta)
|
||||
: Options(options)
|
||||
, Meta(meta)
|
||||
, Output(options->Output)
|
||||
{
|
||||
// Convert target name to ANSI text (with limited length)
|
||||
const int32 ansiNameLen = Math::Min<int32>(ARRAY_COUNT(TargetNameAnsi) - 1, options->TargetName.Length());
|
||||
StringUtils::ConvertUTF162ANSI(*options->TargetName, TargetNameAnsi, ansiNameLen);
|
||||
TargetNameAnsi[ansiNameLen] = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -248,12 +248,18 @@ void ShaderCompiler::DisposeIncludedFilesCache()
|
||||
bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto meta = _context->Meta;
|
||||
#if BUILD_DEBUG
|
||||
#define PROFILE_COMPILE_SHADER(s) ZoneTransientN(___tracy_scoped_zone, s.Name.Get(), true);
|
||||
#else
|
||||
#define PROFILE_COMPILE_SHADER(s)
|
||||
#endif
|
||||
|
||||
// Generate vertex shaders cache
|
||||
for (int32 i = 0; i < meta->VS.Count(); i++)
|
||||
{
|
||||
auto& shader = meta->VS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Vertex && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader, &WriteCustomDataVS))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -266,6 +272,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto& shader = meta->HS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Hull && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader, &WriteCustomDataHS))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -278,6 +285,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto& shader = meta->DS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Domain && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -290,6 +298,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto& shader = meta->GS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Geometry && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -302,6 +311,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto& shader = meta->PS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Pixel && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -314,6 +324,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
{
|
||||
auto& shader = meta->CS[i];
|
||||
ASSERT(shader.GetStage() == ShaderStage::Compute && (shader.Flags & ShaderFlags::Hidden) == 0);
|
||||
PROFILE_COMPILE_SHADER(shader);
|
||||
if (CompileShader(shader))
|
||||
{
|
||||
LOG(Error, "Failed to compile \'{0}\'", String(shader.Name));
|
||||
@@ -321,6 +332,7 @@ bool ShaderCompiler::CompileShaders()
|
||||
}
|
||||
}
|
||||
|
||||
#undef PROFILE_COMPILE_SHADER
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "Engine/Serialization/MemoryWriteStream.h"
|
||||
#include "Engine/Core/Types/StringBuilder.h"
|
||||
#include "Engine/Engine/Globals.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Parser/ShaderMeta.h"
|
||||
|
||||
/// <summary>
|
||||
@@ -28,6 +29,7 @@ public:
|
||||
/// <returns>True if failed, otherwise false</returns>
|
||||
static bool Export(ShaderCompilationContext* context)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
#if USE_EDITOR
|
||||
static String ShadersDebugInfoFolder = Globals::ProjectCacheFolder / TEXT("Shaders/Debug");
|
||||
#else
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
#include "ShadersCompilation.h"
|
||||
#include "ShaderCompilationContext.h"
|
||||
#include "ShaderDebugDataExporter.h"
|
||||
#include "Config.h"
|
||||
#include "Parser/ShaderProcessing.h"
|
||||
#include "Parser/ShaderMeta.h"
|
||||
#include "Engine/Engine/EngineService.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Math/Math.h"
|
||||
#include "Engine/Core/Types/TimeSpan.h"
|
||||
#include "Parser/ShaderProcessing.h"
|
||||
#include "Engine/Graphics/Config.h"
|
||||
#include "Engine/Graphics/RenderTools.h"
|
||||
#include "Engine/Graphics/Shaders/GPUShader.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
@@ -459,4 +462,30 @@ void ShadersCompilationService::Dispose()
|
||||
ShaderIncludesMapLocker.Unlock();
|
||||
}
|
||||
|
||||
void ShaderCompilationContext::OnError(const char* message)
|
||||
{
|
||||
LOG(Error, "Failed to compile '{0}'. {1}", Options->TargetName, String(message));
|
||||
}
|
||||
|
||||
void ShaderCompilationContext::OnCollectDebugInfo(ShaderFunctionMeta& meta, int32 permutationIndex, const char* data, const int32 dataLength)
|
||||
{
|
||||
#ifdef GPU_USE_SHADERS_DEBUG_LAYER
|
||||
|
||||
// Cache data
|
||||
meta.Permutations[permutationIndex].DebugData.Set(data, dataLength);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
ShaderCompilationContext::ShaderCompilationContext(const ShaderCompilationOptions* options, ShaderMeta* meta)
|
||||
: Options(options)
|
||||
, Meta(meta)
|
||||
, Output(options->Output)
|
||||
{
|
||||
// Convert target name to ANSI text (with limited length)
|
||||
const int32 ansiNameLen = Math::Min<int32>(ARRAY_COUNT(TargetNameAnsi) - 1, options->TargetName.Length());
|
||||
StringUtils::ConvertUTF162ANSI(*options->TargetName, TargetNameAnsi, ansiNameLen);
|
||||
TargetNameAnsi[ansiNameLen] = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user