Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APV] Cell streaming system #5731

Merged
merged 108 commits into from
Oct 20, 2021
Merged

[APV] Cell streaming system #5731

merged 108 commits into from
Oct 20, 2021

Conversation

JulienIgnace-Unity
Copy link
Contributor

@JulienIgnace-Unity JulienIgnace-Unity commented Sep 20, 2021

Purpose of this PR

This PR introduces cell streaming to the APV.

This includes:

  • Refactor to split properly loading cell from the asset and uploading data to GPU
  • Renamed things a bit: Add for adding a cell from asset and Load to upload it to GPU
  • Handled out of memory (both index and texture) more gracefully: Cell isn't uploaded but still available in CPU memory
  • Cell debug is now red for cells that aren't "loaded" (uploaded to GPU)
  • Precompute of cell chunk cost
  • Added name of 3D textures allocated for APV
  • First version of streaming of cell. Only based on distance to camera for now.
  • Debug option to "freeze" streaming in order to assess the current state
  • Removed all GCAlloc for load/unload code as it is now called regularly.
  • Disabled by default. Added a debug entry to enable it.
  • Actual data upload is done in "chunks" to avoid allocating for worse case scenario. Currently set at 8 chunks (500KB)
  • Index GPU Buffer update is now done partially to improve performance.

Still needs to be done:

  • Handle multiple cameras
  • Handle fragmentation
  • Base streaming on more than just camera position.

What has been tested:

  • Automated tests are green
  • Baking one/Multiple scenes
  • Tested add/remove of scenes after baking
  • Tested that streaming actually worked while under budget (with the help of cell debug)
  • Tested that being under budget is handled gracefully with streaming disabled (no error, just stops loading after being oom)

JulienIgnace-Unity and others added 30 commits August 5, 2021 15:06
Updated Probe Reference debug to use it completely
… into hd/apv-cell-streaming

# Conflicts:
#	com.unity.render-pipelines.core/Runtime/Utilities/MeshGizmo.cs
… into hd/apv-cell-streaming

# Conflicts:
#	com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.cs
int m_UpdateMaxIndex = int.MinValue;

// Static variable required to avoid allocations inside lambda functions
static Cell g_Cell = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes, can we use the cell index instead to do the checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but I don't think that would make any difference, would it? It's just comparing references.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we still need to have the global static thing? I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the static is mandatory because we use lambda for finding stuff. So it would capture the variable and generate gcalloc without it.
I guess we can make functors and set the ref in it to avoid this but it's much more verbose for not a lot of gain (I don't expect this to be run multi-threaded)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you can replace the FindIndex with an old school for loop, it will avoid GC allocs and the static global field.


// In order not to pre-allocate for the worse case, we update the texture by smaller chunks with a preallocated DataLoc
int chunkIndex = 0;
while (chunkIndex < cellInfo.chunkList.Count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct, but is delicate, have you stress tested this a bit to see if all looks fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested as much as I could but it could be interesting to test with bigger/more complex scenes as well. As it is, it's hard to force streaming activity in a relevant way :/

public int flatIdxInCellIndices = -1;
public bool loaded = false;
public ProbeBrickIndex.CellIndexUpdateInfo updateInfo;
public int sourceAssetInstanceID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? It was very useful to use a string as a ID to debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perf reason. I need to check that everytime an asset is streamed in/out to remove existing cells from internal arrays. Comparing strings did not feel good at all.
I might be overthinking this though, for now we don't even have asset streaming so...

cells[cell.index] = cell;
// The same cell can exist in more than one asset
// Need to check existence because we don't want to add cells more than once to streaming structures
// TODO: Check perf if relevant?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of the same as above. This is relevant in term of perf when we have asset streaming. Right now it is expected that this happens during loading only so it's probably fine as is.

@iM0ve iM0ve self-requested a review October 11, 2021 08:18
@iM0ve
Copy link
Contributor

iM0ve commented Oct 11, 2021

Testing status: Complete

Whats to be tested:
Real-world use

  • Upgrading ClassRoom APV project and rebaking

Feature testing

  • Probe Volume settings
  • Probe volume override
  • Probe volume component
  • HD Asset APV settings
  • Cell streaming system itself
  • Baking sets
  • Loading/unloading scenes
  • Debug modes

Workflow

  • Setting up a new APV project. Used Amalienborg as base

No streaming specific issues found but filed a lot for general APV here

Showcase

4EHeTZ9blF.mp4

Copy link
Contributor

@iM0ve iM0ve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the review

… into hd/apv-cell-streaming-2

# Conflicts:
#	com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs
@JulienIgnace-Unity JulienIgnace-Unity merged commit daccc59 into master Oct 20, 2021
@JulienIgnace-Unity JulienIgnace-Unity deleted the hd/apv-cell-streaming-2 branch October 20, 2021 10:19
odbb added a commit that referenced this pull request Oct 20, 2021
* master:
  Add missing shader stages in shader keyword copying  (#6008)
  [Yamato] Add all DX11 job for URP (#6075)
  [HDRP] Add more performance test coverage (#5814)
  Fix templates ISO date (#6073)
  Fix division by 0 when AO is 0 (#6078)
  Fixed grammar errors (#6077)
  [HDRP][Path Tracing] Improved robustness of the stacklit material (#6066)
  [APV] Cell streaming system (#5731)
  Update revision for URP update test project (#6061)
  [HDRP][Path Tracing] Camera ray misses now return a null value with Minimum Depth > 1 (#6067)
  Renable missing test (Lens Flare) (#5456)
  [HDRP][Path Tracing] Added proper support for interleaved tiling (#5953)
  Fix to render depth or depth/normal of waving grass (#4097)
  Remove ScreenSpaceShadowResolvePass (#6002)
  [HDRP][Docs] Update docs with RendererList related option (#6031)
  Layer drawer used in ray/path tracing now matches 100% with camera's. (#5956)
  Fix iridescence tooltip (#5950)
  [HDRP] Change RenderGraph Begin/Execute function pattern to avoid leaks (#5929)
  [HDRP] Fix errors when switching build targets in editor (#5918)
  Generate a material as a subasset for ShaderGraphs (#5795)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants