Skip to content

Commit

Permalink
Maintain APV cells loaded if at least one scene still references that…
Browse files Browse the repository at this point in the history
… cell (#5900)

* Add override checkbox.

* Fix for problem when max subdiv is smaller than index voxel update size.

* Revert "Merge branch 'HDRP/add-override-checkbox-for-pv' into HDRP/investigate-issue-with-faulty-index"

This reverts commit e33a421, reversing
changes made to 924763f.
  • Loading branch information
FrancescoC-unity committed Oct 8, 2021
1 parent d262c74 commit 07b140f
Showing 1 changed file with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ public struct ExtraDataActionInput
// List of info for cells that are yet to be loaded.
private List<CellSortInfo> m_CellsToBeLoaded = new List<CellSortInfo>();


// Ref counting here as a separate dictionary as a temporary measure to facilitate future changes that will soon go in.
// cell.index, refCount
Dictionary<int, int> m_CellRefCounting = new Dictionary<int, int>();
void InvalidateAllCellRefs()
{
m_CellRefCounting.Clear();
}

bool m_NeedLoadAsset = false;
bool m_ProbeReferenceVolumeInit = false;
bool m_EnabledBySRP = false;
Expand Down Expand Up @@ -693,20 +702,34 @@ void RemoveCell(Cell cell)
{
if (cell.loaded)
{
if (cells.ContainsKey(cell.index))
cells.Remove(cell.index);
bool needsUnloading = true;
if (m_CellRefCounting.ContainsKey(cell.index))
{
m_CellRefCounting[cell.index]--;
needsUnloading = m_CellRefCounting[cell.index] <= 0;
if (needsUnloading)
{
m_CellRefCounting[cell.index] = 0;
}
}

if (m_ChunkInfo.ContainsKey(cell.index))
m_ChunkInfo.Remove(cell.index);
if (needsUnloading)
{
if (cells.ContainsKey(cell.index))
cells.Remove(cell.index);

if (cell.flatIdxInCellIndices >= 0)
m_CellIndices.MarkCellAsUnloaded(cell.flatIdxInCellIndices);
if (m_ChunkInfo.ContainsKey(cell.index))
m_ChunkInfo.Remove(cell.index);

RegId cellBricksID = new RegId();
if (m_CellToBricks.TryGetValue(cell, out cellBricksID))
{
ReleaseBricks(cellBricksID);
m_CellToBricks.Remove(cell);
if (cell.flatIdxInCellIndices >= 0)
m_CellIndices.MarkCellAsUnloaded(cell.flatIdxInCellIndices);

RegId cellBricksID = new RegId();
if (m_CellToBricks.TryGetValue(cell, out cellBricksID))
{
ReleaseBricks(cellBricksID);
m_CellToBricks.Remove(cell);
}
}
}

Expand All @@ -715,6 +738,9 @@ void RemoveCell(Cell cell)

void AddCell(Cell cell, List<Chunk> chunks)
{
if (m_CellRefCounting.ContainsKey(cell.index)) m_CellRefCounting[cell.index]++;
else m_CellRefCounting.Add(cell.index, 1);

cell.loaded = true;
cells[cell.index] = cell;

Expand Down Expand Up @@ -898,6 +924,9 @@ void PerformPendingLoading()
// Load the ones that are already active but reload if we said we need to load
if (m_HasChangedIndex)
{
// We changed index so all assets are going to be re-loaded, hence the refs will be repopulated from scratch
InvalidateAllCellRefs();

foreach (var asset in m_ActiveAssets.Values)
{
LoadAsset(asset);
Expand Down

0 comments on commit 07b140f

Please sign in to comment.