Commit Graph

112 Commits

Author SHA1 Message Date
Luke Thatcher
10cdd4a111 Merging //UE5/Dev-ParallelRendering/... (up to CL 30965645) to //UE5/Main/... (base CL 30962637)
Significant refactor of RHI command list management and submission, and RHI breadcrumbs / RenderGraph (RDG) scopes, to allow for parallel translation of most RHI command lists.
See individual changelists in //UE5/Dev-ParallelRendering for details. A summary of the changes is as follows:

This work's primary goal was to allow as many RHI command lists as possible to be parallel translated, to make more efficient use of many-core systems. To achieve this:
 - The submission code paths for the immediate and parallel RHI command lists have been merged into a single function: FRHICommandListExecutor::Submit().
 - A "dispatch thread" (which is simply a series of chained task graph tasks) is used to decide which command lists are batched together in a single parallel translate job.
 - Individual command lists can disable parallel translate, which forces them to be executed on the RHI thread. This happens automatically if an RHI command list performs an operation that is not thread safe (e.g. buffer lock, or low-level resource transition).

One of the primary blockers for parallel translation was the RHI breadcrumb system, and the way RDG builds scopes. This was also refactored to remove these limitations:
 - RDG could only push/pop events on the immediate command list, which resulted in parallel and immediate work being interleaved, breaking any opportunity for parallelism.
 - Platform RHI implementations of breadcrumbs (e.g. in D3D12 RHI) was not correct across multiple RHI contexts. Push/pop operations aren't necessarily balanced within any one RHI context given that RDG builds "parallel pass sets" containing arbitrary ranges of renderer passes.

A summary of the new RHI breadcrumb system is as follows:
 - A tree of breadcrumb nodes is built by the render thread and RDG. Each node contains the node name, and pointers to the parent and next nodes. When fully built, the nodes form a depth-first linked list which is used for traversing the tree for GPU crash debugging.
 - The memory for breadcrumb nodes is provided by ref-counted allocator objects. These allocators are pipelined through the RHI, allowing the platform RHI implementation to extend their lifetime for GPU crash debugging purposes.
 - RHIPushEvent / RHIPopEvent have been removed, replaced with RHIBeginBreadcrumbGPU / RHIEndBreadcrumbGPU. Platform RHIs implement these functions to perform GPU immediate writes using the unique ID of each node, for tracking GPU progress.
 - Format string arguments are captured by-value to remove the cost of string formatting while building the breadcrumb tree. String formatting only occurs when the actual formatted string is required (e.g. during GPU crash breadcrumb stack traversal, or when calling platform GPU profiling APIs).

RenderGraph scopes have been simplified:
 - The separate scope trees / arrays of ops have been combined. There is now a single tree of RDG scopes containing all types.
 - Each RDG pass holds a pointer to the scope it was created under.
 - BeginCPU / EndCPU is called on each RDG scope as the various RDG threads enter / exit them. This allows us to mark-up each worker thread with the relevant Unreal Insights scopes.

Other changes include:
 - Fixes for bugs uncovered when parallel translate was enabled.
 - Adjusted platform affinities necessary due to the new layout of thread tasks in the renderer.
 - Refactored RHI draw call stats to better fit the new pipeline design.

#rb jeannoe.morissette, zach.bethel
#jira UE-139543

[CL 30973133 by Luke Thatcher in ue5-main branch]
2024-01-29 12:47:28 -05:00
steve robb
f029468598 Fixed up a lot of bool-taking container resize functions to take EAllowShrinking instead.
[CL 30729174 by steve robb in ue5-main branch]
2024-01-19 16:41:35 -05:00
zach bethel
ddf1de47b9 Fixed unity build break.
#jira none

[CL 27380699 by zach bethel in ue5-main branch]
2023-08-25 12:44:10 -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
96b0631948 Fixed RHI validation errors with buffer creation.
#jira UE-189559

[CL 26236170 by zach bethel in ue5-main branch]
2023-06-26 12:21:05 -04:00
zach bethel
61a256b156 More command list conversions. Streaming buffers, vertex factories, and TUniformBufferRef.
[CL 26217320 by zach bethel in ue5-main branch]
2023-06-23 16:03:17 -04:00
zach bethel
aa1b0c680f Deprecated non-command list RHI methods.
- RHICreate{Vertex, Index, Structured}Buffer
 - RHICreate{ShaderResource, UnorderedAccess}View
 - RHIUpdateUniformBuffer
 - Various initialization / locking methods for helper buffer types in RHIUtilities.h

The goal is to continue to force resource creation through command lists to avoid surprises with moving things off the render thread.

#rb christopher.waters

[CL 26183242 by zach bethel in ue5-main branch]
2023-06-22 11:08:27 -04:00
zach bethel
a7a9029b20 Deprecated InitRHI() in favor of InitRHI(FRHICommandListBase&).
#rb mihnea.balta, luke.thatcher, christopher.waters

[CL 26097009 by zach bethel in ue5-main branch]
2023-06-19 13:56:56 -04:00
zach bethel
a9a5fa39db Deprecated non-command list variant of InitResource and UpdateResource. Patched the engine to pass command lists through. Follow-up CL's will refactor individual locations to thread command lists through the various callstacks, but that was done very judiciously in this CL to reduce risk.
#rb mihnea.balta, christopher.waters

[CL 25953623 by zach bethel in ue5-main branch]
2023-06-13 11:46:40 -04:00
zach bethel
d026651f30 Initialize global texture resources before other global resources.
#jira UE-188452

[CL 25941406 by zach bethel in ue5-main branch]
2023-06-12 17:54:08 -04:00
zach bethel
6d657e92f1 Resubmitted InitDynamicRHI refactor with fixes for startup initialization.
[CL 25897584 by zach bethel in ue5-main branch]
2023-06-09 12:58:33 -04:00
zach bethel
f0efa3cf35 Undo refactor of InitDynamicRHI as there is a memory leak.
[CL 25872730 by zach bethel in ue5-main branch]
2023-06-08 11:34:52 -04:00
zach bethel
f84151acfa Deprecated {Init, Release}DynamicRHI in favor of just {Init, Release}RHI.
#rb luke.thatcher, christopher.waters, mihnea.balta

[CL 25859166 by zach bethel in ue5-main branch]
2023-06-07 17:33:37 -04:00
zach bethel
4c8c48b2cc Use a simple recursive mutex for render resource list to fix race condition when adding resources concurrently.
#preflight 646e7e5c1b241f0748600d6a

[CL 25624446 by zach bethel in ue5-main branch]
2023-05-25 13:32:58 -04:00
mihnea balta
6cc52ffd89 Removing incorrect LLM tag from BeginInitResource() introduced in CL 22230608.
Forcing a tag here is incorrect, as it will override the tag that's supposed to be set by the owner of the resource. For example, this attributed StaticMesh memory to the generic SceneRender tag.

#rb massimo.tristano
#preflight skip
#jira none
#rnx

[CL 25231351 by mihnea balta in ue5-main branch]
2023-04-28 09:47:16 -04:00
zach bethel
ade4e07b7a Refactored the global dynamic vertex buffer to support parallel usage.
#preflight 6441799027014596f3c9b1b0
#rb christopher.waters, luke.thatcher

[CL 25146384 by zach bethel in ue5-main branch]
2023-04-21 11:31:42 -04:00
Josie Yang
2f00d270c9 Define FName as static before passing to UE_TRACE_METADATA_SCOPE_ASSET_FNAME as FName lookup has performance impact.
Also rename AssetName to OwnerName to better describe what is stored.

#jira UE-167815
#rb Kenzo.Terelst
#preflight 641484d0691c5ebc159b2a5b

[CL 24714010 by Josie Yang in ue5-main branch]
2023-03-20 07:02:50 -04:00
Josie Yang
245b52ff57 Insight asset meta data tracking on DX12 buffers
#jira UE-167815
#rb Kenzo.Terelst
#preflight 640f3db928026468d93d1aa7

[CL 24652481 by Josie Yang in ue5-main branch]
2023-03-15 07:11:22 -04:00
josie yang
2289056981 Fix incorrect auto merge of CL23966262 causing duplicated OwnerName
[CL 23966886 by josie yang in ue5-main branch]
2023-02-02 08:46:21 -05:00
josie yang
c133d226e8 Integrate RenderResourceViewer from //UE5/Main
Part3 - Integrate CL23347911 as edigrate
Add owner column to Render Resource Viewer, add owner path name tracking to skeletal & static mesh buffers
with conflict resolve modifications in RawIndexBuffer.cpp/h, RenderResource.cpp/h, RHIResources.h

#preflight 63dab3e2cf5296811729fecd

[CL 23966872 by josie yang in ue5-main branch]
2023-02-02 08:45:12 -05: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
5c36939f3a Dependency cleanup around RenderCore.h includes.
#preflight 63c1b21d1a06fc6105ef31c4

[CL 23688227 by christopher waters in ue5-main branch]
2023-01-13 17:25:01 -05:00
Josie Yang
f14eb91ef7 Remove game thread check on RHI resource set owner name. EngineTest can call on FSkinWeightVertexBuffer from other thread on consoles
#jira UE-172334
#preflight skip

[CL 23526201 by Josie Yang in ue5-main branch]
2022-12-15 08:52:27 -05:00