Add shader reloading on header file edit for shaders with compilation errors

This commit is contained in:
Wojciech Figat
2022-04-08 13:53:23 +02:00
parent da4008575b
commit 598876d8e3
2 changed files with 16 additions and 8 deletions

View File

@@ -324,15 +324,14 @@ void Asset::Reload()
Content::AssetReloading(this);
OnReloading(this);
// Fire unload event
// TODO: maybe just call release storage ref or sth? we cannot call onUnload because managed asset objects gets invalidated
//onUnload_MainThread();
ScopeLock lock(Locker);
// Unload current data
unload(true);
_isLoaded = false;
if (IsLoaded())
{
// Unload current data
unload(true);
_isLoaded = false;
}
// Start reloading process
startLoading();

View File

@@ -19,6 +19,8 @@
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Content/Asset.h"
#include "Engine/Content/Content.h"
#include "Engine/Content/Assets/Shader.h"
#if USE_EDITOR
#define COMPILE_WITH_ASSETS_IMPORTER 1 // Hack to use shaders importing in this module
#include "Engine/ContentImporters/AssetsImportingManager.h"
@@ -56,7 +58,6 @@ using namespace ShadersCompilationImpl;
class ShadersCompilationService : public EngineService
{
public:
ShadersCompilationService()
: EngineService(TEXT("Shaders Compilation Service"), -100)
{
@@ -250,6 +251,7 @@ namespace
if (action == FileSystemAction::Delete)
return;
// Get list of assets using this shader file
Array<Asset*> toReload;
{
ScopeLock lock(ShaderIncludesMapLocker);
@@ -260,6 +262,13 @@ namespace
toReload = file->Value;
}
// Add any shaders that failed to load (eg. due to error in included header)
for (Asset* asset : Content::GetAssets())
{
if (asset->LastLoadFailed() && asset->Is<Shader>() && !toReload.Contains(asset))
toReload.Add(asset);
}
LOG(Info, "Shader include \'{0}\' has been modified.", path);
// Wait a little so app that was editing the file (e.g. Visual Studio, Notepad++) has enough time to flush whole file change