Optimize GPU memory usage in Editor when viewport is inactive
This commit is contained in:
@@ -34,7 +34,7 @@ RenderBuffers::~RenderBuffers()
|
||||
_resources.ClearDelete();
|
||||
}
|
||||
|
||||
void RenderBuffers::Prepare()
|
||||
void RenderBuffers::ReleaseUnusedMemory()
|
||||
{
|
||||
// Auto release temporal buffer if not used for some time
|
||||
const uint64 frameIndex = Engine::FrameCount;
|
||||
|
||||
@@ -100,9 +100,9 @@ public:
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Prepares buffers for rendering a scene. Called before rendering so other parts can reuse calculated value.
|
||||
/// Frees unused buffers to reduce memory usage for certain drawing effects that are state-dependant but unused for multiple frames.
|
||||
/// </summary>
|
||||
void Prepare();
|
||||
void ReleaseUnusedMemory();
|
||||
|
||||
/// <summary>
|
||||
/// Requests the half-resolution depth to be prepared for the current frame.
|
||||
|
||||
@@ -46,9 +46,9 @@ void RenderTask::DrawAll()
|
||||
for (auto task : Tasks)
|
||||
{
|
||||
if (task->CanDraw())
|
||||
{
|
||||
task->OnDraw();
|
||||
}
|
||||
else
|
||||
task->OnIdle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ void RenderTask::OnDraw()
|
||||
OnEnd(context);
|
||||
}
|
||||
|
||||
void RenderTask::OnIdle()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderTask::OnBegin(GPUContext* context)
|
||||
{
|
||||
Begin(this, context);
|
||||
@@ -325,6 +329,9 @@ void SceneRenderTask::OnPostRender(GPUContext* context, RenderContext& renderCon
|
||||
OnCollectDrawCalls(renderContextBatch, SceneRendering::PostRender);
|
||||
|
||||
PostRender(context, renderContext);
|
||||
|
||||
if (Buffers)
|
||||
Buffers->ReleaseUnusedMemory();
|
||||
}
|
||||
|
||||
Viewport SceneRenderTask::GetViewport() const
|
||||
@@ -424,6 +431,14 @@ bool SceneRenderTask::CanDraw() const
|
||||
return RenderTask::CanDraw();
|
||||
}
|
||||
|
||||
void SceneRenderTask::OnIdle()
|
||||
{
|
||||
RenderTask::OnIdle();
|
||||
|
||||
if (Buffers)
|
||||
Buffers->ReleaseUnusedMemory();
|
||||
}
|
||||
|
||||
MainRenderTask::MainRenderTask(const SpawnParams& params)
|
||||
: SceneRenderTask(params)
|
||||
{
|
||||
|
||||
@@ -112,10 +112,15 @@ public:
|
||||
API_PROPERTY() virtual bool CanDraw() const;
|
||||
|
||||
/// <summary>
|
||||
/// Called by graphics device to draw this task. Can be used to invoke task rendering nested inside another task - use on own risk!
|
||||
/// Called by graphics device to draw this task.
|
||||
/// </summary>
|
||||
API_FUNCTION() virtual void OnDraw();
|
||||
|
||||
/// <summary>
|
||||
/// Called by graphics device to idle task that has not been selected for drawing this frame (CanDraw returned false). Can be used to recycle cached memory if task is idle for many frames in a row.
|
||||
/// </summary>
|
||||
virtual void OnIdle();
|
||||
|
||||
/// <summary>
|
||||
/// Called on task rendering begin.
|
||||
/// </summary>
|
||||
@@ -407,6 +412,7 @@ public:
|
||||
// [RenderTask]
|
||||
bool Resize(int32 width, int32 height) override;
|
||||
bool CanDraw() const override;
|
||||
void OnIdle() override;
|
||||
void OnBegin(GPUContext* context) override;
|
||||
void OnRender(GPUContext* context) override;
|
||||
void OnEnd(GPUContext* context) override;
|
||||
|
||||
Reference in New Issue
Block a user