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]
- Material property output activeness is now deferred. Previously, it was checked during tree generation. It needs to be deferred because the tree is shared between a base material and its instances. An inactive property in base can be active in an instance.
- For FExpressionSetStructField, do not generate a previous frame field expression if the field isn't requested.
- Implemented GenerateHLSLExpression for UMaterialExpressionVolumetricCloudEmptySpaceSkippingInput and UMaterialExpressionVolumetricCloudEmptySpaceSkippingOutput.
- Fallback to preview values (if allowed) for material function inputs connected to invalid reroute nodes.
- FExpressionTextureSample now falls back to hardware derivatives if analytic derivatives fail to prepare.
- Added virtual function GetPreviewExpression to FExpression. Some expressions don't have numeric values and cannot be previewed directly. Those expressions should override this virtual function to return numeric preview expressions that represent their preview values. Also implemented the virtual function for FExpressionParameter.
- Added SeenStaticParameterValues to FEmitContext. For some reasons, users can create static parameter nodes with the same name but different default values. Use the first default value seen to keep things consistent.
- FMaterialResource::HasVertexPositionOffsetConnected() now queries cached expression data instead of the base material because the answer can change in instances.
#rb tom.holmes
[FYI] tom.holmes, jason.nadro, danny.kabrane, massimo.tristano
[CL 30770932 by jian ru in ue5-main branch]
[FYI] massimo.tristano
Original CL Desc
-----------------------------------------------------------------
Material Editor - Made material translation DDC query async to material translation (running at the same time), so that the process that completes first will be used instead of doing them both serially.
#rb dan.elksnitis
#jira UE-193797
[CL 30121479 by massimo tristano in ue5-main branch]
There were two issues:
* The material function preview was not correctly converting material attribute output.
* The cached expression were not populated, causing the IsMaterialAttributeOutput() function to not return the correct value.
Down the line, this was causing material attribute data to be connected to a float3 input causing a crash down the line.
#rb none
[FYI] sebastien.hillaire, massimo.tristano
[CL 28180761 by charles derousiers in ue5-main branch]
- Warning_CompileErrorsInMaterial was used twice for two different error messages.
- Renamed the second one to Warning_CompileErrorsInMaterialInstance, since it was an error message specific to material instances.
#rb Jon.Cain
#jira UE-195762
[CL 28033767 by jason nadro in ue5-main branch]