From b3d77ab9eb75b7100d6ec00608e08f4b08bcfa0d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 3 Jul 2024 13:22:19 +0200 Subject: [PATCH] Add shaders profiling console command --- Source/Engine/Engine/CommandLine.cpp | 1 + Source/Engine/Engine/CommandLine.h | 5 +++++ Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp | 4 ++++ Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/Source/Engine/Engine/CommandLine.cpp b/Source/Engine/Engine/CommandLine.cpp index c1d1a8540..744060288 100644 --- a/Source/Engine/Engine/CommandLine.cpp +++ b/Source/Engine/Engine/CommandLine.cpp @@ -156,6 +156,7 @@ bool CommandLine::Parse(const Char* cmdLine) PARSE_ARG_SWITCH("-build ", Build); PARSE_BOOL_SWITCH("-skipcompile ", SkipCompile); PARSE_BOOL_SWITCH("-shaderdebug ", ShaderDebug); + PARSE_BOOL_SWITCH("-shaderprofile ", ShaderProfile); PARSE_ARG_OPT_SWITCH("-play ", Play); #endif diff --git a/Source/Engine/Engine/CommandLine.h b/Source/Engine/Engine/CommandLine.h index 039349770..aac3000e9 100644 --- a/Source/Engine/Engine/CommandLine.h +++ b/Source/Engine/Engine/CommandLine.h @@ -169,6 +169,11 @@ public: /// Nullable ShaderDebug; + /// + /// -shaderprofile (enables debugging data generation for shaders but leaves shader compiler optimizations active for performance profiling) + /// + Nullable ShaderProfile; + /// /// -play !guid! ( Scene to play, can be empty to use default ) /// diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp index 8a88e2d25..6f91ff4be 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderAssetBase.cpp @@ -254,6 +254,10 @@ bool ShaderAssetBase::LoadShaderCache(ShaderCacheResult& result) options.GenerateDebugData = true; options.NoOptimize = true; } + else if (CommandLine::Options.ShaderProfile) + { + options.GenerateDebugData = true; + } auto& platformDefine = options.Macros.AddOne(); #if PLATFORM_WINDOWS platformDefine.Name = "PLATFORM_WINDOWS"; diff --git a/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp b/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp index d882e5db7..b8adce351 100644 --- a/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp +++ b/Source/Engine/Graphics/Shaders/Cache/ShaderCacheManager.cpp @@ -188,11 +188,13 @@ bool ShaderCacheManagerService::Init() int32 MaterialGraphVersion = -1; int32 ParticleGraphVersion = -1; bool ShaderDebug; + bool ShaderProfile; }; CacheVersion cacheVersion; const String cacheVerFile = rootDir / TEXT("CacheVersion"); #if USE_EDITOR const bool shaderDebug = CommandLine::Options.ShaderDebug; + const bool shaderProfile = CommandLine::Options.ShaderProfile; #else const bool shaderDebug = false; #endif @@ -209,6 +211,7 @@ bool ShaderCacheManagerService::Init() || cacheVersion.MaterialGraphVersion != MATERIAL_GRAPH_VERSION || cacheVersion.ParticleGraphVersion != PARTICLE_GPU_GRAPH_VERSION || cacheVersion.ShaderDebug != shaderDebug + || cacheVersion.ShaderProfile != shaderProfile ) { LOG(Warning, "Shaders cache database is invalid. Performing reset."); @@ -227,6 +230,7 @@ bool ShaderCacheManagerService::Init() cacheVersion.MaterialGraphVersion = MATERIAL_GRAPH_VERSION; cacheVersion.ParticleGraphVersion = PARTICLE_GPU_GRAPH_VERSION; cacheVersion.ShaderDebug = shaderDebug; + cacheVersion.ShaderProfile = shaderProfile; if (File::WriteAllBytes(cacheVerFile, (byte*)&cacheVersion, sizeof(cacheVersion))) { LOG(Error, "Failed to create the shaders cache database version file.");