Refactor rendering code by moving RenderContext to a separate harder file

This commit is contained in:
2026-08-16 12:45:54 +02:00
parent 1f9f2b6a39
commit 926d9a0a0d
78 changed files with 419 additions and 375 deletions
@@ -20,6 +20,7 @@
#include "Engine/Audio/AudioListener.h"
#include "Engine/Audio/AudioSource.h"
#include "Engine/Particles/ParticleEffect.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Models/ModelInstanceEntry.h"
#include "Engine/Animations/SceneAnimations/SceneAnimationPlayer.h"
#include "Engine/Engine/EngineService.h"
@@ -10,7 +10,7 @@
#include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Audio/AudioClip.h"
#include "Engine/Audio/AudioSource.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Profiler/ProfilerMemory.h"
#include "Engine/Scripting/Scripting.h"
+1 -1
View File
@@ -8,7 +8,7 @@
#include "Engine/Content/Upgraders/ModelAssetUpgrader.h"
#include "Engine/Content/Factories/BinaryAssetFactory.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Models/ModelInstanceEntry.h"
#include "Engine/Streaming/StreamingGroup.h"
#include "Engine/Debug/Exceptions/ArgumentOutOfRangeException.h"
@@ -8,7 +8,7 @@
#include "Engine/Streaming/StreamingGroup.h"
#include "Engine/Threading/Threading.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Models/Config.h"
#include "Engine/Graphics/Models/MeshDeformation.h"
#include "Engine/Graphics/Models/ModelInstanceEntry.h"
+1
View File
@@ -15,6 +15,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/DynamicBuffer.h"
+1 -1
View File
@@ -9,7 +9,6 @@
#include "Engine/Core/Collections/BitArray.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Content/Deprecated.h"
@@ -20,6 +19,7 @@
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Profiler/ProfilerMemory.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/GlobalSignDistanceFieldPass.h"
#include "Engine/Renderer/GI/GlobalSurfaceAtlasPass.h"
#include "Engine/Serialization/Serialization.h"
+1 -1
View File
@@ -4,7 +4,7 @@
#include "GPUContext.h"
#include "PixelFormatExtensions.h"
#include "GPUDevice.h"
#include "RenderTask.h"
#include "RenderContext.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Utilities.h"
#include "Engine/Core/Math/Math.h"
+1 -1
View File
@@ -5,7 +5,7 @@
#include "GPUResourceProperty.h"
#include "GPUBufferDescription.h"
#include "PixelFormatExtensions.h"
#include "RenderTask.h"
#include "RenderContext.h"
#include "Shaders/GPUVertexLayout.h"
#include "Async/Tasks/GPUCopyResourceTask.h"
#include "Engine/Core/Utilities.h"
@@ -8,7 +8,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Renderer/DrawCall.h"
@@ -4,15 +4,15 @@
#include "MaterialShaderFeatures.h"
#include "MaterialParams.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Renderer/DrawCall.h"
#if USE_EDITOR
#include "Engine/Renderer/Lightmaps.h"
#endif
@@ -7,12 +7,12 @@
#include "Engine/Graphics/RenderView.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
PACK_STRUCT(struct DeformableMaterialShaderData {
Matrix WorldMatrix;
@@ -7,7 +7,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Renderer/DrawCall.h"
@@ -2,11 +2,10 @@
#include "MaterialShader.h"
#include "Engine/Core/Log.h"
#include "Engine/Serialization/MemoryReadStream.h"
#include "Engine/Level/LargeWorlds.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
@@ -1,7 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#include "MaterialShaderFeatures.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h"
@@ -10,7 +10,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h"
@@ -5,7 +5,7 @@
#include "Engine/Core/Log.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
@@ -9,8 +9,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Level/Scene/Lightmap.h"
#include "Engine/Renderer/DrawCall.h"
@@ -10,7 +10,7 @@
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h"
+1 -1
View File
@@ -8,7 +8,7 @@
#include "Engine/Content/Assets/Model.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Shaders/GPUVertexLayout.h"
#include "Engine/Renderer/RenderList.h"
@@ -9,7 +9,7 @@
#include "Engine/Core/Log.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Shaders/GPUVertexLayout.h"
#include "Engine/Level/Scene/Scene.h"
+106
View File
@@ -0,0 +1,106 @@
// Copyright (c) Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Collections/Array.h"
#include "Engine/Platform/CriticalSection.h"
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Renderer/RendererAllocation.h"
#include "RenderView.h"
class RenderBuffers;
class RenderList;
class SceneRenderTask;
/// <summary>
/// The high-level renderer context. Used to collect the draw calls for the scene rendering. Can be used to perform a custom rendering.
/// </summary>
API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContext
{
DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContext);
/// <summary>
/// The render buffers that contain drawing state (eg. LOD transitions) and scene buffers (eg. GBuffer, DDGI, Shadow Maps).
/// </summary>
API_FIELD() RenderBuffers* Buffers = nullptr;
/// <summary>
/// The render list that collects draw calls.
/// </summary>
API_FIELD() RenderList* List = nullptr;
/// <summary>
/// The scene rendering task that is a source of renderable objects (optional).
/// </summary>
API_FIELD() SceneRenderTask* Task = nullptr;
/// <summary>
/// The proxy render view used to synchronize objects level of detail during rendering (eg. during shadow maps rendering passes). It's optional.
/// </summary>
API_FIELD() RenderView* LodProxyView = nullptr;
/// <summary>
/// The render view.
/// </summary>
API_FIELD() RenderView View;
/// <summary>
/// The GPU access locking critical section to protect data access when performing multi-threaded rendering.
/// </summary>
static CriticalSection GPULocker;
RenderContext() = default;
RenderContext(SceneRenderTask* task) noexcept;
};
/// <summary>
/// The high-level renderer context batch that encapsulates multiple rendering requests within a single task (eg. optimize main view scene rendering and shadow projections at once).
/// </summary>
API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContextBatch
{
DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContextBatch);
/// <summary>
/// The render buffers.
/// </summary>
API_FIELD() RenderBuffers* Buffers = nullptr;
/// <summary>
/// The scene rendering task that is a source of renderable objects (optional).
/// </summary>
API_FIELD() SceneRenderTask* Task = nullptr;
/// <summary>
/// The all render views collection for the current rendering (main view, shadow projections, etc.).
/// </summary>
API_FIELD() Array<RenderContext, RendererAllocation> Contexts;
/// <summary>
/// The Job System labels to wait on, after draw calls collecting.
/// </summary>
API_FIELD() Array<int64, InlinedAllocation<8>> WaitLabels;
/// <summary>
/// Enables using async tasks via Job System when performing drawing.
/// </summary>
API_FIELD() bool EnableAsync = true;
RenderContextBatch() = default;
RenderContextBatch(SceneRenderTask* task);
RenderContextBatch(const RenderContext& context);
FORCE_INLINE RenderContext& GetMainContext()
{
return Contexts.Get()[0];
}
FORCE_INLINE const RenderContext& GetMainContext() const
{
return Contexts.Get()[0];
}
/// <summary>
/// Waits for all scheduled async jobs to complete and clears WaitLabels.
/// </summary>
void FlushWaitLabels();
};
+1
View File
@@ -2,6 +2,7 @@
#include "RenderTask.h"
#include "RenderBuffers.h"
#include "RenderContext.h"
#include "GPUDevice.h"
#include "GPUSwapChain.h"
#include "PostProcessEffect.h"
-94
View File
@@ -8,7 +8,6 @@
#include "Engine/Platform/CriticalSection.h"
#include "Engine/Scripting/ScriptingObjectReference.h"
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Renderer/RendererAllocation.h"
#include "RenderView.h"
class GPUDevice;
@@ -464,96 +463,3 @@ public:
// [SceneRenderTask]
void OnBegin(GPUContext* context) override;
};
/// <summary>
/// The high-level renderer context. Used to collect the draw calls for the scene rendering. Can be used to perform a custom rendering.
/// </summary>
API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContext
{
DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContext);
/// <summary>
/// The render buffers that contain drawing state (eg. LOD transitions) and scene buffers (eg. GBuffer, DDGI, Shadow Maps).
/// </summary>
API_FIELD() RenderBuffers* Buffers = nullptr;
/// <summary>
/// The render list that collects draw calls.
/// </summary>
API_FIELD() RenderList* List = nullptr;
/// <summary>
/// The scene rendering task that is a source of renderable objects (optional).
/// </summary>
API_FIELD() SceneRenderTask* Task = nullptr;
/// <summary>
/// The proxy render view used to synchronize objects level of detail during rendering (eg. during shadow maps rendering passes). It's optional.
/// </summary>
API_FIELD() RenderView* LodProxyView = nullptr;
/// <summary>
/// The render view.
/// </summary>
API_FIELD() RenderView View;
/// <summary>
/// The GPU access locking critical section to protect data access when performing multi-threaded rendering.
/// </summary>
static CriticalSection GPULocker;
RenderContext() = default;
RenderContext(SceneRenderTask* task) noexcept;
};
/// <summary>
/// The high-level renderer context batch that encapsulates multiple rendering requests within a single task (eg. optimize main view scene rendering and shadow projections at once).
/// </summary>
API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContextBatch
{
DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContextBatch);
/// <summary>
/// The render buffers.
/// </summary>
API_FIELD() RenderBuffers* Buffers = nullptr;
/// <summary>
/// The scene rendering task that is a source of renderable objects (optional).
/// </summary>
API_FIELD() SceneRenderTask* Task = nullptr;
/// <summary>
/// The all render views collection for the current rendering (main view, shadow projections, etc.).
/// </summary>
API_FIELD() Array<RenderContext, RendererAllocation> Contexts;
/// <summary>
/// The Job System labels to wait on, after draw calls collecting.
/// </summary>
API_FIELD() Array<int64, InlinedAllocation<8>> WaitLabels;
/// <summary>
/// Enables using async tasks via Job System when performing drawing.
/// </summary>
API_FIELD() bool EnableAsync = true;
RenderContextBatch() = default;
RenderContextBatch(SceneRenderTask* task);
RenderContextBatch(const RenderContext& context);
FORCE_INLINE RenderContext& GetMainContext()
{
return Contexts.Get()[0];
}
FORCE_INLINE const RenderContext& GetMainContext() const
{
return Contexts.Get()[0];
}
/// <summary>
/// Waits for all scheduled async jobs to complete and clears WaitLabels.
/// </summary>
void FlushWaitLabels();
};
+1 -1
View File
@@ -6,7 +6,7 @@
#include "PixelFormat.h"
#include "RenderView.h"
#include "GPUDevice.h"
#include "RenderTask.h"
#include "RenderContext.h"
#include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Assets/SkinnedModel.h"
#include "Engine/Core/Math/Packed.h"
+1 -1
View File
@@ -6,8 +6,8 @@
#include "Engine/Core/Math/Double4x4.h"
#include "Engine/Renderer/RenderList.h"
#include "RenderBuffers.h"
#include "RenderTask.h"
#include "RenderTools.h"
#include "RenderContext.h"
void RenderView::Prepare(RenderContext& renderContext)
{
+1 -1
View File
@@ -19,7 +19,7 @@
#include "Engine/Core/Collections/CollectionPoolCache.h"
#include "Engine/Core/Math/Double4x4.h"
#include "Engine/Debug/Exceptions/JsonParseException.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Physics/Physics.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Profiler/ProfilerMemory.h"
+1 -1
View File
@@ -15,7 +15,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/Models/MeshAccessor.h"
#include "Engine/Graphics/Models/MeshDeformation.h"
+1 -1
View File
@@ -12,7 +12,7 @@
#include "Editor/Editor.h"
#include "Editor/Managed/ManagedEditor.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Level/Scene/SceneRendering.h"
#else
#include "Engine/Engine/Engine.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Renderer/RenderList.h"
#include "Engine/Level/Scene/SceneRendering.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
Decal::Decal(const SpawnParams& params)
@@ -2,7 +2,7 @@
#include "DirectionalLight.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h"
@@ -8,6 +8,7 @@
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/ProbesRenderer.h"
#include "Engine/Renderer/ReflectionsPass.h"
#include "Engine/Content/Content.h"
@@ -8,7 +8,7 @@
#include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Renderer/GBufferPass.h"
@@ -4,6 +4,7 @@
#include "Engine/Content/Deprecated.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/Serialization.h"
@@ -4,6 +4,7 @@
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Level/Scene/SceneRendering.h"
PostFxVolume::PostFxVolume(const SpawnParams& params)
+1 -1
View File
@@ -9,7 +9,7 @@
#include "Engine/Renderer/GBufferPass.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
+1
View File
@@ -11,6 +11,7 @@
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/ProbesRenderer.h"
#include "Engine/Renderer/GBufferPass.h"
#include "Engine/Content/Content.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Renderer/RenderList.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Level/Scene/SceneRendering.h"
#include "Engine/Content/Assets/Material.h"
+1 -1
View File
@@ -11,7 +11,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUBuffer.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Level/Scene/SceneRendering.h"
#include "Engine/Profiler/ProfilerCPU.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Graphics/RenderView.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Content/Assets/IESProfile.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/SceneRendering.h"
+1 -1
View File
@@ -9,7 +9,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Models/MeshDeformation.h"
#include "Engine/Graphics/Shaders/GPUVertexLayout.h"
#include "Engine/Serialization/Serialization.h"
+1 -1
View File
@@ -4,7 +4,7 @@
#define SCENE_RENDERING_USE_PROFILER_PER_ACTOR 0
#include "SceneRendering.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderBuffers.h"
@@ -4,6 +4,7 @@
#include "Engine/Core/Collections/Sorting.h"
#include "Engine/Content/Assets/Model.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Particles/ParticleEffect.h"
#include "Engine/Engine/Time.h"
#include "Engine/Profiler/ProfilerCPU.h"
@@ -10,6 +10,7 @@
#include "Engine/Level/Scene/Scene.h"
#include "Engine/Engine/Time.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Graphics/RenderContext.h"
#if USE_EDITOR
#include "Editor/Editor.h"
#include "Editor/Managed/ManagedEditor.h"
+1
View File
@@ -14,6 +14,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUVertexLayout.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Profiler/ProfilerMemory.h"
+1 -1
View File
@@ -3,7 +3,7 @@
#include "Cloth.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Math/Ray.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Models/MeshAccessor.h"
#include "Engine/Graphics/Models/MeshBase.h"
@@ -10,7 +10,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
GPU_CB_STRUCT(Data {
Float4 ScreenSize;
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
bool SMAA::setupResources()
{
@@ -7,6 +7,7 @@
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/GBufferPass.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Graphics/Graphics.h"
+1 -1
View File
@@ -9,7 +9,7 @@
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
GPU_CB_STRUCT(Data {
@@ -7,7 +7,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
GPU_CB_STRUCT(Data {
+1 -1
View File
@@ -11,7 +11,7 @@
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
// This must match hlsl defines
@@ -12,7 +12,7 @@
#include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Foliage/Foliage.h"
#include "Engine/ShadowsOfMordor/Builder.Config.h"
@@ -14,8 +14,8 @@
#include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Renderer/Lightmaps.h"
@@ -11,7 +11,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Renderer/RenderList.h"
@@ -10,7 +10,7 @@
#include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/Shaders/GPUConstantBuffer.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Renderer/DrawCall.h"
#include "Engine/Renderer/RendererPass.h"
+1 -1
View File
@@ -10,7 +10,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Engine/Engine.h"
+1 -1
View File
@@ -10,7 +10,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
ForwardPass::ForwardPass()
+1
View File
@@ -14,6 +14,7 @@
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/Graphics.h"
@@ -23,6 +23,7 @@
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Level/Actors/BrushMode.h"
#include "Engine/Renderer/GBufferPass.h"
@@ -18,6 +18,7 @@
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/Async/GPUSyncPoint.h"
@@ -14,7 +14,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderTools.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Core/Collections/Sorting.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPULimits.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
+1 -1
View File
@@ -13,7 +13,7 @@
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/PostProcessSettings.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Shaders/GPUShader.h"
#include "Engine/Engine/Time.h"
@@ -7,6 +7,7 @@
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Engine/Time.h"
#include "Engine/Graphics/GPUPass.h"
+1 -1
View File
@@ -23,7 +23,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Scripting/ScriptingObjectReference.h"
#include "Engine/Tools/TextureTool/TextureTool.h"
#include "Engine/Threading/ThreadPoolTask.h"
+1 -1
View File
@@ -11,7 +11,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Level/Actors/EnvironmentProbe.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Core/Collections/Sorting.h"
#include "Engine/Graphics/Materials/IMaterial.h"
#include "Engine/Graphics/Materials/MaterialShader.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPULimits.h"
+1
View File
@@ -10,6 +10,7 @@
struct FLAXENGINE_API RenderSetup
{
RenderingUpscaleLocation UpscaleLocation = RenderingUpscaleLocation::DuringAntiAliasing;
float RenderScale = 1.0f;
bool UseShadows = false;
bool UseMotionVectors = false;
bool UseTemporalAAJitter = false;
+229 -213
View File
@@ -6,6 +6,7 @@
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/PostProcessEffect.h"
#include "Engine/Engine/EngineService.h"
#include "GBufferPass.h"
@@ -71,7 +72,7 @@ public:
RendererService RendererServiceInstance;
void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderContextBatch& renderContextBatch);
void RenderInner(RenderContext& renderContext, RenderContextBatch& renderContextBatch);
bool RendererService::Init()
{
@@ -181,7 +182,7 @@ void RenderAntiAliasingPass(RenderContext& renderContext, GPUTexture* input, GPU
}
}
void RenderLightBuffer(const SceneRenderTask* task, GPUContext* context, RenderContext& renderContext, GPUTexture* lightBuffer, const GPUTextureDescription& tempDesc)
void RenderLightBuffer(GPUContext* context, RenderContext& renderContext, GPUTexture* lightBuffer, const GPUTextureDescription& tempDesc)
{
context->ResetRenderTarget();
auto colorGradingLUT = ColorGradingPass::Instance()->RenderLUT(renderContext);
@@ -196,8 +197,8 @@ void RenderLightBuffer(const SceneRenderTask* task, GPUContext* context, RenderC
Swap(lightBuffer, tempBuffer);
}
RenderTargetPool::Release(lightBuffer);
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(renderContext.Task->GetOutputView());
context->SetViewportAndScissors(renderContext.Task->GetOutputViewport());
context->Draw(tempBuffer);
RenderTargetPool::Release(tempBuffer);
}
@@ -278,7 +279,7 @@ void Renderer::Render(SceneRenderTask* task)
// Perform the actual rendering
task->OnPreRender(context, renderContext);
RenderInner(task, renderContext, renderContextBatch);
RenderInner(renderContext, renderContextBatch);
task->OnPostRender(context, renderContext);
#if USE_EDITOR
@@ -362,216 +363,233 @@ void Renderer::DrawActors(RenderContext& renderContext, const Array<Actor*>& cus
}
}
void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderContextBatch& renderContextBatch)
static void Setup(GPUContext* context, RenderContext& renderContext)
{
auto context = GPUDevice::Instance->GetMainContext();
PROFILE_CPU_NAMED("Setup");
auto* graphicsSettings = GraphicsSettings::Get();
auto& view = renderContext.View;
ASSERT(renderContext.Buffers && renderContext.Buffers->GetWidth() > 0);
const bool isGBufferDebug = GBufferPass::IsDebugView(renderContext.View.Mode);
const int32 screenWidth = renderContext.Buffers->GetWidth();
const int32 screenHeight = renderContext.Buffers->GetHeight();
// Perform postFx volumes blending and query before rendering
task->CollectPostFxVolumes(renderContext);
renderContext.Task->CollectPostFxVolumes(renderContext);
renderContext.List->BlendSettings();
{
auto aaMode = EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::AntiAliasing) ? renderContext.List->Settings.AntiAliasing.Mode : AntialiasingMode::None;
if (aaMode == AntialiasingMode::TemporalAntialiasing && view.IsOrthographicProjection())
if (aaMode == AntialiasingMode::TemporalAntialiasing && renderContext.View.IsOrthographicProjection())
aaMode = AntialiasingMode::None; // TODO: support TAA in ortho projection (see RenderView::Prepare to jitter projection matrix better)
renderContext.List->Settings.AntiAliasing.Mode = aaMode;
}
// Initialize setup
// Initialize render setup
RenderSetup& setup = renderContext.List->Setup;
const bool isGBufferDebug = GBufferPass::IsDebugView(renderContext.View.Mode);
setup.UpscaleLocation = renderContext.Task->UpscaleLocation;
if (setup.UpscaleLocation == RenderingUpscaleLocation::DuringAntiAliasing && renderContext.List->Settings.AntiAliasing.Mode != AntialiasingMode::TemporalAntialiasing)
setup.UpscaleLocation = RenderingUpscaleLocation::AfterAntiAliasing; // Fall-back when AA doesn't support uplscaling
PRAGMA_DISABLE_DEPRECATION_WARNINGS
setup.RenderScale = renderContext.Task->RenderingPercentage * renderContext.Task->RenderScale;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
setup.UseShadows = !isGBufferDebug && EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Shadows) && ShadowsPass::Instance()->IsReady();
switch (renderContext.View.Mode)
{
PROFILE_CPU_NAMED("Setup");
const int32 screenWidth = renderContext.Buffers->GetWidth();
const int32 screenHeight = renderContext.Buffers->GetHeight();
setup.UpscaleLocation = renderContext.Task->UpscaleLocation;
if (setup.UpscaleLocation == RenderingUpscaleLocation::DuringAntiAliasing && renderContext.List->Settings.AntiAliasing.Mode != AntialiasingMode::TemporalAntialiasing)
setup.UpscaleLocation = RenderingUpscaleLocation::AfterAntiAliasing; // Fall-back when AA doesn't support uplscaling
setup.UseShadows = !isGBufferDebug && EnumHasAnyFlags(view.Flags, ViewFlags::Shadows) && ShadowsPass::Instance()->IsReady();
switch (renderContext.View.Mode)
{
case ViewMode::QuadOverdraw:
case ViewMode::Emissive:
case ViewMode::LightmapUVsDensity:
case ViewMode::GlobalSurfaceAtlas:
case ViewMode::GlobalSDF:
case ViewMode::GlobalSDFOverdraw:
case ViewMode::MaterialComplexity:
case ViewMode::VertexColors:
case ViewMode::LightOverlap:
setup.UseShadows = false;
break;
}
if (screenWidth < 16 || screenHeight < 16 || renderContext.Task->IsCameraCut || isGBufferDebug || renderContext.View.Mode == ViewMode::NoPostFx)
setup.UseMotionVectors = false;
else
{
const MotionBlurSettings& motionBlurSettings = renderContext.List->Settings.MotionBlur;
const ScreenSpaceReflectionsSettings ssrSettings = renderContext.List->Settings.ScreenSpaceReflections;
setup.UseMotionVectors =
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::MotionBlur) && motionBlurSettings.Enabled && motionBlurSettings.Scale > ZeroTolerance) ||
renderContext.View.Mode == ViewMode::MotionVectors ||
(ssrSettings.Intensity > ZeroTolerance && ssrSettings.TemporalEffect && EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SSR)) ||
renderContext.List->Settings.AntiAliasing.Mode == AntialiasingMode::TemporalAntialiasing;
}
setup.UseTemporalAAJitter = renderContext.List->Settings.AntiAliasing.Mode == AntialiasingMode::TemporalAntialiasing;
setup.UseGlobalSurfaceAtlas = renderContext.View.Mode == ViewMode::GlobalSurfaceAtlas ||
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Reflections) && renderContext.List->Settings.GlobalIllumination.Reflections == ReflectionsMode::DDGI) ||
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::GI) && renderContext.List->Settings.GlobalIllumination.Mode == GlobalIlluminationMode::DDGI);
setup.UseGlobalSDF = (graphicsSettings->EnableGlobalSDF && EnumHasAnyFlags(view.Flags, ViewFlags::GlobalSDF)) ||
renderContext.View.Mode == ViewMode::GlobalSDF ||
renderContext.View.Mode == ViewMode::GlobalSDFOverdraw ||
setup.UseGlobalSurfaceAtlas;
setup.UseVolumetricFog = (view.Flags & ViewFlags::Fog) != ViewFlags::None;
// Disable TAA jitter in debug modes
switch (renderContext.View.Mode)
{
case ViewMode::Unlit:
case ViewMode::Diffuse:
case ViewMode::Normals:
case ViewMode::Depth:
case ViewMode::Emissive:
case ViewMode::AmbientOcclusion:
case ViewMode::Metalness:
case ViewMode::Roughness:
case ViewMode::Specular:
case ViewMode::SpecularColor:
case ViewMode::SubsurfaceColor:
case ViewMode::ShadingModel:
case ViewMode::GlobalSDF:
case ViewMode::GlobalSDFOverdraw:
case ViewMode::GlobalSurfaceAtlas:
case ViewMode::LightmapUVsDensity:
case ViewMode::MaterialComplexity:
case ViewMode::Wireframe:
case ViewMode::NoPostFx:
case ViewMode::VertexColors:
case ViewMode::QuadOverdraw:
case ViewMode::LightOverlap:
setup.UseTemporalAAJitter = false;
break;
}
// Customize setup (by postfx or custom gameplay effects)
renderContext.Task->SetupRender(renderContext);
for (PostProcessEffect* e : renderContext.List->PostFx)
e->PreRender(context, renderContext);
case ViewMode::QuadOverdraw:
case ViewMode::Emissive:
case ViewMode::LightmapUVsDensity:
case ViewMode::GlobalSurfaceAtlas:
case ViewMode::GlobalSDF:
case ViewMode::GlobalSDFOverdraw:
case ViewMode::MaterialComplexity:
case ViewMode::VertexColors:
case ViewMode::LightOverlap:
setup.UseShadows = false;
break;
}
if (screenWidth < 16 || screenHeight < 16 || renderContext.Task->IsCameraCut || isGBufferDebug || renderContext.View.Mode == ViewMode::NoPostFx)
setup.UseMotionVectors = false;
else
{
const MotionBlurSettings& motionBlurSettings = renderContext.List->Settings.MotionBlur;
const ScreenSpaceReflectionsSettings ssrSettings = renderContext.List->Settings.ScreenSpaceReflections;
setup.UseMotionVectors =
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::MotionBlur) && motionBlurSettings.Enabled && motionBlurSettings.Scale > ZeroTolerance) ||
renderContext.View.Mode == ViewMode::MotionVectors ||
(ssrSettings.Intensity > ZeroTolerance && ssrSettings.TemporalEffect && EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::SSR)) ||
renderContext.List->Settings.AntiAliasing.Mode == AntialiasingMode::TemporalAntialiasing;
}
setup.UseTemporalAAJitter = renderContext.List->Settings.AntiAliasing.Mode == AntialiasingMode::TemporalAntialiasing;
setup.UseGlobalSurfaceAtlas = renderContext.View.Mode == ViewMode::GlobalSurfaceAtlas ||
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::Reflections) && renderContext.List->Settings.GlobalIllumination.Reflections == ReflectionsMode::DDGI) ||
(EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::GI) && renderContext.List->Settings.GlobalIllumination.Mode == GlobalIlluminationMode::DDGI);
setup.UseGlobalSDF = (graphicsSettings->EnableGlobalSDF && EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::GlobalSDF)) ||
renderContext.View.Mode == ViewMode::GlobalSDF ||
renderContext.View.Mode == ViewMode::GlobalSDFOverdraw ||
setup.UseGlobalSurfaceAtlas;
setup.UseVolumetricFog = (renderContext.View.Flags & ViewFlags::Fog) != ViewFlags::None;
// Disable TAA jitter in debug modes
switch (renderContext.View.Mode)
{
case ViewMode::Unlit:
case ViewMode::Diffuse:
case ViewMode::Normals:
case ViewMode::Depth:
case ViewMode::Emissive:
case ViewMode::AmbientOcclusion:
case ViewMode::Metalness:
case ViewMode::Roughness:
case ViewMode::Specular:
case ViewMode::SpecularColor:
case ViewMode::SubsurfaceColor:
case ViewMode::ShadingModel:
case ViewMode::GlobalSDF:
case ViewMode::GlobalSDFOverdraw:
case ViewMode::GlobalSurfaceAtlas:
case ViewMode::LightmapUVsDensity:
case ViewMode::MaterialComplexity:
case ViewMode::Wireframe:
case ViewMode::NoPostFx:
case ViewMode::VertexColors:
case ViewMode::QuadOverdraw:
case ViewMode::LightOverlap:
setup.UseTemporalAAJitter = false;
break;
}
// Customize setup (by postfx or custom gameplay effects)
renderContext.Task->SetupRender(renderContext);
for (PostProcessEffect* e : renderContext.List->PostFx)
e->PreRender(context, renderContext);
// Final render view preparations
renderContext.View.Prepare(renderContext);
}
static void CollectDrawCalls(GPUContext* context, RenderContext& renderContext, RenderContextBatch& renderContextBatch)
{
PROFILE_CPU_NAMED("Collect Draw Calls");
RenderSetup& setup = renderContext.List->Setup;
renderContext.View.Pass = DrawPass::GBuffer | DrawPass::Forward | DrawPass::Distortion;
if (setup.UseMotionVectors)
renderContext.View.Pass |= DrawPass::MotionVectors;
renderContextBatch.GetMainContext() = renderContext; // Sync render context in batch with the current value
renderContext.List->PreDraw(context, renderContextBatch);
LightPass::Instance()->SetupLights(renderContext, renderContextBatch);
if (setup.UseShadows)
ShadowsPass::Instance()->SetupShadows(renderContext, renderContextBatch);
#if GPU_ENABLE_DEVELOPMENT
GBufferPass::Instance()->PreOverrideDrawCalls(renderContext);
#endif
// Dispatch drawing (via JobSystem - multiple job batches for every scene)
JobSystem::SetJobStartingOnDispatch(false);
renderContext.Task->OnCollectDrawCalls(renderContextBatch, SceneRendering::DrawCategory::SceneDraw);
renderContext.Task->OnCollectDrawCalls(renderContextBatch, SceneRendering::DrawCategory::SceneDrawAsync);
if (setup.UseGlobalSDF)
GlobalSignDistanceFieldPass::Instance()->OnCollectDrawCalls(renderContextBatch);
if (setup.UseGlobalSurfaceAtlas)
GlobalSurfaceAtlasPass::Instance()->OnCollectDrawCalls(renderContextBatch);
if (EnumHasAllFlags(renderContext.View.Flags, ViewFlags::CustomPostProcess))
{
for (PostProcessEffect* fx : renderContext.List->PostFx)
fx->CollectDrawCalls(renderContextBatch);
}
// Wait for async jobs to finish
JobSystem::SetJobStartingOnDispatch(true);
renderContextBatch.FlushWaitLabels();
// Perform custom post-scene drawing (eg. GPU dispatches used by VFX)
for (int32 i = 0; i < renderContextBatch.Contexts.Count(); i++)
renderContextBatch.Contexts[i].List->DrainDelayedDraws(context, renderContextBatch, i);
renderContext.List->PostDraw(context, renderContextBatch);
#if GPU_ENABLE_DEVELOPMENT
GBufferPass::Instance()->OverrideDrawCalls(renderContext);
#endif
}
static void ProcessDrawCalls(GPUContext* context, RenderContext& renderContext, RenderContextBatch& renderContextBatch)
{
PROFILE_CPU_NAMED("Process Draw Calls");
// Utility that handles async jobs for a specific rendering routines in async
struct DrawCallsProcessor
{
RenderContextBatch& RenderContextBatch;
Pair<DrawCallsListType, bool> MainContextSorting[5] =
{
// Draw List + Reverse Distance sorting
ToPair(DrawCallsListType::GBuffer, false),
ToPair(DrawCallsListType::GBufferNoDecals, false),
ToPair(DrawCallsListType::Forward, true),
ToPair(DrawCallsListType::Distortion, false),
ToPair(DrawCallsListType::MotionVectors, false),
};
void BuildObjectsBufferJob(int32 index)
{
RenderContextBatch.Contexts[index].List->BuildObjectsBuffer();
}
void SortDrawCallsJob(int32 index)
{
RenderContext& renderContext = RenderContextBatch.GetMainContext();
if (index < ARRAY_COUNT(MainContextSorting))
{
// Main context sorting
RenderSetup& setup = renderContext.List->Setup;
auto sorting = MainContextSorting[index];
if (sorting.First == DrawCallsListType::MotionVectors && !setup.UseMotionVectors)
return;
renderContext.List->SortDrawCalls(renderContext, sorting.Second, sorting.First);
}
else
{
// Shadow context sorting
auto& shadowContext = RenderContextBatch.Contexts[index - ARRAY_COUNT(MainContextSorting)];
shadowContext.List->SortDrawCalls(shadowContext, false, DrawCallsListType::Depth, DrawPass::Depth);
shadowContext.List->SortDrawCalls(shadowContext, false, shadowContext.List->ShadowDepthDrawCallsList, renderContext.List->DrawCalls, DrawCallsListType::Depth, DrawPass::Depth);
}
}
} processor = { renderContextBatch };
// Dispatch async jobs
Function<void(int32)> func;
func.Bind<DrawCallsProcessor, &DrawCallsProcessor::BuildObjectsBufferJob>(&processor);
const int64 buildObjectsBufferJob = JobSystem::Dispatch(func, renderContextBatch.Contexts.Count());
func.Bind<DrawCallsProcessor, &DrawCallsProcessor::SortDrawCallsJob>(&processor);
const int64 sortDrawCallsJob = JobSystem::Dispatch(func, ARRAY_COUNT(DrawCallsProcessor::MainContextSorting) + renderContextBatch.Contexts.Count());
// Upload objects buffers to the GPU
JobSystem::Wait(buildObjectsBufferJob);
{
PROFILE_CPU_NAMED("FlushObjectsBuffer");
GPUMemoryPass pass(context);
for (auto& e : renderContextBatch.Contexts)
e.List->ObjectBuffer.Flush(context);
}
// Wait for async jobs to finish
// TODO: use per-pass wait labels (eg. don't wait for shadow pass draws sorting until ShadowPass needs it)
JobSystem::Wait(sortDrawCallsJob);
}
void RenderInner(RenderContext& renderContext, RenderContextBatch& renderContextBatch)
{
auto context = GPUDevice::Instance->GetMainContext();
ASSERT(renderContext.Buffers && renderContext.Buffers->GetWidth() > 0);
// Setup rendering
RenderSetup& setup = renderContext.List->Setup;
Setup(context, renderContext);
// Build batch of render contexts (main view and shadow projections)
{
PROFILE_CPU_NAMED("Collect Draw Calls");
view.Pass = DrawPass::GBuffer | DrawPass::Forward | DrawPass::Distortion;
if (setup.UseMotionVectors)
view.Pass |= DrawPass::MotionVectors;
renderContextBatch.GetMainContext() = renderContext; // Sync render context in batch with the current value
renderContext.List->PreDraw(context, renderContextBatch);
LightPass::Instance()->SetupLights(renderContext, renderContextBatch);
if (setup.UseShadows)
ShadowsPass::Instance()->SetupShadows(renderContext, renderContextBatch);
#if GPU_ENABLE_DEVELOPMENT
GBufferPass::Instance()->PreOverrideDrawCalls(renderContext);
#endif
// Dispatch drawing (via JobSystem - multiple job batches for every scene)
JobSystem::SetJobStartingOnDispatch(false);
task->OnCollectDrawCalls(renderContextBatch, SceneRendering::DrawCategory::SceneDraw);
task->OnCollectDrawCalls(renderContextBatch, SceneRendering::DrawCategory::SceneDrawAsync);
if (setup.UseGlobalSDF)
GlobalSignDistanceFieldPass::Instance()->OnCollectDrawCalls(renderContextBatch);
if (setup.UseGlobalSurfaceAtlas)
GlobalSurfaceAtlasPass::Instance()->OnCollectDrawCalls(renderContextBatch);
if (EnumHasAllFlags(renderContext.View.Flags, ViewFlags::CustomPostProcess))
{
for (PostProcessEffect* fx : renderContext.List->PostFx)
fx->CollectDrawCalls(renderContextBatch);
}
// Wait for async jobs to finish
JobSystem::SetJobStartingOnDispatch(true);
renderContextBatch.FlushWaitLabels();
// Perform custom post-scene drawing (eg. GPU dispatches used by VFX)
for (int32 i = 0; i < renderContextBatch.Contexts.Count(); i++)
renderContextBatch.Contexts[i].List->DrainDelayedDraws(context, renderContextBatch, i);
renderContext.List->PostDraw(context, renderContextBatch);
#if GPU_ENABLE_DEVELOPMENT
GBufferPass::Instance()->OverrideDrawCalls(renderContext);
#endif
}
CollectDrawCalls(context, renderContext, renderContextBatch);
// Process draw calls (sorting, objects buffer building)
{
PROFILE_CPU_NAMED("Process Draw Calls");
// Utility that handles async jobs for a specific rendering routines in async
struct DrawCallsProcessor
{
RenderContextBatch& RenderContextBatch;
Pair<DrawCallsListType, bool> MainContextSorting[5] =
{
// Draw List + Reverse Distance sorting
ToPair(DrawCallsListType::GBuffer, false),
ToPair(DrawCallsListType::GBufferNoDecals, false),
ToPair(DrawCallsListType::Forward, true),
ToPair(DrawCallsListType::Distortion, false),
ToPair(DrawCallsListType::MotionVectors, false),
};
void BuildObjectsBufferJob(int32 index)
{
RenderContextBatch.Contexts[index].List->BuildObjectsBuffer();
}
void SortDrawCallsJob(int32 index)
{
RenderContext& renderContext = RenderContextBatch.GetMainContext();
if (index < ARRAY_COUNT(MainContextSorting))
{
// Main context sorting
RenderSetup& setup = renderContext.List->Setup;
auto sorting = MainContextSorting[index];
if (sorting.First == DrawCallsListType::MotionVectors && !setup.UseMotionVectors)
return;
renderContext.List->SortDrawCalls(renderContext, sorting.Second, sorting.First);
}
else
{
// Shadow context sorting
auto& shadowContext = RenderContextBatch.Contexts[index - ARRAY_COUNT(MainContextSorting)];
shadowContext.List->SortDrawCalls(shadowContext, false, DrawCallsListType::Depth, DrawPass::Depth);
shadowContext.List->SortDrawCalls(shadowContext, false, shadowContext.List->ShadowDepthDrawCallsList, renderContext.List->DrawCalls, DrawCallsListType::Depth, DrawPass::Depth);
}
}
} processor = { renderContextBatch };
// Dispatch async jobs
Function<void(int32)> func;
func.Bind<DrawCallsProcessor, &DrawCallsProcessor::BuildObjectsBufferJob>(&processor);
const int64 buildObjectsBufferJob = JobSystem::Dispatch(func, renderContextBatch.Contexts.Count());
func.Bind<DrawCallsProcessor, &DrawCallsProcessor::SortDrawCallsJob>(&processor);
const int64 sortDrawCallsJob = JobSystem::Dispatch(func, ARRAY_COUNT(DrawCallsProcessor::MainContextSorting) + renderContextBatch.Contexts.Count());
// Upload objects buffers to the GPU
JobSystem::Wait(buildObjectsBufferJob);
{
PROFILE_CPU_NAMED("FlushObjectsBuffer");
GPUMemoryPass pass(context);
for (auto& e : renderContextBatch.Contexts)
e.List->ObjectBuffer.Flush(context);
}
// Wait for async jobs to finish
// TODO: use per-pass wait labels (eg. don't wait for shadow pass draws sorting until ShadowPass needs it)
JobSystem::Wait(sortDrawCallsJob);
}
ProcessDrawCalls(context, renderContext, renderContextBatch);
// Get the light accumulation buffer
auto outputFormat = renderContext.Buffers->GetOutputFormat();
@@ -587,8 +605,8 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
{
QuadOverdrawPass::Instance()->Render(renderContext, context, lightBuffer->View());
context->ResetRenderTarget();
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(renderContext.Task->GetOutputView());
context->SetViewportAndScissors(renderContext.Task->GetOutputViewport());
context->Draw(lightBuffer);
RenderTargetPool::Release(lightBuffer);
return;
@@ -636,8 +654,8 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
#endif
{
context->ResetRenderTarget();
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(renderContext.Task->GetOutputView());
context->SetViewportAndScissors(renderContext.Task->GetOutputViewport());
context->Draw(lightBuffer->View());
RenderTargetPool::Release(lightBuffer);
return;
@@ -650,11 +668,11 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
AmbientOcclusionPass::Instance()->Render(renderContext);
// Check if use custom view mode
if (isGBufferDebug)
if (GBufferPass::IsDebugView(renderContext.View.Mode))
{
context->ResetRenderTarget();
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(renderContext.Task->GetOutputView());
context->SetViewportAndScissors(renderContext.Task->GetOutputViewport());
GBufferPass::Instance()->RenderDebug(renderContext);
RenderTargetPool::Release(lightBuffer);
return;
@@ -676,7 +694,7 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
}
if (renderContext.View.Mode == ViewMode::LightBuffer)
{
RenderLightBuffer(task, context, renderContext, lightBuffer, tempDesc);
RenderLightBuffer(context, renderContext, lightBuffer, tempDesc);
return;
}
@@ -693,7 +711,7 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
renderContext.List->Settings.CameraArtifacts.GrainAmount = 0.0f;
renderContext.List->Settings.CameraArtifacts.ChromaticDistortion = 0.0f;
renderContext.List->Settings.CameraArtifacts.VignetteIntensity = 0.0f;
RenderLightBuffer(task, context, renderContext, lightBuffer, tempDesc);
RenderLightBuffer(context, renderContext, lightBuffer, tempDesc);
return;
}
@@ -735,8 +753,8 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
// Check if skip post-processing
if (renderContext.View.Mode == ViewMode::NoPostFx || renderContext.View.Mode == ViewMode::Wireframe)
{
context->SetRenderTarget(task->GetOutputView());
context->SetViewportAndScissors(task->GetOutputViewport());
context->SetRenderTarget(renderContext.Task->GetOutputView());
context->SetViewportAndScissors(renderContext.Task->GetOutputViewport());
if (!Graphics::GammaColorSpace)
GBufferPass::Instance()->DrawLinearToSrgb(renderContext, frameBuffer);
else
@@ -752,10 +770,8 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
renderContext.List->RunCustomPostFxPass(context, renderContext, PostProcessEffectLocation::BeforePostProcessingPass, frameBuffer, tempBuffer);
// Temporal Anti-Aliasing (goes before post processing)
PRAGMA_DISABLE_DEPRECATION_WARNINGS
bool useUpscaling = task->RenderingPercentage * task->RenderScale < 1.0f;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
const Viewport outputViewport = task->GetOutputViewport();
bool useUpscaling = setup.RenderScale < 1.0f;
const Viewport outputViewport = renderContext.Task->GetOutputViewport();
if (renderContext.List->Settings.AntiAliasing.Mode == AntialiasingMode::TemporalAntialiasing)
{
if (useUpscaling && setup.UpscaleLocation == RenderingUpscaleLocation::DuringAntiAliasing)
@@ -817,7 +833,7 @@ PRAGMA_ENABLE_DEPRECATION_WARNINGS
)
{
// PostFx -> Back Buffer
GPUTextureView* outputView = task->GetOutputView();
GPUTextureView* outputView = renderContext.Task->GetOutputView();
PostProcessingPass::Instance()->Render(renderContext, frameBuffer, outputView, outputViewport, colorGradingLUT);
RenderTargetPool::Release(tempBuffer);
RenderTargetPool::Release(frameBuffer);
@@ -853,7 +869,7 @@ PRAGMA_ENABLE_DEPRECATION_WARNINGS
#endif
// Anti Aliasing
GPUTextureView* outputView = task->GetOutputView();
GPUTextureView* outputView = renderContext.Task->GetOutputView();
if (!renderContext.List->HasAnyPostFx(renderContext, PostProcessEffectLocation::AfterAntiAliasingPass, MaterialPostFxLocation::AfterAntiAliasingPass) && !useUpscaling)
{
// AA -> Back Buffer
@@ -12,7 +12,7 @@
#include "Engine/Content/Content.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/GPUContext.h"
+1 -1
View File
@@ -5,7 +5,7 @@
#include "VolumetricFogPass.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/PixelFormatExtensions.h"
#include "Engine/Content/Content.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "DrawCall.h"
#include "GI/DynamicDiffuseGlobalIllumination.h"
#include "Engine/Graphics/Graphics.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
+1 -1
View File
@@ -13,7 +13,7 @@
#include "Engine/Physics/PhysicsBackend.h"
#include "Engine/Content/Deprecated.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Level/Scene/Scene.h"
#include "Engine/Profiler/ProfilerCPU.h"
+1
View File
@@ -10,6 +10,7 @@
#include "Engine/Graphics/Textures/GPUTexture.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Core/Math/OrientedBoundingBox.h"
#include "Engine/Level/Scene/Scene.h"
#if USE_EDITOR
+1 -1
View File
@@ -7,7 +7,7 @@
#include "Engine/Content/Content.h"
#include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Assets/MaterialInstance.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Level/Actors/Camera.h"
#include "Engine/Serialization/Serialization.h"
+1 -1
View File
@@ -6,7 +6,7 @@
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/Models/Types.h"
#include "Engine/Graphics/RenderView.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderContext.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTools.h"
#include "Engine/Graphics/Shaders/GPUVertexLayout.h"
@@ -3093,6 +3093,7 @@ namespace Flax.Build.Bindings
else
throw new Exception("Not supported Non-POD type " + apiType);
CppIncludeFiles.Add("Engine/Scripting/ManagedCLR/MClass.h");
CppIncludeFiles.Add(apiType.File.Name);
// Get the full typename with nested parent prefix
var fullName = apiType.FullNameNative;