diff --git a/Source/Engine/Foliage/Foliage.h b/Source/Engine/Foliage/Foliage.h index a71eba59e..533251767 100644 --- a/Source/Engine/Foliage/Foliage.h +++ b/Source/Engine/Foliage/Foliage.h @@ -169,7 +169,7 @@ private: }; typedef Array> DrawCallsList; - typedef Dictionary BatchedDrawCalls; + typedef Dictionary BatchedDrawCalls; void DrawInstance(RenderContext& renderContext, FoliageInstance& instance, FoliageType& type, Model* model, int32 lod, float lodDitherFactor, DrawCallsList* drawCallsLists, BatchedDrawCalls& result) const; void DrawCluster(RenderContext& renderContext, FoliageCluster* cluster, FoliageType& type, DrawCallsList* drawCallsLists, BatchedDrawCalls& result) const; #else diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h index 9a677e613..30260e66e 100644 --- a/Source/Engine/Graphics/RenderTask.h +++ b/Source/Engine/Graphics/RenderTask.h @@ -8,6 +8,7 @@ #include "Engine/Platform/CriticalSection.h" #include "Engine/Scripting/ScriptingObjectReference.h" #include "Engine/Scripting/ScriptingType.h" +#include "Engine/Renderer/RendererAllocation.h" #include "PostProcessBase.h" #include "RenderView.h" @@ -448,7 +449,7 @@ API_STRUCT(NoDefault) struct RenderContextBatch /// /// The all render views collection for the current rendering (main view, shadow projections, etc.). /// - API_FIELD() Array Contexts; + API_FIELD() Array Contexts; RenderContextBatch() = default; RenderContextBatch(SceneRenderTask* task); diff --git a/Source/Engine/Level/Scene/SceneRendering.cpp b/Source/Engine/Level/Scene/SceneRendering.cpp index f0d23a1ff..e5b6e209b 100644 --- a/Source/Engine/Level/Scene/SceneRendering.cpp +++ b/Source/Engine/Level/Scene/SceneRendering.cpp @@ -48,7 +48,7 @@ void SceneRendering::Draw(RenderContextBatch& renderContextBatch, DrawCategory c auto& list = Actors[(int32)category]; // Setup frustum data - Array frustumsData; + Array frustumsData; BoundingFrustum* frustums = &view.CullingFrustum; int32 frustumsCount = renderContextBatch.Contexts.Count(); if (frustumsCount != 1) diff --git a/Source/Engine/Renderer/RenderList.cpp b/Source/Engine/Renderer/RenderList.cpp index d37451bec..92dafa21e 100644 --- a/Source/Engine/Renderer/RenderList.cpp +++ b/Source/Engine/Renderer/RenderList.cpp @@ -110,7 +110,7 @@ void RendererSkyLightData::SetupLightData(LightData* data, bool useShadow) const data->RadiusInv = 1.0f / Radius; } -void* RenderListAllocation::Allocate(uintptr size) +void* RendererAllocation::Allocate(uintptr size) { void* result = nullptr; for (int32 i = 0; i < MemPool.Count(); i++) @@ -129,7 +129,7 @@ void* RenderListAllocation::Allocate(uintptr size) return result; } -void RenderListAllocation::Free(void* ptr, uintptr size) +void RendererAllocation::Free(void* ptr, uintptr size) { MemPool.Add({ ptr, size }); } @@ -326,7 +326,7 @@ void RenderList::RunCustomPostFxPass(GPUContext* context, RenderContext& renderC } } -bool RenderList::HasAnyPostFx(RenderContext& renderContext, PostProcessEffectLocation postProcess) const +bool RenderList::HasAnyPostFx(const RenderContext& renderContext, PostProcessEffectLocation postProcess) const { if (renderContext.View.Flags & ViewFlags::CustomPostProcess) { @@ -342,7 +342,7 @@ bool RenderList::HasAnyPostFx(RenderContext& renderContext, PostProcessEffectLoc return false; } -bool RenderList::HasAnyPostFx(RenderContext& renderContext, MaterialPostFxLocation materialPostFx) const +bool RenderList::HasAnyPostFx(const RenderContext& renderContext, MaterialPostFxLocation materialPostFx) const { for (int32 i = 0; i < Settings.PostFxMaterials.Materials.Count(); i++) { diff --git a/Source/Engine/Renderer/RenderList.h b/Source/Engine/Renderer/RenderList.h index cb5b78640..b4048eca0 100644 --- a/Source/Engine/Renderer/RenderList.h +++ b/Source/Engine/Renderer/RenderList.h @@ -8,6 +8,7 @@ #include "Engine/Graphics/DynamicBuffer.h" #include "Engine/Scripting/ScriptingObject.h" #include "DrawCall.h" +#include "RendererAllocation.h" enum class StaticFlags; class RenderBuffers; @@ -220,89 +221,10 @@ struct DrawBatch } }; -class RenderListAllocation -{ -public: - static FLAXENGINE_API void* Allocate(uintptr size); - static FLAXENGINE_API void Free(void* ptr, uintptr size); - - template - class Data - { - T* _data = nullptr; - uintptr _size; - - public: - FORCE_INLINE Data() - { - } - - FORCE_INLINE ~Data() - { - if (_data) - RenderListAllocation::Free(_data, _size); - } - - FORCE_INLINE T* Get() - { - return _data; - } - - FORCE_INLINE const T* Get() const - { - return _data; - } - - FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const - { - capacity = capacity ? capacity * 2 : 64; - if (capacity < minCapacity) - capacity = minCapacity; - return capacity; - } - - FORCE_INLINE void Allocate(uint64 capacity) - { - _size = capacity * sizeof(T); - _data = (T*)RenderListAllocation::Allocate(_size); - } - - FORCE_INLINE void Relocate(uint64 capacity, int32 oldCount, int32 newCount) - { - T* newData = capacity != 0 ? (T*)RenderListAllocation::Allocate(capacity * sizeof(T)) : nullptr; - if (oldCount) - { - if (newCount > 0) - Memory::MoveItems(newData, _data, newCount); - Memory::DestructItems(_data, oldCount); - } - if (_data) - RenderListAllocation::Free(_data, _size); - _data = newData; - _size = capacity * sizeof(T); - } - - FORCE_INLINE void Free() - { - if (_data) - { - RenderListAllocation::Free(_data, _size); - _data = nullptr; - } - } - - FORCE_INLINE void Swap(Data& other) - { - ::Swap(_data, other._data); - ::Swap(_size, other._size); - } - }; -}; - struct BatchedDrawCall { DrawCall DrawCall; - Array Instances; + Array Instances; }; /// diff --git a/Source/Engine/Renderer/RendererAllocation.h b/Source/Engine/Renderer/RendererAllocation.h new file mode 100644 index 000000000..af0d6f1f8 --- /dev/null +++ b/Source/Engine/Renderer/RendererAllocation.h @@ -0,0 +1,85 @@ +// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. + +#pragma once + +#include "Engine/Core/Memory/Memory.h" +#include "Engine/Core/Types/BaseTypes.h" + +class RendererAllocation +{ +public: + static FLAXENGINE_API void* Allocate(uintptr size); + static FLAXENGINE_API void Free(void* ptr, uintptr size); + + template + class Data + { + T* _data = nullptr; + uintptr _size; + + public: + FORCE_INLINE Data() + { + } + + FORCE_INLINE ~Data() + { + if (_data) + RendererAllocation::Free(_data, _size); + } + + FORCE_INLINE T* Get() + { + return _data; + } + + FORCE_INLINE const T* Get() const + { + return _data; + } + + FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const + { + capacity = capacity ? capacity * 2 : 64; + if (capacity < minCapacity) + capacity = minCapacity; + return capacity; + } + + FORCE_INLINE void Allocate(uint64 capacity) + { + _size = capacity * sizeof(T); + _data = (T*)RendererAllocation::Allocate(_size); + } + + FORCE_INLINE void Relocate(uint64 capacity, int32 oldCount, int32 newCount) + { + T* newData = capacity != 0 ? (T*)RendererAllocation::Allocate(capacity * sizeof(T)) : nullptr; + if (oldCount) + { + if (newCount > 0) + Memory::MoveItems(newData, _data, newCount); + Memory::DestructItems(_data, oldCount); + } + if (_data) + RendererAllocation::Free(_data, _size); + _data = newData; + _size = capacity * sizeof(T); + } + + FORCE_INLINE void Free() + { + if (_data) + { + RendererAllocation::Free(_data, _size); + _data = nullptr; + } + } + + FORCE_INLINE void Swap(Data& other) + { + ::Swap(_data, other._data); + ::Swap(_size, other._size); + } + }; +}; diff --git a/Source/Engine/Renderer/VolumetricFogPass.cpp b/Source/Engine/Renderer/VolumetricFogPass.cpp index 6d6b804c5..6a25ebf5a 100644 --- a/Source/Engine/Renderer/VolumetricFogPass.cpp +++ b/Source/Engine/Renderer/VolumetricFogPass.cpp @@ -588,8 +588,8 @@ void VolumetricFogPass::Render(RenderContext& renderContext) GPUTextureView* localShadowedLightScattering = nullptr; { // Get lights to render - Array> pointLights; - Array> spotLights; + Array> pointLights; + Array> spotLights; for (int32 i = 0; i < renderContext.List->PointLights.Count(); i++) { const auto& light = renderContext.List->PointLights[i];