Commit Graph

131 Commits

Author SHA1 Message Date
tiago costa
1e44dca468 Improved HeightField object management.
- this fixes a number of crashes and issue with heightfields missing from global distance field when heightfield shadows are enabled.

- Context:
  - Heightfields are used by two techniques using different approaches:
    - Global Distance Field (r.AOGlobalDistanceField.Heightfield) - heightfields are composed one by one into Global SDF so there's no need for bindless resources or atlas.
    - Height Field Shadows (r.HeightFieldShadowing) - since all heightfields data must be accessible in the same dispatch, heightfields descriptiors are stored in structured buffers (HeightFieldObjectBuffers) and textures are copied to an atlas (GHeightFieldTextureAtlas/GHFVisibilityTextureAtlas).
  - FDistanceFieldSceneData::HeightfieldPrimitives is an array of relevant heighfield primitives.
  - For each primitive, DistanceFieldInstanceIndices contains the index of the corresponding entry in HeightfieldPrimitives array.
    - The same DistanceFieldInstanceIndices is also used to manage distance fields (there's an assumption that a primitive can have a distance field or a height field, but not both).
  - The codepath to manage the HeightFieldObjectBuffers and GHeightFieldTextureAtlas/GHFVisibilityTextureAtlas is only enabled when ShouldPrepareHeightFieldScene() returns true.
  - There's limited space in the atlas so it's not guaranteed that every loaded heightfield fits in the atlas.

- Issues with existing approach:
  - When the codepath to manage HeightFieldObjectBuffers/Atlases is enabled, only the heighfields that fit in the atlas are added to FDistanceFieldSceneData::HeightfieldPrimitives.
    - this means that in some cases not every loaded heighfield will be composed into the global distance field (since only primitives in HeightfieldPrimitives are included).
    - there are also a few bugs with the code that can result in crashes.
  - Heighfields that fail the inital allocation are not added to HeightfieldPrimitives even after space becomes available in the atlas.
    - the atlas itself correctly retries to fit failed allocations when space becomes available, however the higher level managment code doesn't handle this.

- Changes:
  - all heightfield primitives are added to FDistanceFieldSceneData::HeightfieldPrimitives regardless of whether they fit in atlas or not.
    - this way all heightfields will be included in global distance field
  - added a new field, bInAtlas, to entries in HeightFieldObjectBuffers.
  - during Height Field Shadows culling pass, heightfields not present in atlas are skipped.
  - significantly refactored relevant codepaths to simplify logic.

#rb Krzysztof.Narkowicz, Jian.Ru
#preflight 6372c0ef953c19d4353ad211

[CL 23131399 by tiago costa in ue5-main branch]
2022-11-14 20:42:26 -05:00
krzysztof narkowicz
398c268d59 Lumen - don't access DistanceFieldData when tracking primitives. Instead just cache it inside bSupportsDistanceFieldRepresentation.
[CL 23071980 by krzysztof narkowicz in ue5-main branch]
2022-11-10 01:15:46 -05:00
tiago costa
f048ed220f Clear DistanceFieldInstanceIndices when resetting HeightfieldPrimitives to prevent stale indices.
#preflight skip
#rb Jian.Ru, Krzysztof.Narkowicz

[CL 23069447 by tiago costa in ue5-main branch]
2022-11-09 20:54:49 -05:00
bob tellez
dad4b92133 #UE Qucik fix for memory corruption in DistanceFieldObjectManagement index logic
[FYI] krzysztof.narkowicz

[CL 22918374 by bob tellez in ue5-main branch]
2022-11-02 11:58:42 -04:00
krzysztof narkowicz
3c426fbff0 Global Distance Field - fixed missing updates to Global SDF when there are more than one SceneRender() calls per frame by removing UpdateTrackingBounds optimization:
* We update primitives once per scene inside a SceneRender()
* GlobalSDF is cached per view
* GlobalSDF update is based on whether current primitive is in UpdateTrackingBounds, where UpdateTrackingBounds are built from current views
* If render gets called with a non main view (like a cubemap capture) then scene primitive will be updated, but GlobalSDF for the main view won't

[FYI] Tiago.Costa

[CL 22710474 by krzysztof narkowicz in ue5-main branch]
2022-10-22 07:12:02 -04:00
krzysztof narkowicz
5c86522ed4 Added AffectIndirectLightingWhileHidden property to primitive component.
Following the existing CastHiddenShadow, AffectIndirectLightingWhileHidden allows hidden primitives to be injected into GI and reflections. This is useful as an extra art direction knob to create cheap invisible area lights through GI.

* Only implemented in Lumen
* Will inject {Visible=false, AffectIndirectLightingWhileHidden=true} primitives into both distance field scene and ray tracing scene (TLAS)

#rb Daniel.Wright, Yuriy.ODonnell

[CL 22412764 by krzysztof narkowicz in ue5-main branch]
2022-10-07 19:44:48 -04:00
zach bethel
f92a99b5a6 Fix for distance field atlas validation error.
#preflight 6324c97d8131e92d65f90c67
#jira UE-163910

[CL 22063974 by zach bethel in ue5-main branch]
2022-09-16 20:25:49 -04:00
zach bethel
f69b6fbc27 Fixed validation errors due to async compute distance field targets.
#jira UE-163453
#preflight 631faf4be07c4dc0b134f5e6

[CL 21985233 by zach bethel in ue5-main branch]
2022-09-13 12:31:35 -04:00
krzysztof narkowicz
7a5bf8c610 Lumen Software Ray Tracing - replaced voxel lighting volume with an object grid, which allows to sample surface cache directly instead of a low resolution and leaky resampled voxel representation.
* Higher resolution reflections
* No leaking from voxel resampling
* Better emissive representation as previously voxel lighting could miss those
* Allows to resolve hits below voxel interpolation footprint, which previously had to be black in order to prevent from sampling the surface from which current ray originated and causing multibounce to explode.

Distance field object grid is now a part of the global distance field update. Which allows to reuse the page table, update, separate mobility caches and make sure that global distance field matches hit lighting (previous Voxel Lighting was updated in a different place and didn�t always match). Object grid is half resolution and stores up to 4 closest objects to the cell center. All objects are sorted by distance. On every global distance field, the appropriate cell is loaded. Objects are processed in order (sorted by distance to cell center) and their surface cache is applied to hit points until a valid coverage is found.

Smaller changes:
* Removed LumenVoxelLighting
* Prefixed Global Distance Field resources with �GlobalDistanceField.�
* Distance field object buffers are now properly tracked by RDG
* Distance field will bind empty buffers if there are no distance field objects
* Moved global distance field object composite shaders to GlobalDistanceFieldCompositeObjects.usf in order to speed up shader compilation
* Removed mesh SDF change tracking through AddModifiedBoundsForLumen
* Remove more unused parts of Distance Scene
* Fixed ComputeSurfaceCacheSample sampling outside of valid bilinear region

Memory:
Memory increased from 72mb to 112mb. Could be optimized in future by moving object cull grid to separate page table to leverage extra sparseness, or by simply reducing max number of element per grid cell to 3, thus bringing memory overhead to 82mb.

Performance:
Console, FortGPUTestBed, 1080p
Lumen High: 3.4ms -> 3.4ms
Lumen Epic: 7.9ms -> 8.1ms

[FYI] Daniel.Wright, Tiago.Costa

[CL 21825874 by krzysztof narkowicz in ue5-main branch]
2022-09-06 14:53:33 -04:00
tiago costa
7ae20fa7c1 Use DistanceFieldSampler in the shaders used to update global SDF.
- Remove depedency on ViewUniformBuffer.
- Changed DistanceFieldSampler to use wrap addressing so that it matches the global sampler addressing mode.

#rb aleksander.netzel
#preflight 63063a1ac744dac967282411

[CL 21541307 by tiago costa in ue5-main branch]
2022-08-24 11:17:02 -04:00
krzysztof narkowicz
200b151ee4 Filter out invisible shadow casters from Lumen and Global Distance Field. Shadow casters were causing various artifacts in GI and reflections as they can stick out of the main mesh and can have a different material (e.g. grey texture).
[FYI] Daniel.Wright, Tiago.Costa

#ROBOMERGE-AUTHOR: krzysztof.narkowicz
#ROBOMERGE-SOURCE: CL 21097300 via CL 21098166 via CL 21098383
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v972-20964824)

[CL 21106234 by krzysztof narkowicz in ue5-main branch]
2022-07-15 03:40:17 -04:00
jason hoerner
8d16aa3dd2 Lumen multi-view-family / multi-GPU: Support for per-view Lumen scene data, enabled by default for Display Cluster rendering (Virtual Production). Produces identical lighting results as rendering one view at a time. Fixes massive multi-GPU related artifacts (due to use of pages that are unininitialized on other GPUs), and somewhat less severe multi-view artifacts on a single GPU (significantly darker lighting with multiple views). To handle switching GPU assignments on the fly, persistent per-view Lumen data is automatically copied cross GPU when the GPU mask changes.
Per-GPU Lumen scene data is automatically allocated if a View is running on a different GPU, and no per-view data is available, to handle cases where multi-GPU is in use outside of Display Cluster.

#jira UE-157691
#rnx
#rb Krzysztof.Narkowicz Daniel.Wright
#preflight 62d065d4a6141b6adffe82f3

[CL 21100710 by jason hoerner in ue5-main branch]
2022-07-14 18:29:10 -04:00
daniel wright
9292fcb068 Distance field stochastic semi-transparency for foliage
* Global SDF tracing uses a per-step noise comparison to implement semi-transparency (r.LumenScene.GlobalSDF.DitheredTransparencyStepThreshold), with a high min step size to regain performance
 * Fixed Global SDF Coverage getting stomped when Movable objects were nearby, which was lowering its effective resolution.  Empty space is now marked as not covered, which requires MinStepSizes to be kept smaller than or equal to ONE_SIDED_BAND_SIZE.
 * Mesh SDF tracing now expands based on coverage and implements its own semi-transparency (r.Lumen.DiffuseIndirect.MeshSDF.DitheredTransparencyStepThreshold)
 * Only Screen Probe and Radiance Cache traces enable dithered transparency to combat foliage over-occlusion.  Visualize matches reflection behavior by default, so it has to have TraceInput.bDitheredTransparency = true to visualize what diffuse rays see.

#ROBOMERGE-AUTHOR: daniel.wright
#ROBOMERGE-SOURCE: CL 21019034 via CL 21019035 via CL 21019036
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v972-20964824)

[CL 21023956 by daniel wright in ue5-main branch]
2022-07-09 14:06:37 -04:00
zach bethel
f6638993ed Upgraded CSV stats to RDG variants to include RDG pass executions to reduce RDG_Execute CSV tag.
[FYI] ben.woodhouse, jian.ru

#ROBOMERGE-AUTHOR: zach.bethel
#ROBOMERGE-SOURCE: CL 20951340 via CL 20951352 via CL 20951364
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v971-20777995)

[CL 20953292 by zach bethel in ue5-main branch]
2022-07-05 19:59:53 -04:00
jason hoerner
1f73247f9d MGPU: Fix for global distance field data not being initialized when swapping GPUs. Force full update of global distance field data if the GPU index changes. If AFR is enabled, force global distance fields to be updated across all GPUs, to avoid thrashing due to the GPU index changing every frame.
#jira UE-145093
#rnx
#rb jason.nadro
#preflight 62bc9eb9b64c84b3ba7a9d2f

[CL 20881535 by jason hoerner in ue5-main branch]
2022-06-29 16:12:02 -04:00
Mi Wang
f86b1532a7 Fix EmissiveLightSource not correctly encoded to be injected into the VoxelLighting.
#fyi krzysztof.narkowicz
#preflight

[CL 20627397 by Mi Wang in ue5-main branch]
2022-06-13 11:02:58 -04:00
jason hoerner
6144ebf450 Scene renderer no longer contains multiple view families. Instead, multiple view families are handled by creating multiple scene renderers, which are added to a linked list with the first scene renderer as the list head. This more or less reverses CL 19813996, while preserving the optimizations gained from having knowledge of multiple scene renderers. This includes deferring cross GPU resource transfer waits to the last scene render, running ray tracing scene update once, and only flushing resources once. Future optimizations and bug fixes may take advantage of additional information from other scene renderers.
The refactor to get rid of the FSceneTextures and FSceneTexturesConfig global singletons has also been preserved.  The FViewFamilyInfo is used to hold those structures, so client facing API functions that lack a scene renderer reference can still pull the FSceneTextures[Config] from the view family pointer.  All other scene renderer state has been moved from FViewFamilyInfo back into FSceneRenderer.

#jira none
#rnx
#rb ola.olsson krzysztof.narkowicz zach.bethel
#preflight 629f770e233ae0a8f8fb7f2e

[CL 20540730 by jason hoerner in ue5-main branch]
2022-06-07 13:19:54 -04:00
tiago costa
eb13fab6de Clear IndicesToUpdateInHeightFieldObjectBuffers after processing it.
- It was accumulating new indices resulting in unecessary updates.
Store PendingHeightFieldAdd/UpdateOps in TSet instead of TArray so that Contains/Remove calls are O(1).

#rb Krzysztof.Narkowicz
#preflight 627d0c089f7ad2a14be26bd9

[CL 20163847 by tiago costa in ue5-main branch]
2022-05-12 09:36:48 -04:00
zach bethel
16dcf5b313 Refactored Lumen and Distance Field buffers to RDG.
- Replaced FRW{Structured, ByteAddress}Buffer with TRefCountPtr<FRDGPooledBuffer>
 - Replaced ResizeResourceIfNeeded with Resize{Structured, ByteAddress}BufferIfNeeded.
 - Replaced FScatterUploadBuffer with FRDGScatterUploadBuffer.
 - Removed awkward copy of page table buffers now that scatters are on the RDG timeline.
 - Reduced number of uniform buffers created by consolidating within FLumenSceneFrameTemporaries.
 - Fixed up const-correctness of FLumenSceneFrameTemporaries to sanity check that resources were not being mutated later in the frame.
 - Reduced explicit view creations somewhat.
 - Distance fields needs an FDistanceFieldSceneFrameTemporaries to cache RDG resources, but I held off on this due to the number of files it would touch.

#rb krzyzstof.narkowicz, daniel.wright

#ROBOMERGE-AUTHOR: zach.bethel
#ROBOMERGE-SOURCE: CL 19921040 via CL 19922067 via CL 19922607
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)

[CL 19925590 by zach bethel in ue5-main branch]
2022-04-26 14:37:07 -04:00
tiago costa
d3e0196bd2 Fix error compiling shaders sampling distance fields when using non-default Distance Field Offset Data Structure
- Shaders sampling mesh distance fields must define OFFSET_DATA_STRUCT according to r.DFShadowOffsetDataStructure.
- Also renamed cvar r.DFShadowOffsetDataStructure to r.DistanceFields.OffsetDataStructure since it applies to all techniques sampling mesh distance fields.

#preflight 626661771a71643e8b8b07df
#rb Krzysztof.Narkowicz
#jira none

[CL 19900311 by tiago costa in ue5-main branch]
2022-04-25 07:32:32 -04:00
jason hoerner
b19bb6be2f UE5_MAIN: Multi-view-family scene renderer refactor, part 1. Major structural change to allow scene renderer to accept multiple view families, with otherwise negligible changes in internal behavior.
* Added "BeginRenderingViewFamilies" render interface call that accepts multiple view families.  Original "BeginRenderingViewFamily" falls through to this.
* FSceneRenderer modified to include an array of view families, plus an active view family and the Views for that family.
* Swap ViewFamily to ActiveViewFamily.
* Swap Views array from TArray<FViewInfo> to TArrayView<FViewInfo>, including where the Views array is passed to functions.
* FSceneRenderer iterates over the view families, rendering each one at a time, as separate render graph executions.
* Some frame setup and cleanup logic outside the render graph runs once.
* Moved stateful FSceneRenderer members to FViewFamilyInfo, to preserve existing one-at-a-time view family rendering behavior.
* Display Cluster (Virtual Production) uses new API.

Next step will push everything into one render graph, which requires handling per-family external resources and cleaning up singletons (like FSceneTextures and FSceneTexturesConfig).  Once that's done, we'll be in a position to further interleave rendering, properly handle once per frame work, and solve artifacts in various systems.

#jira none
#rnx
#rb zach.bethel
#preflight 625df821b21bb49791d377c9

[CL 19813996 by jason hoerner in ue5-main branch]
2022-04-19 14:45:26 -04:00
zach bethel
a00b40ad3b Deprecated GetRenderTargetItem() from IPooledRenderTarget.
#preflight 624ddb30090236773a1a83e0
#rb luke.thatcher

#ROBOMERGE-AUTHOR: zach.bethel
#ROBOMERGE-SOURCE: CL 19655641 via CL 19655653 via CL 19655661
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v938-19570697)

[CL 19657582 by zach bethel in ue5-main branch]
2022-04-06 18:24:24 -04:00
jason hoerner
078ea856d8 UE5_MAIN: Multi-GPU crash, corruption, and DumpGPU fixes.
* Distance Field streaming GPU mask scope clean up, to avoid startup crash.  Added single high level FRHIGPUMask::All() scope in PrepareDistanceFieldScene, to avoid the need to set the mask in multiple lower level functions, and hopefully cover future modifications to the distance field scene code.  View dependent subset of the code is then masked to the view.  Validation asserts added in case code gets moved around in the future.
* Fixed bug when generating SRVs for structured buffers -- wasn't pointing the SRV to the correct GPU buffer.  Caused GPU hangs and all sorts of corrupted rendering.
* Fixed bug that RHICopyToResolveTarget wasn't using the correct GPU index.  Main symptom was DumpGPU being non-functional on the second GPU, but could cause other artifacts as well.

#jira none
#rnx
#rb christopher.waters chris.kulla
#preflight 624716e2b6084b9832597015

[CL 19591778 by jason hoerner in ue5-main branch]
2022-04-01 13:44:07 -04:00
fred kimberley
81b706b1b5 Fix build errors from removing implict conversion to FVector.
#rb Michael.Noland

#ROBOMERGE-AUTHOR: fred.kimberley
#ROBOMERGE-SOURCE: CL 19260414 in //UE5/Release-Engine-Staging/...
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v924-19243027)

[CL 19264049 by fred kimberley in ue5-main branch]
2022-03-04 04:25:49 -05:00
tiago costa
403b305472 Distance Field LWC support #3
- Upload heightfield bounds tile + relative world position
- Upload heightfield tile + relative world matrices
- Positions are still converted to float when loaded in shader.

#rb none
#preflight 622118eebf662715a8c73d52
#jira none

[CL 19250645 by tiago costa in ue5-main branch]
2022-03-03 14:45:55 -05:00