Optimize GPU textures and buffers uploads with a batched memory barrier

This commit is contained in:
Wojtek Figat
2025-09-03 22:11:26 +02:00
parent 212b0de29b
commit f1c4fd464a
4 changed files with 14 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
#include "GPUTask.h"
#include "GPUTasksManager.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Profiler/ProfilerCPU.h"
DefaultGPUTasksExecutor::DefaultGPUTasksExecutor()
@@ -30,6 +31,9 @@ void DefaultGPUTasksExecutor::FrameBegin()
// Default implementation performs async operations on start of the frame which is synchronized with a rendering thread
GPUTask* buffer[32];
const int32 count = GPUDevice::Instance->GetTasksManager()->RequestWork(buffer, 32);
if (count == 0)
return;
GPUMemoryPass pass(_context->GPU);
for (int32 i = 0; i < count; i++)
{
_context->Run(buffer[i]);

View File

@@ -14,6 +14,7 @@
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPipelineState.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/DynamicBuffer.h"
@@ -741,8 +742,11 @@ void Render2D::End()
}
// Flush geometry buffers
{
GPUMemoryPass pass(Context);
VB.Flush(Context);
IB.Flush(Context);
}
// Set output
Context->ResetSR();

View File

@@ -15,6 +15,7 @@
#include "Engine/Content/Content.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/RenderTask.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTargetPool.h"
@@ -939,6 +940,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co
// Send objects data to the GPU
{
PROFILE_GPU_CPU_NAMED("Update Objects");
GPUMemoryPass pass(context);
surfaceAtlasData.ObjectsBuffer.Flush(context);
surfaceAtlasData.ObjectsListBuffer.Flush(context);
}

View File

@@ -2,6 +2,7 @@
#include "Renderer.h"
#include "Engine/Graphics/GPUContext.h"
#include "Engine/Graphics/GPUPass.h"
#include "Engine/Graphics/RenderTargetPool.h"
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Graphics/RenderTask.h"
@@ -523,6 +524,7 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
JobSystem::Wait(buildObjectsBufferJob);
{
PROFILE_CPU_NAMED("FlushObjectsBuffer");
GPUMemoryPass pass(context);
for (auto& e : renderContextBatch.Contexts)
e.List->ObjectBuffer.Flush(context);
}