From eb69dafb7cbd67222efaf4e65eb61c981f4f3cee Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 28 Jul 2026 22:32:36 +0200 Subject: [PATCH] Add `Loaded` event to `Asset` in scripting Refactor `Asset` events naming to match engine scheme --- Source/Editor/Windows/SplashScreen.cpp | 4 +-- Source/Engine/Content/Asset.cpp | 16 +++++++++-- Source/Engine/Content/Asset.h | 26 ++++++++++++++--- .../Content/Assets/MaterialInstance.cpp | 4 +-- Source/Engine/Content/Assets/SkinnedModel.cpp | 12 ++++---- Source/Engine/Core/Types/Variant.cpp | 22 +++++++-------- Source/Engine/Debug/DebugDraw.cpp | 2 +- .../Level/Actors/ExponentialHeightFog.cpp | 2 +- Source/Engine/Level/Actors/Sky.cpp | 2 +- Source/Engine/Particles/Particles.cpp | 2 +- .../Engine/Physics/Colliders/BoxCollider.cpp | 2 +- .../Physics/Colliders/CapsuleCollider.cpp | 2 +- .../Engine/Physics/Colliders/MeshCollider.cpp | 7 +++++ .../Physics/Colliders/SphereCollider.cpp | 2 +- Source/Engine/Render2D/Render2D.cpp | 2 +- .../Engine/Renderer/AmbientOcclusionPass.cpp | 4 +-- Source/Engine/Renderer/AntiAliasing/FXAA.cpp | 5 +--- Source/Engine/Renderer/AntiAliasing/SMAA.cpp | 4 +-- Source/Engine/Renderer/AntiAliasing/TAA.cpp | 4 +-- Source/Engine/Renderer/ColorGradingPass.cpp | 4 +-- .../ContrastAdaptiveSharpeningPass.cpp | 4 +-- Source/Engine/Renderer/DepthOfFieldPass.cpp | 4 +-- .../Renderer/Editor/LightmapUVsDensity.cpp | 4 +-- .../Renderer/Editor/QuadOverdrawPass.cpp | 4 +-- .../Engine/Renderer/Editor/VertexColors.cpp | 5 ++-- Source/Engine/Renderer/EyeAdaptationPass.cpp | 4 +-- Source/Engine/Renderer/ForwardPass.cpp | 9 +----- Source/Engine/Renderer/GBufferPass.cpp | 28 +++++++------------ Source/Engine/Renderer/GBufferPass.h | 3 +- .../GI/DynamicDiffuseGlobalIllumination.cpp | 4 +-- .../Renderer/GI/GlobalSurfaceAtlasPass.cpp | 4 +-- .../Renderer/GlobalSignDistanceFieldPass.cpp | 4 +-- Source/Engine/Renderer/HistogramPass.cpp | 4 +-- Source/Engine/Renderer/LightPass.cpp | 5 +--- Source/Engine/Renderer/MotionBlurPass.cpp | 5 +--- Source/Engine/Renderer/PostProcessingPass.cpp | 5 +--- Source/Engine/Renderer/ProbesRenderer.cpp | 4 +-- Source/Engine/Renderer/ReflectionsPass.cpp | 4 +-- Source/Engine/Renderer/RendererPass.h | 6 ++++ .../Renderer/ScreenSpaceReflectionsPass.cpp | 4 +-- Source/Engine/Renderer/ShadowsPass.cpp | 5 +--- Source/Engine/Renderer/Utils/BitonicSort.cpp | 5 ++-- Source/Engine/Renderer/Utils/MultiScaler.cpp | 4 +-- Source/Engine/Renderer/VolumetricFogPass.cpp | 6 +--- 44 files changed, 117 insertions(+), 145 deletions(-) diff --git a/Source/Editor/Windows/SplashScreen.cpp b/Source/Editor/Windows/SplashScreen.cpp index 64202e2d6..86c695d6f 100644 --- a/Source/Editor/Windows/SplashScreen.cpp +++ b/Source/Editor/Windows/SplashScreen.cpp @@ -213,7 +213,7 @@ void SplashScreen::Show() if (font->IsLoaded()) OnFontLoaded(font); else - font->OnLoaded.Bind(this); + font->Loaded.Bind(this); } // Load custom image @@ -337,7 +337,7 @@ void SplashScreen::OnFontLoaded(Asset* asset) ASSERT(asset && asset->IsLoaded()); auto font = (FontAsset*)asset; - font->OnLoaded.Unbind(this); + font->Loaded.Unbind(this); // Create fonts const float s = _dpiScale; diff --git a/Source/Engine/Content/Asset.cpp b/Source/Engine/Content/Asset.cpp index 006c278b6..dab12cc3f 100644 --- a/Source/Engine/Content/Asset.cpp +++ b/Source/Engine/Content/Asset.cpp @@ -403,7 +403,10 @@ uint64 Asset::GetMemoryUsage() const Locker.Lock(); if (Platform::AtomicRead(&_loadingTask)) result += sizeof(ContentLoadTask); + result += (Loaded.Capacity() + Reloading.Capacity() + Unloaded.Capacity()) * sizeof(Delegate::FunctionType); +PRAGMA_DISABLE_DEPRECATION_WARNINGS; result += (OnLoaded.Capacity() + OnReloading.Capacity() + OnUnloaded.Capacity()) * sizeof(EventType::FunctionType); +PRAGMA_ENABLE_DEPRECATION_WARNINGS; result += _references.Capacity() * sizeof(HashSet::Bucket); Locker.Unlock(); return result; @@ -426,7 +429,10 @@ void Asset::Reload() // Fire event if (!IsInternalType()) Content::AssetReloading(this); +PRAGMA_DISABLE_DEPRECATION_WARNINGS; OnReloading(this); + Reloading(this); +PRAGMA_ENABLE_DEPRECATION_WARNINGS; ScopeLock lock(Locker); @@ -676,14 +682,17 @@ bool Asset::onLoad(LoadAssetTask* task) return failed; } +PRAGMA_DISABLE_DEPRECATION_WARNINGS; + void Asset::onLoaded() { if (IsInMainThread()) { onLoaded_MainThread(); } - else if (OnLoaded.IsBinded() || _references.HasItems()) + else if (OnLoaded.IsBinded() || Loaded.IsBinded() || _references.HasItems()) { + // Delay event call to the main thread Function action; action.Bind(this); Task::StartNew(New(action, this)); @@ -699,12 +708,12 @@ void Asset::onLoaded_MainThread() for (const auto& e : _references) e.Item->OnAssetLoaded(this, this); OnLoaded(this); + Loaded(this); } void Asset::onUnload_MainThread() { // Note: asset should not be locked now (Locker should be free) so other thread won't be locked. - ASSERT(IsInMainThread()); // Cancel any streaming before calling OnUnloaded event @@ -715,8 +724,11 @@ void Asset::onUnload_MainThread() for (const auto& e : _references) e.Item->OnAssetUnloaded(this, this); OnUnloaded(this); + Unloaded(this); } +PRAGMA_ENABLE_DEPRECATION_WARNINGS; + bool Asset::WaitForInitGraphics() { #define IS_GPU_NOT_READY() (GPUDevice::Instance == nullptr || GPUDevice::Instance->GetState() != GPUDevice::DeviceState::Ready) diff --git a/Source/Engine/Content/Asset.h b/Source/Engine/Content/Asset.h index c23dff51a..3a3ba2882 100644 --- a/Source/Engine/Content/Asset.h +++ b/Source/Engine/Content/Asset.h @@ -78,18 +78,36 @@ public: /// /// Action called when asset gets loaded + /// [Deprecated in v1.13] /// - EventType OnLoaded; + DEPRECATED("Use Loaded event instead.") EventType OnLoaded; + + /// + /// Action called when asset gets loaded. Always called from the main thread. + /// + API_EVENT() Delegate Loaded; + + /// + /// Action called when asset start reloading (e.g. after reimport). Always called from the main thread. + /// [Deprecated in v1.13] + /// + DEPRECATED("Use Reloading event instead.") EventType OnReloading; /// /// Action called when asset start reloading (e.g. after reimport). Always called from the main thread. /// - EventType OnReloading; + Delegate Reloading; /// - /// Action called when asset gets unloaded + /// Action called when asset gets unloaded. Always called from the main thread. + /// [Deprecated in v1.13] /// - EventType OnUnloaded; + DEPRECATED("Use Unloaded event instead.") EventType OnUnloaded; + + /// + /// Action called when asset gets unloaded. Always called from the main thread. + /// + Delegate Unloaded; /// /// General purpose mutex for an asset object. Should guard most of the asset functionalities to be secure. diff --git a/Source/Engine/Content/Assets/MaterialInstance.cpp b/Source/Engine/Content/Assets/MaterialInstance.cpp index febcd02cf..61d5c5b62 100644 --- a/Source/Engine/Content/Assets/MaterialInstance.cpp +++ b/Source/Engine/Content/Assets/MaterialInstance.cpp @@ -25,7 +25,7 @@ void MaterialInstance::OnBaseSet() ASSERT(_baseMaterial->IsLoaded()); _baseMaterial->AddReference(); - _baseMaterial->OnUnloaded.Bind(this); + _baseMaterial->Unloaded.Bind(this); _baseMaterial->ParamsChanged.Bind(this); // Sync parameters with the base parameters to ensure all data is valid for rendering (constants offset and resource register) @@ -63,7 +63,7 @@ void MaterialInstance::OnBaseSet() void MaterialInstance::OnBaseUnset() { _baseMaterial->RemoveReference(); - _baseMaterial->OnUnloaded.Unbind(this); + _baseMaterial->Unloaded.Unbind(this); _baseMaterial->ParamsChanged.Unbind(this); } diff --git a/Source/Engine/Content/Assets/SkinnedModel.cpp b/Source/Engine/Content/Assets/SkinnedModel.cpp index 5c98853ff..7640650bc 100644 --- a/Source/Engine/Content/Assets/SkinnedModel.cpp +++ b/Source/Engine/Content/Assets/SkinnedModel.cpp @@ -197,9 +197,9 @@ SkinnedModel::SkeletonMapping SkinnedModel::GetSkeletonMapping(Asset* source, bo // Add to cache _skeletonMappingCache.Add(source, mappingData); - source->OnUnloaded.Bind(this); + source->Unloaded.Bind(this); #if USE_EDITOR - source->OnReloading.Bind(this); + source->Reloading.Bind(this); #endif } mapping.SourceSkeleton = mappingData.SourceSkeleton; @@ -756,9 +756,9 @@ void SkinnedModel::ClearSkeletonMapping() { for (const auto& e : _skeletonMappingCache) { - e.Key->OnUnloaded.Unbind(this); + e.Key->Unloaded.Unbind(this); #if USE_EDITOR - e.Key->OnReloading.Unbind(this); + e.Key->Reloading.Unbind(this); #endif Allocator::Free((void*)e.Value.NodesMapping.Get()); } @@ -773,9 +773,9 @@ void SkinnedModel::OnSkeletonMappingSourceAssetUnloaded(Asset* obj) ASSERT(found); // Unlink event - obj->OnUnloaded.Unbind(this); + obj->Unloaded.Unbind(this); #if USE_EDITOR - obj->OnReloading.Unbind(this); + obj->Reloading.Unbind(this); #endif // Clear cache diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index 5fcfea63a..a4dd897d1 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -592,8 +592,8 @@ Variant::Variant(Variant&& other) noexcept AsAsset = other.AsAsset; if (AsAsset) { - AsAsset->OnUnloaded.Unbind(&other); - AsAsset->OnUnloaded.Bind(this); + AsAsset->Unloaded.Unbind(&other); + AsAsset->Unloaded.Bind(this); other.AsAsset = nullptr; } break; @@ -723,7 +723,7 @@ Variant::Variant(Asset* v) { v->AddReference(); Type.SetTypeName(v->GetType()); - v->OnUnloaded.Bind(this); + v->Unloaded.Bind(this); } } @@ -976,7 +976,7 @@ Variant::~Variant() case VariantType::Asset: if (AsAsset) { - AsAsset->OnUnloaded.Unbind(this); + AsAsset->Unloaded.Unbind(this); AsAsset->RemoveReference(); } break; @@ -1044,8 +1044,8 @@ Variant& Variant::operator=(Variant&& other) AsAsset = other.AsAsset; if (AsAsset) { - AsAsset->OnUnloaded.Unbind(&other); - AsAsset->OnUnloaded.Bind(this); + AsAsset->Unloaded.Unbind(&other); + AsAsset->Unloaded.Bind(this); } break; case VariantType::Array: @@ -1117,7 +1117,7 @@ Variant& Variant::operator=(const Variant& other) if (other.AsAsset) { AsAsset->AddReference(); - AsAsset->OnUnloaded.Bind(this); + AsAsset->Unloaded.Bind(this); } break; case VariantType::Array: @@ -2369,7 +2369,7 @@ void Variant::SetType(const VariantType& type) case VariantType::Asset: if (AsAsset) { - AsAsset->OnUnloaded.Unbind(this); + AsAsset->Unloaded.Unbind(this); AsAsset->RemoveReference(); } break; @@ -2483,7 +2483,7 @@ void Variant::SetType(VariantType&& type) case VariantType::Asset: if (AsAsset) { - AsAsset->OnUnloaded.Unbind(this); + AsAsset->Unloaded.Unbind(this); AsAsset->RemoveReference(); } break; @@ -2716,14 +2716,14 @@ void Variant::SetAsset(Asset* asset) SetType(VariantType(VariantType::Asset)); if (AsAsset) { - AsAsset->OnUnloaded.Unbind(this); + AsAsset->Unloaded.Unbind(this); AsAsset->RemoveReference(); } AsAsset = asset; if (asset) { asset->AddReference(); - asset->OnUnloaded.Bind(this); + asset->Unloaded.Bind(this); } } diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index a756892d6..f496df881 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -680,7 +680,7 @@ void DebugDrawService::Update() LOG(Fatal, "Cannot load DebugDraw shader"); } #if COMPILE_WITH_DEV_ENV - DebugDrawShader->OnReloading.Bind(&OnShaderReloading); + DebugDrawShader->Reloading.Bind(&OnShaderReloading); #endif } if (DebugDrawPsWireTrianglesDepthTest.Depth == nullptr && DebugDrawShader && DebugDrawShader->IsLoaded()) diff --git a/Source/Engine/Level/Actors/ExponentialHeightFog.cpp b/Source/Engine/Level/Actors/ExponentialHeightFog.cpp index c1e804ea9..a8d99a2f1 100644 --- a/Source/Engine/Level/Actors/ExponentialHeightFog.cpp +++ b/Source/Engine/Level/Actors/ExponentialHeightFog.cpp @@ -27,7 +27,7 @@ ExponentialHeightFog::ExponentialHeightFog(const SpawnParams& params) LOG(Fatal, "Cannot load fog shader."); } #if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); + _shader.Get()->Reloading.Bind(this); #endif } diff --git a/Source/Engine/Level/Actors/Sky.cpp b/Source/Engine/Level/Actors/Sky.cpp index 09f9f086d..e4cc0ab18 100644 --- a/Source/Engine/Level/Actors/Sky.cpp +++ b/Source/Engine/Level/Actors/Sky.cpp @@ -43,7 +43,7 @@ Sky::Sky(const SpawnParams& params) return; } #if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); + _shader.Get()->Reloading.Bind(this); #endif } diff --git a/Source/Engine/Particles/Particles.cpp b/Source/Engine/Particles/Particles.cpp index e1f064601..e9558ec4e 100644 --- a/Source/Engine/Particles/Particles.cpp +++ b/Source/Engine/Particles/Particles.cpp @@ -700,7 +700,7 @@ void DrawEmittersGPU(GPUContext* context, RenderContextBatch& renderContextBatch GPUParticlesSorting = Content::LoadAsyncInternal(TEXT("Shaders/GPUParticlesSorting")); #if COMPILE_WITH_DEV_ENV if (GPUParticlesSorting) - GPUParticlesSorting.Get()->OnReloading.Bind(); + GPUParticlesSorting.Get()->Reloading.Bind(); #endif } if (GPUParticlesSorting == nullptr || !GPUParticlesSorting->IsLoaded()) diff --git a/Source/Engine/Physics/Colliders/BoxCollider.cpp b/Source/Engine/Physics/Colliders/BoxCollider.cpp index 47e551b37..96126c037 100644 --- a/Source/Engine/Physics/Colliders/BoxCollider.cpp +++ b/Source/Engine/Physics/Colliders/BoxCollider.cpp @@ -144,7 +144,7 @@ void BoxCollider::OnDebugDrawSelf() void BoxCollider::OnDebugDrawSelected() { OnDebugDrawSelf(); - + DEBUG_DRAW_BOX(_bounds, Color::GreenYellow.AlphaMultiplied(0.1f), 0, true); if (_contactOffset > 0) { OrientedBoundingBox contactBounds = _bounds; diff --git a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp index 83ce85115..0c0538301 100644 --- a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp +++ b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp @@ -72,7 +72,7 @@ void CapsuleCollider::OnDebugDrawSelected() const float height = Math::Max(Math::Abs(_height) * _cachedScale, minSize); const Vector3 position = _transform.LocalToWorld(_center); DEBUG_DRAW_WIRE_CAPSULE(position, rotation, radius, height, Color::GreenYellow, 0, false); - + DEBUG_DRAW_CAPSULE(position, rotation, radius, height, Color::GreenYellow.AlphaMultiplied(0.1f), 0, true); if (_contactOffset > 0) { DEBUG_DRAW_WIRE_CAPSULE(position, rotation, radius + _contactOffset, height, Color::Blue.AlphaMultiplied(0.2f), 0, false); diff --git a/Source/Engine/Physics/Colliders/MeshCollider.cpp b/Source/Engine/Physics/Colliders/MeshCollider.cpp index 91731e7de..630d058b4 100644 --- a/Source/Engine/Physics/Colliders/MeshCollider.cpp +++ b/Source/Engine/Physics/Colliders/MeshCollider.cpp @@ -97,6 +97,13 @@ void MeshCollider::OnDebugDrawSelf() void MeshCollider::OnDebugDrawSelected() { OnDebugDrawSelf(); + if (CollisionData && CollisionData->IsLoaded()) + { + Array* vertexBuffer; + Array* indexBuffer; + CollisionData->GetDebugTriangles(vertexBuffer, indexBuffer); + DEBUG_DRAW_TRIANGLES_EX2(*vertexBuffer, *indexBuffer, _transform.GetWorld(), Color::GreenYellow.AlphaMultiplied(0.1f), 0, true); + } // Base Collider::OnDebugDrawSelected(); diff --git a/Source/Engine/Physics/Colliders/SphereCollider.cpp b/Source/Engine/Physics/Colliders/SphereCollider.cpp index eda3884e4..73ea7a046 100644 --- a/Source/Engine/Physics/Colliders/SphereCollider.cpp +++ b/Source/Engine/Physics/Colliders/SphereCollider.cpp @@ -43,7 +43,7 @@ void SphereCollider::OnDebugDrawSelf() void SphereCollider::OnDebugDrawSelected() { OnDebugDrawSelf(); - + DEBUG_DRAW_SPHERE(_sphere, Color::GreenYellow.AlphaMultiplied(0.1f), 0, true); if (_contactOffset > 0) { BoundingSphere contactBounds = _sphere; diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index ef969bbba..392ec2229 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -628,7 +628,7 @@ bool Render2DService::Init() if (GUIShader == nullptr) return true; #if COMPILE_WITH_DEV_ENV - GUIShader.Get()->OnReloading.Bind(); + GUIShader.Get()->Reloading.Bind(); #endif VB.SetLayout(GPUVertexLayout::Get({ diff --git a/Source/Engine/Renderer/AmbientOcclusionPass.cpp b/Source/Engine/Renderer/AmbientOcclusionPass.cpp index 3d5bcb756..9622b7f81 100644 --- a/Source/Engine/Renderer/AmbientOcclusionPass.cpp +++ b/Source/Engine/Renderer/AmbientOcclusionPass.cpp @@ -105,9 +105,7 @@ bool AmbientOcclusionPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/SSAO")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, AmbientOcclusionPass, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/AntiAliasing/FXAA.cpp b/Source/Engine/Renderer/AntiAliasing/FXAA.cpp index c4d1c85ae..8023c51b2 100644 --- a/Source/Engine/Renderer/AntiAliasing/FXAA.cpp +++ b/Source/Engine/Renderer/AntiAliasing/FXAA.cpp @@ -23,10 +23,7 @@ bool FXAA::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/FXAA")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif - + BIND_SHADER_RELOADING(_shader, FXAA, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/AntiAliasing/SMAA.cpp b/Source/Engine/Renderer/AntiAliasing/SMAA.cpp index 3972b6f16..4185cfab1 100644 --- a/Source/Engine/Renderer/AntiAliasing/SMAA.cpp +++ b/Source/Engine/Renderer/AntiAliasing/SMAA.cpp @@ -36,9 +36,7 @@ bool SMAA::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/SMAA")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, SMAA, OnShaderReloading); } if (!_shader->IsLoaded()) { diff --git a/Source/Engine/Renderer/AntiAliasing/TAA.cpp b/Source/Engine/Renderer/AntiAliasing/TAA.cpp index c578f57c0..f904f98cd 100644 --- a/Source/Engine/Renderer/AntiAliasing/TAA.cpp +++ b/Source/Engine/Renderer/AntiAliasing/TAA.cpp @@ -29,9 +29,7 @@ bool TAA::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/TAA")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, TAA, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/ColorGradingPass.cpp b/Source/Engine/Renderer/ColorGradingPass.cpp index 658d2e6a9..684fcf805 100644 --- a/Source/Engine/Renderer/ColorGradingPass.cpp +++ b/Source/Engine/Renderer/ColorGradingPass.cpp @@ -117,9 +117,7 @@ bool ColorGradingPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/ColorGrading")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ColorGradingPass, OnShaderReloading); PostProcessSettings defaultSettings; GPUTexture* defaultLut; DefaultData.Init(defaultSettings, defaultLut); diff --git a/Source/Engine/Renderer/ContrastAdaptiveSharpeningPass.cpp b/Source/Engine/Renderer/ContrastAdaptiveSharpeningPass.cpp index e8f039aa0..958a55725 100644 --- a/Source/Engine/Renderer/ContrastAdaptiveSharpeningPass.cpp +++ b/Source/Engine/Renderer/ContrastAdaptiveSharpeningPass.cpp @@ -41,9 +41,7 @@ bool ContrastAdaptiveSharpeningPass::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/CAS")); if (!_shader) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ContrastAdaptiveSharpeningPass, OnShaderReloading); } if (!_shader || !_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/DepthOfFieldPass.cpp b/Source/Engine/Renderer/DepthOfFieldPass.cpp index 866df28fd..25bd37539 100644 --- a/Source/Engine/Renderer/DepthOfFieldPass.cpp +++ b/Source/Engine/Renderer/DepthOfFieldPass.cpp @@ -79,9 +79,7 @@ bool DepthOfFieldPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/DepthOfField")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, DepthOfFieldPass, OnShaderReloading); } return false; diff --git a/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp b/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp index ea68b1520..51833287e 100644 --- a/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp +++ b/Source/Engine/Renderer/Editor/LightmapUVsDensity.cpp @@ -35,9 +35,7 @@ LightmapUVsDensityMaterialShader::LightmapUVsDensityMaterialShader() _shader = Content::LoadAsyncInternal(TEXT("Shaders/Editor/LightmapUVsDensity")); if (!_shader) return; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, LightmapUVsDensityMaterialShader, OnShaderReloading); _gridTexture = Content::LoadAsyncInternal(TEXT("Engine/Textures/Tiles_M")); } diff --git a/Source/Engine/Renderer/Editor/QuadOverdrawPass.cpp b/Source/Engine/Renderer/Editor/QuadOverdrawPass.cpp index da1480128..61bc0e9f3 100644 --- a/Source/Engine/Renderer/Editor/QuadOverdrawPass.cpp +++ b/Source/Engine/Renderer/Editor/QuadOverdrawPass.cpp @@ -138,9 +138,7 @@ bool QuadOverdrawPass::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/Editor/QuadOverdraw")); if (!_shader) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, QuadOverdrawPass, OnShaderReloading); } if (!_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/Editor/VertexColors.cpp b/Source/Engine/Renderer/Editor/VertexColors.cpp index f3d7cc39b..2b4203a6f 100644 --- a/Source/Engine/Renderer/Editor/VertexColors.cpp +++ b/Source/Engine/Renderer/Editor/VertexColors.cpp @@ -12,6 +12,7 @@ #include "Engine/Graphics/Shaders/GPUConstantBuffer.h" #include "Engine/Graphics/RenderTask.h" #include "Engine/Renderer/DrawCall.h" +#include "Engine/Renderer/RendererPass.h" GPU_CB_STRUCT(VertexColorsMaterialShaderData { Matrix ViewProjectionMatrix; @@ -24,9 +25,7 @@ VertexColorsMaterialShader::VertexColorsMaterialShader() _shader = Content::LoadAsyncInternal(TEXT("Shaders/Editor/VertexColors")); if (!_shader) return; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, VertexColorsMaterialShader, OnShaderReloading); } #if COMPILE_WITH_DEV_ENV diff --git a/Source/Engine/Renderer/EyeAdaptationPass.cpp b/Source/Engine/Renderer/EyeAdaptationPass.cpp index 8d2b0f0de..43e757e2b 100644 --- a/Source/Engine/Renderer/EyeAdaptationPass.cpp +++ b/Source/Engine/Renderer/EyeAdaptationPass.cpp @@ -232,9 +232,7 @@ bool EyeAdaptationPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/EyeAdaptation")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, EyeAdaptationPass, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/ForwardPass.cpp b/Source/Engine/Renderer/ForwardPass.cpp index 434a68560..275bb5c73 100644 --- a/Source/Engine/Renderer/ForwardPass.cpp +++ b/Source/Engine/Renderer/ForwardPass.cpp @@ -29,23 +29,16 @@ bool ForwardPass::Init() _psApplyDistortion = GPUDevice::Instance->CreatePipelineState(); _shader = Content::LoadAsyncInternal(TEXT("Shaders/Forward")); if (_shader == nullptr) - { return true; - } -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ForwardPass, OnShaderReloading); return false; } bool ForwardPass::setupResources() { - // Check shader if (!_shader->IsLoaded()) - { return true; - } const auto shader = _shader->GPU; // Create pipeline stages diff --git a/Source/Engine/Renderer/GBufferPass.cpp b/Source/Engine/Renderer/GBufferPass.cpp index 8048331d2..8bba190d3 100644 --- a/Source/Engine/Renderer/GBufferPass.cpp +++ b/Source/Engine/Renderer/GBufferPass.cpp @@ -48,28 +48,24 @@ bool GBufferPass::Init() _psLinearToSrgb = GPUDevice::Instance->CreatePipelineState(); // Load assets - _gBufferShader = Content::LoadAsyncInternal(TEXT("Shaders/GBuffer")); + _shader = Content::LoadAsyncInternal(TEXT("Shaders/GBuffer")); _skyModel = Content::LoadAsyncInternal(TEXT("Engine/Models/Sphere")); _boxModel = Content::LoadAsyncInternal(TEXT("Engine/Models/SimpleBox")); - if (_gBufferShader == nullptr || _skyModel == nullptr || _boxModel == nullptr) - { + if (_shader == nullptr || _skyModel == nullptr || _boxModel == nullptr) return true; - } -#if COMPILE_WITH_DEV_ENV - _gBufferShader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, GBufferPass, OnShaderReloading); return false; } bool GBufferPass::setupResources() { - if (!_gBufferShader || !_gBufferShader->IsLoaded()) + if (!_shader || !_shader->IsLoaded()) return true; - auto gbuffer = _gBufferShader->GPU; + auto shader = _shader->GPU; // Validate shader constant buffers sizes - if (gbuffer->GetCB(0)->GetSize() != sizeof(GBufferPassData)) + if (shader->GetCB(0)->GetSize() != sizeof(GBufferPassData)) { LOG(Warning, "GBuffer shader has incorrct constant buffers sizes."); return true; @@ -79,13 +75,13 @@ bool GBufferPass::setupResources() GPUPipelineState::Description psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle; if (!_psDebug->IsValid()) { - psDesc.PS = gbuffer->GetPS("PS_DebugView"); + psDesc.PS = shader->GetPS("PS_DebugView"); if (_psDebug->Init(psDesc)) return true; } if (!_psLinearToSrgb->IsValid()) { - psDesc.PS = gbuffer->GetPS("PS_LinearToSrgb"); + psDesc.PS = shader->GetPS("PS_LinearToSrgb"); if (_psLinearToSrgb->Init(psDesc)) return true; } @@ -101,7 +97,7 @@ void GBufferPass::Dispose() // Cleanup SAFE_DELETE_GPU_RESOURCE(_psDebug); SAFE_DELETE_GPU_RESOURCE(_psLinearToSrgb); - _gBufferShader = nullptr; + _shader = nullptr; _skyModel = nullptr; _boxModel = nullptr; #if GPU_ENABLE_DEVELOPMENT @@ -257,14 +253,10 @@ bool SortDecal(RenderDecalData const& a, RenderDecalData const& b) void GBufferPass::RenderDebug(RenderContext& renderContext) { - // Check if has resources loaded if (checkIfSkipPass()) return; - - // Cache data auto device = GPUDevice::Instance; auto context = device->GetMainContext(); - auto lights = _gBufferShader->GPU; GBufferPassData data; // Set constants buffer @@ -278,7 +270,7 @@ void GBufferPass::RenderDebug(RenderContext& renderContext) break; } data.ViewMode = static_cast(renderContext.View.Mode); - auto cb = lights->GetCB(0); + auto cb = _shader->GPU->GetCB(0); context->UpdateCB(cb, &data); context->BindCB(0, cb); diff --git a/Source/Engine/Renderer/GBufferPass.h b/Source/Engine/Renderer/GBufferPass.h index b927b8c04..db404dd94 100644 --- a/Source/Engine/Renderer/GBufferPass.h +++ b/Source/Engine/Renderer/GBufferPass.h @@ -13,8 +13,7 @@ class GBufferPass : public RendererPass { private: - - AssetReference _gBufferShader; + AssetReference _shader; GPUPipelineState* _psDebug = nullptr; GPUPipelineState* _psLinearToSrgb = nullptr; AssetReference _skyModel; diff --git a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp index 2ec6336ee..9dfa1bb0a 100644 --- a/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp +++ b/Source/Engine/Renderer/GI/DynamicDiffuseGlobalIllumination.cpp @@ -293,9 +293,7 @@ bool DynamicDiffuseGlobalIlluminationPass::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/GI/DDGI")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, DynamicDiffuseGlobalIlluminationPass, OnShaderReloading); } if (!_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp index ffb0a3c11..114be3fdc 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp @@ -789,9 +789,7 @@ bool GlobalSurfaceAtlasPass::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/GI/GlobalSurfaceAtlas")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, GlobalSurfaceAtlasPass, OnShaderReloading); } if (!_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp index 3c3c8e0c8..155a58d6a 100644 --- a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp +++ b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp @@ -702,9 +702,7 @@ bool GlobalSignDistanceFieldPass::setupResources() _shader = Content::LoadAsyncInternal(TEXT("Shaders/GlobalSignDistanceField")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, GlobalSignDistanceFieldPass, OnShaderReloading); } if (!_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/HistogramPass.cpp b/Source/Engine/Renderer/HistogramPass.cpp index dc3d08b3b..6a5b612ab 100644 --- a/Source/Engine/Renderer/HistogramPass.cpp +++ b/Source/Engine/Renderer/HistogramPass.cpp @@ -90,9 +90,7 @@ bool HistogramPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/Histogram")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, HistogramPass, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/LightPass.cpp b/Source/Engine/Renderer/LightPass.cpp index 34c8fb409..01094e5fa 100644 --- a/Source/Engine/Renderer/LightPass.cpp +++ b/Source/Engine/Renderer/LightPass.cpp @@ -42,10 +42,7 @@ bool LightPass::Init() _sphereModel = Content::LoadAsyncInternal(TEXT("Engine/Models/Sphere")); if (_shader == nullptr || _sphereModel == nullptr) return true; - -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, LightPass, OnShaderReloading); // Pick the format for shadow mask (rendered shadow projection into screen-space) auto format = PixelFormat::R8G8_UNorm; diff --git a/Source/Engine/Renderer/MotionBlurPass.cpp b/Source/Engine/Renderer/MotionBlurPass.cpp index f4b2f9018..51cc36c8f 100644 --- a/Source/Engine/Renderer/MotionBlurPass.cpp +++ b/Source/Engine/Renderer/MotionBlurPass.cpp @@ -62,9 +62,7 @@ bool MotionBlurPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/MotionBlur")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, MotionBlurPass, OnShaderReloading); // Prepare formats for the buffers auto format = PixelFormat::R16G16_Float; @@ -84,7 +82,6 @@ bool MotionBlurPass::Init() bool MotionBlurPass::setupResources() { - // Check shader if (!_shader->IsLoaded()) return true; const auto shader = _shader->GPU; diff --git a/Source/Engine/Renderer/PostProcessingPass.cpp b/Source/Engine/Renderer/PostProcessingPass.cpp index d6f8a0ebc..9889387ef 100644 --- a/Source/Engine/Renderer/PostProcessingPass.cpp +++ b/Source/Engine/Renderer/PostProcessingPass.cpp @@ -92,16 +92,13 @@ bool PostProcessingPass::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/PostProcessing")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, PostProcessingPass, OnShaderReloading); return false; } bool PostProcessingPass::setupResources() { - // Wait for shader if (!_shader->IsLoaded()) return true; auto shader = _shader->GPU; diff --git a/Source/Engine/Renderer/ProbesRenderer.cpp b/Source/Engine/Renderer/ProbesRenderer.cpp index 2f4a827da..8318ddfe5 100644 --- a/Source/Engine/Renderer/ProbesRenderer.cpp +++ b/Source/Engine/Renderer/ProbesRenderer.cpp @@ -260,9 +260,7 @@ bool ProbesRendererService::LazyInit() _initFailed = _shader == nullptr; if (_initFailed) return false; -#if COMPILE_WITH_DEV_ENV - _shader->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ProbesRendererService, OnShaderReloading); } if (!_shader->IsLoaded()) return true; diff --git a/Source/Engine/Renderer/ReflectionsPass.cpp b/Source/Engine/Renderer/ReflectionsPass.cpp index 7686f4f36..f2a2892d6 100644 --- a/Source/Engine/Renderer/ReflectionsPass.cpp +++ b/Source/Engine/Renderer/ReflectionsPass.cpp @@ -178,9 +178,7 @@ bool ReflectionsPass::Init() _preIntegratedGF = Content::LoadAsyncInternal(PRE_INTEGRATED_GF_ASSET_NAME); if (_shader == nullptr || _sphereModel == nullptr || _boxModel == nullptr || _preIntegratedGF == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ReflectionsPass, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/RendererPass.h b/Source/Engine/Renderer/RendererPass.h index f337b6b0e..707378a99 100644 --- a/Source/Engine/Renderer/RendererPass.h +++ b/Source/Engine/Renderer/RendererPass.h @@ -104,6 +104,12 @@ class RendererPass : public Singleton, public RendererPassBase #define REPORT_INVALID_SHADER_PASS_CB_SIZE(shader, index, dataType) LOG(Fatal, "Shader {0} has incorrect constant buffer {1} size: {2} bytes. Expected: {3} bytes", shader->ToString(), index, shader->GetCB(index)->GetSize(), sizeof(dataType)); #define CHECK_INVALID_SHADER_PASS_CB_SIZE(shader, index, dataType) ASSERT(shader && shader->GetCB(index)); if (shader->GetCB(index)->GetSize() != sizeof(dataType) && shader->GetCB(index)->GetSize() != 0) { REPORT_INVALID_SHADER_PASS_CB_SIZE(shader, index, dataType); return true; } +#if COMPILE_WITH_DEV_ENV +#define BIND_SHADER_RELOADING(shader, pass, method) shader->Reloading.Bind(this) +#else +#define BIND_SHADER_RELOADING(shader, pass, method) +#endif + #if PLATFORM_WEB // Hack to fix WebGPU limitation that requires to specify different sampler type manually (eg. to sample depth texture without filtering) void SetWebGPUTextureViewSampler(GPUTextureView* view, uint32 samplerType); diff --git a/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp b/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp index b63e9fd3d..9477c81a8 100644 --- a/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp +++ b/Source/Engine/Renderer/ScreenSpaceReflectionsPass.cpp @@ -68,9 +68,7 @@ bool ScreenSpaceReflectionsPass::Init() _preIntegratedGF = Content::LoadAsyncInternal(PRE_INTEGRATED_GF_ASSET_NAME); if (_shader == nullptr || _preIntegratedGF == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ScreenSpaceReflectionsPass, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/ShadowsPass.cpp b/Source/Engine/Renderer/ShadowsPass.cpp index 5cd7905cc..f2c5edc03 100644 --- a/Source/Engine/Renderer/ShadowsPass.cpp +++ b/Source/Engine/Renderer/ShadowsPass.cpp @@ -614,10 +614,7 @@ bool ShadowsPass::Init() _sphereModel = Content::LoadAsyncInternal(TEXT("Engine/Models/Sphere")); if (_shader == nullptr || _sphereModel == nullptr) return true; - -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, ShadowsPass, OnShaderReloading); // Select format for shadow maps _shadowMapFormat = PixelFormat::Unknown; diff --git a/Source/Engine/Renderer/Utils/BitonicSort.cpp b/Source/Engine/Renderer/Utils/BitonicSort.cpp index 001f903e8..287dac084 100644 --- a/Source/Engine/Renderer/Utils/BitonicSort.cpp +++ b/Source/Engine/Renderer/Utils/BitonicSort.cpp @@ -5,6 +5,7 @@ #include "Engine/Graphics/GPUBuffer.h" #include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPULimits.h" +#include "Engine/Renderer/GI/GlobalSurfaceAtlasPass.h" GPU_CB_STRUCT(Data { float NullItemKey; @@ -38,9 +39,7 @@ bool BitonicSort::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/BitonicSort")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, BitonicSort, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/Utils/MultiScaler.cpp b/Source/Engine/Renderer/Utils/MultiScaler.cpp index ab4930f52..e9a89b279 100644 --- a/Source/Engine/Renderer/Utils/MultiScaler.cpp +++ b/Source/Engine/Renderer/Utils/MultiScaler.cpp @@ -29,9 +29,7 @@ bool MultiScaler::Init() _shader = Content::LoadAsyncInternal(TEXT("Shaders/MultiScaler")); if (_shader == nullptr) return true; -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, MultiScaler, OnShaderReloading); return false; } diff --git a/Source/Engine/Renderer/VolumetricFogPass.cpp b/Source/Engine/Renderer/VolumetricFogPass.cpp index 542f9db51..81acd36e0 100644 --- a/Source/Engine/Renderer/VolumetricFogPass.cpp +++ b/Source/Engine/Renderer/VolumetricFogPass.cpp @@ -103,12 +103,8 @@ bool VolumetricFogPass::Init() // Load assets _shader = Content::LoadAsyncInternal(TEXT("Shaders/VolumetricFog")); if (_shader == nullptr) - { return true; - } -#if COMPILE_WITH_DEV_ENV - _shader.Get()->OnReloading.Bind(this); -#endif + BIND_SHADER_RELOADING(_shader, VolumetricFogPass, OnShaderReloading); return false; }