Commit Graph

186 Commits

Author SHA1 Message Date
zach bethel
14d84c3bb0 Re-enabled render command pipes by default.
[CL 27834049 by zach bethel in ue5-main branch]
2023-09-13 11:51:59 -04:00
zach bethel
b036d46bef Fixed server build break.
[CL 27768599 by zach bethel in ue5-main branch]
2023-09-11 16:10:46 -04:00
zach bethel
63a64c0791 Reworked render command pipes sync scopes to only start recording when a pipe was previously recording.
- Fixes issue where pipes are stopped, then a sync occurs and pipes are erroneously started up again.
 - Removed start / stop from end of frame updates.

#jira UE-194553

[CL 27767719 by zach bethel in ue5-main branch]
2023-09-11 15:52:47 -04:00
zach bethel
fd5f008daf Disabled render command pipes to investigate crash.
#jira none

[CL 27716051 by zach bethel in ue5-main branch]
2023-09-08 12:47:52 -04:00
zach bethel
715c4c3851 Fixed build break
[CL 27693415 by zach bethel in ue5-main branch]
2023-09-07 18:37:59 -04:00
zach bethel
6473b91df9 Hardened thread safety of render command pipe system and added ability to sync specific pipes.
- Added additional sync scopes to handle VT standalone path.

#jira UE-194136, FORT-648678, UE-194553, PLAY-12828

[CL 27691097 by zach bethel in ue5-main branch]
2023-09-07 17:51:23 -04:00
zach bethel
1ee43df79f Added validation to issue an ensure when a sync scope is used during end of frame updates.
[CL 27530932 by zach bethel in ue5-main branch]
2023-08-31 14:26:55 -04:00
zach bethel
869dbfa725 Removed ensure to check against render commands being enqueued from the rendering thread timeline, as this there are some valid cases in (shader compilation).
#jira UE-193448

[CL 27488816 by zach bethel in ue5-main branch]
2023-08-30 13:02:13 -04:00
zach bethel
fb4fed1103 Re-enabled render command pipes and fixed Skinning / Niagara race conditions.
- Added flags to render command pipe definitions to allow for disabling in code.
 - Release the TFunction after each command to match behavior of the render command tasks.

[CL 27412478 by zach bethel in ue5-main branch]
2023-08-28 11:31:06 -04:00
christopher waters
5ae57ccf85 The majority of FRenderCommandPipeRegistry is not needed in server builds.
#rb marc.audy

[CL 27224087 by christopher waters in ue5-main branch]
2023-08-18 19:12:59 -04:00
wojciech krywult
572fd58df2 RenderCore: Fixed crashes that could occur while using DumpGPU console command if writes to the drive are slow.
#rb David.Harvey
#jira UE-160213
#rnx

[CL 27107689 by wojciech krywult in ue5-main branch]
2023-08-15 12:55:53 -04:00
zach bethel
cfd832379c Temporarily disabled async render command pipes to investigate crash.
[CL 27102857 by zach bethel in ue5-main branch]
2023-08-15 10:50:52 -04:00
zach bethel
b5b17e2ae7 Render Command Pipe Implementation and API
Render Command Pipes dedicated asynchronous task pipes for render commands. Users can easily define new pipes and enqueue commands into them. Pipes can be synchronized using a scope to run serial render commands on the render thread, but initially pipes cannot be synchronized individually with each other. Render command overhead is reduced by recording command lambdas into MPSC queues which are serviced by the task graph; both for pipes and for the render thread. This reduces the task overhead as commands are no longer 1-to-1 with tasks.

Pipe behavior is controlled with new CVars. `r.RenderCommandPipeMode` controls overall behavior:
 0 - Legacy render thread tasks,
 1 - Render thread MPSC queue,
 2 - Render thread and async pipe MPSC queues.

To define a Render Command Pipe, use DEFINE_RENDER_COMMAND_PIPE(MyPipe), or DECLARE_RENDER_COMMAND_PIPE(MyPipe, MODULE_API) to declare an extern reference.

Enqueue a command into the pipe like so:

ENQUEUE_RENDER_COMMAND(MyCommand)(UE::RenderCommandPipe::MyPipe, [] (FRHICommandList&) {}).

Omitting a pipe will fallback to the 'general' pipe which is the render thread.

Eventually pipes need to be synced back to the general pipe for scene renders and other GPU work. On the game thread timeline, use UE::RenderCommandPipe::FSyncScope to synchronize the pipes. This waits for pipes and disables recording of new pipe commands until the scope completes, at which point pipe recording is restarted. This creates a 'sync point', so render commands issued prior to a sync scope will be waited on at the start of the scope, and render commands issued after the scope ends will not be able to start until the render thread finishes processing prior commands.

#rb christopher.waters, luke.thatcher

[CL 27074956 by zach bethel in ue5-main branch]
2023-08-14 12:52:45 -04:00
bob tellez
afd943db61 [Backout] - CL27042396 and 27048615
[FYI] zach.bethel
Original CL Desc
-----------------------------------------------------------------
Render Command Pipe Implementation and API

Render Command Pipes dedicated asynchronous task pipes for render commands. Users can easily define new pipes and enqueue commands into them. Pipes can be synchronized using a scope to run serial render commands on the render thread, but initially pipes cannot be synchronized individually with each other. Render command overhead is reduced by recording command lambdas into MPSC queues which are serviced by the task graph; both for pipes and for the render thread. This reduces the task overhead as commands are no longer 1-to-1 with tasks.

Pipe behavior is controlled with new CVars. `r.RenderCommandPipeMode` controls overall behavior:
 0 - Legacy render thread tasks,
 1 - Render thread MPSC queue,
 2 - Render thread and async pipe MPSC queues.

To define a Render Command Pipe, use DEFINE_RENDER_COMMAND_PIPE(MyPipe), or DECLARE_RENDER_COMMAND_PIPE(MyPipe, MODULE_API) to declare an extern reference.

Enqueue a command into the pipe like so:

ENQUEUE_RENDER_COMMAND(MyCommand)(UE::RenderCommandPipe::MyPipe, [] (FRHICommandList&) {}).

Omitting a pipe will fallback to the 'general' pipe which is the render thread.

Eventually pipes need to be synced back to the general pipe for scene renders and other GPU work. On the game thread timeline, use UE::RenderCommandPipe::FSyncScope to synchronize the pipes. This waits for pipes and disables recording of new pipe commands until the scope completes, at which point pipe recording is restarted. This creates a 'sync point', so render commands issued prior to a sync scope will be waited on at the start of the scope, and render commands issued after the scope ends will not be able to start until the render thread finishes processing prior commands.

#rb christopher.waters, luke.thatcher

[CL 27054009 by bob tellez in ue5-main branch]
2023-08-11 20:05:11 -04:00
zach bethel
2d143afc83 Render Command Pipe Implementation and API
Render Command Pipes dedicated asynchronous task pipes for render commands. Users can easily define new pipes and enqueue commands into them. Pipes can be synchronized using a scope to run serial render commands on the render thread, but initially pipes cannot be synchronized individually with each other. Render command overhead is reduced by recording command lambdas into MPSC queues which are serviced by the task graph; both for pipes and for the render thread. This reduces the task overhead as commands are no longer 1-to-1 with tasks.

Pipe behavior is controlled with new CVars. `r.RenderCommandPipeMode` controls overall behavior:
 0 - Legacy render thread tasks,
 1 - Render thread MPSC queue,
 2 - Render thread and async pipe MPSC queues.

To define a Render Command Pipe, use DEFINE_RENDER_COMMAND_PIPE(MyPipe), or DECLARE_RENDER_COMMAND_PIPE(MyPipe, MODULE_API) to declare an extern reference.

Enqueue a command into the pipe like so:

ENQUEUE_RENDER_COMMAND(MyCommand)(UE::RenderCommandPipe::MyPipe, [] (FRHICommandList&) {}).

Omitting a pipe will fallback to the 'general' pipe which is the render thread.

Eventually pipes need to be synced back to the general pipe for scene renders and other GPU work. On the game thread timeline, use UE::RenderCommandPipe::FSyncScope to synchronize the pipes. This waits for pipes and disables recording of new pipe commands until the scope completes, at which point pipe recording is restarted. This creates a 'sync point', so render commands issued prior to a sync scope will be waited on at the start of the scope, and render commands issued after the scope ends will not be able to start until the render thread finishes processing prior commands.

#rb christopher.waters, luke.thatcher

[CL 27042459 by zach bethel in ue5-main branch]
2023-08-11 15:51:26 -04:00
zach bethel
18bbb90ba2 Converted FRenderCommandFence to use new task graph API.
#jira none
#rb  Andriy.Tylychko

[CL 27039518 by zach bethel in ue5-main branch]
2023-08-11 14:55:43 -04:00
jon cain
27d55af4ed Backout of CL 25764433 to temporarily resolve render resource crash under certain circumstances when pushing changes in UEFN.
#rb Jason.Nadro, Andriy.Tylychko, Sebastian.Thomeczek

[CL 26580177 by jon cain in ue5-main branch]
2023-07-25 13:30:09 -04:00
Andriy Tylychko
ca6b75d7c2 RenderCommandFence and its bundling:
on shutdown, AppPreExit() is covered by StartRenderCommandFenceBundler()/StoptRenderCommandFenceBundler() to minimise the number of RT tasks as there're lots of render fences in this region. waiting on any of fences stops bundling, e.g. by FlushRenderingCommands(). As this happens early in AppPreExit(), this effectively disables bundling and we get a ton of RT tasks that drives mem usage up.
This CL adds FlushRenderCommandFenceBundler() and uses it in FRenderCommandFence::Wait() instead of StopRenderCommandFenceBundler() to keep bundling enabled
#rb danny.couture
#preflight 647a11ea8417d79259a9944b

[CL 25764394 by Andriy Tylychko in ue5-main branch]
2023-06-02 12:20:02 -04:00
mihnea balta
5c24794294 Fix crashes caused by processing the deferred deletion queue at the wrong time, especially when running without an RHI thread.
Since FRHICommandListImmediate::ImmediateFlush() was calling FlushPendingDeletes() after executing the current list of commands, the lambda enqueued by that function was actually running as part of the next command list. Besides unnecessarily extending resource lifetimes, this also meant that the new command list started by flushing the deferred deletion queue, so anything added directly in there (instead of via another enqueued command) would be deleted before the commands were executed on the GPU. This was very easy to reproduce with -norhithread on DX12, because texture unlock operations add the staging buffer to the deferred deletion queue immediately, instead of enqueuing a command to do it, so the staging buffers were gone by the time the GPU tried to copy from them.

This changelist adds a boolean to RHISubmitCommandLists() which is true when we're flushing the immediate command list with the FlushRHIThreadFlushResources mode, so that the RHI can process the deletion queue internally after submission, instead of doing it in RHIPerFrameRHIFlushComplete(). I didn't want to move RHIPerFrameRHIFlushComplete() itself to another point in the timeline, because old RHIs (D3D11 and OpenGL) use that for other purposes, and it seems unwise to alter their behavior (e.g. D3D11 wants to resolve timing queries in there with a blocking wait, and running that at the end of the current command list would introduce a CPU/GPU sync point).

Also:
* deprecated FRHIResource::FlushPendingDeletes(), since all it does is call FlushPendingDeletes() on the command list being passed in, and code outside of the RHI really shouldn't be doing that.
* made FlushPendingDeleteRHIResources_RenderThread() flush the immediate command list instead of calling FlushPendingDeletes() directly

#jira UE-184426
#rnx
#preflight https://horde.devtools.epicgames.com/job/6455194d023fe5d3ad8faa64
#rb Luke.Thatcher

[CL 25423894 by mihnea balta in ue5-main branch]
2023-05-11 06:25:32 -04:00
Andriy Tylychko
c93c982ef7 removed excessive FGraphEvent instance from FRenderCommandFence::BeginFence(). The change uses FGraphEvent returned by the task instead of allocating a new one and manually "completing" it inside a task.
an excessive FGraphEvent instance is still used in `bSyncToRHIAndGPU` branch, and can be similarly improved. though this would require massive changes and won't bring any measurable perf improvements as this happens once a frame.
#preflight 6453d0234d593c0b428d7888
#rb danny.couture, luke.thatcher

[CL 25336380 by Andriy Tylychko in ue5-main branch]
2023-05-04 11:51:17 -04:00
eric mcdaniel
95dae15c35 Ensure GMainThreadBlockedOnRenderThread is properly initialized
#rb none, trivial
#jira none
#preflight 64406811a9720904a6c89f76

[CL 25130815 by eric mcdaniel in ue5-main branch]
2023-04-20 13:16:45 -04:00
jason walter
1e7abf939f Show margin time on game and render threads.
#jira UE-181526
#rb simon.therriault
#preflight 643449eb1d61ecec3b08f7ae

[CL 25006972 by jason walter in ue5-main branch]
2023-04-12 10:33:13 -04:00
PJ Kack
a629b19433 Remove obsolete temp code from 2016 to SuspendAsyncLoading when using FSuspendRenderingThread (a feature that in itself is only used on iOS).
#jira none
#rb per.larsson
#rnx
#preflight 642147bb7a393e211acad6c6

[CL 24800090 by PJ Kack in ue5-main branch]
2023-03-27 03:44:52 -04:00
christopher waters
1f21b73b25 Ran IWYU on RHI and RenderCore, private only.
#preflight 63d358c85c69f453c1f79c37

[CL 23889591 by christopher waters in ue5-main branch]
2023-01-27 14:54:10 -05:00
christopher waters
c6c2200520 Adding includes before cleaning up RHI dependencies.
[CL 23888475 by christopher waters in ue5-main branch]
2023-01-27 14:17:39 -05:00