Skip to content

Commit

Permalink
[Backport] Fixed a null ref exception when baking APV without GPU str…
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienIgnace-Unity authored and Evergreen committed Dec 21, 2023
1 parent f989cc6 commit a061507
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,6 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,

m_BakingBatchIndex = 0;

// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
var prevSHBands = ProbeReferenceVolume.instance.shBands;
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);
// Don't use Disk streaming to avoid having to wait for it when doing dilation.
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);

PrepareCellsForWriting(isBakingSceneSubset);

using var writeScope = new BakingCompleteProfiling(BakingCompleteProfiling.Stages.WriteBakedData);
Expand All @@ -1210,6 +1204,16 @@ static public void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh,
// Reset internal structures depending on current bake.
probeRefVolume.EnsureCurrentBakingSet(m_BakingSet);

// This subsequent block needs to happen AFTER we call WriteBakingCells.
// Otherwise in cases where we change the spacing between probes, we end up loading cells with a certain layout in ForceSHBand
// And then we unload cells using the wrong layout in PerformDilation (after WriteBakingCells updates the baking set object) which leads to a broken internal state.

// Don't use Disk streaming to avoid having to wait for it when doing dilation.
ProbeReferenceVolume.instance.ForceNoDiskStreaming(true);
// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
var prevSHBands = ProbeReferenceVolume.instance.shBands;
ProbeReferenceVolume.instance.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);

// TODO Discuss: Not nice to do this here, shouldn't reloading the asset also resolve cell data?
// Would still need to reload common shared data like bricks as they are separately handled by the baking set itself.
// Load common shared data (bricks + debug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ static int DefragComparer(Cell a, Cell b)

void StartIndexDefragmentation()
{
// We can end up here during baking (dilation) when trying to load all cells even without supporting GPU streaming.
if (!m_SupportGPUStreaming)
return;

m_IndexDefragmentationInProgress = true;

// Prepare the list of cells.
Expand Down

0 comments on commit a061507

Please sign in to comment.