Skip to content

Commit 4e23375

Browse files
committed
Probe Volume: Fix ProbeVolume buffers not being reset after disable (#95)
Fixed ProbeVolume BuffersDataVersion not being reset on disable.
1 parent 9473cb4 commit 4e23375

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,13 +962,10 @@ internal void EnsureVolumeBuffers()
962962
pipelineData.BuffersDataVersion = probeVolumeAsset.dataVersion;
963963
}
964964

965-
internal void CleanupBuffers()
966-
{
967-
CleanupBuffers(pipelineData);
968-
}
969-
970-
public static void CleanupBuffers(ProbeVolumePipelineData pipelineData)
965+
public static void CleanupBuffers(ProbeVolumeHandle probeVolume)
971966
{
967+
ref var pipelineData = ref probeVolume.GetPipelineData();
968+
972969
CleanupBuffer(pipelineData.SHL01Buffer);
973970
CleanupBuffer(pipelineData.SHL2Buffer);
974971
CleanupBuffer(pipelineData.ValidityBuffer);
@@ -1013,6 +1010,12 @@ public static void SetBuffer<T>(ComputeBuffer buffer, T[] data)
10131010
}
10141011
}
10151012

1013+
public static void ReleaseVolumeFromAtlas(ProbeVolumeHandle probeVolume)
1014+
{
1015+
if (RenderPipelineManager.currentPipeline is HDRenderPipeline hdrp)
1016+
hdrp.ReleaseProbeVolumeFromAtlas(probeVolume);
1017+
}
1018+
10161019
#if UNITY_EDITOR
10171020
internal VolumeGlobalUniqueID GetBakeID()
10181021
{

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,21 +612,22 @@ internal void ReleaseProbeVolumeFromAtlas(ProbeVolumeHandle volume)
612612
if (!m_SupportProbeVolume)
613613
return;
614614

615-
ref ProbeVolume.ProbeVolumeAtlasKey usedKey = ref volume.GetPipelineData().UsedAtlasKey;
615+
ref var pipelineData = ref volume.GetPipelineData();
616616

617617
// TODO: Currently, this means that if there are multiple probe volumes that point to the same payload,
618618
// if any of them are disabled, that payload will be evicted from the atlas.
619619
// If will get added back to the atlas the next frame any of the remaining enabled probe volumes are seen,
620620
// so functionally, this is fine. It does however put additional pressure on the atlas allocator + blitting.
621621
// Could add reference counting to atlas keys, or could track key use timestamps and evict based on least recently used as needed.
622-
if (probeVolumeAtlas.IsTextureSlotAllocated(usedKey)) { probeVolumeAtlas.ReleaseTextureSlot(usedKey); }
622+
if (probeVolumeAtlas.IsTextureSlotAllocated(pipelineData.UsedAtlasKey)) { probeVolumeAtlas.ReleaseTextureSlot(pipelineData.UsedAtlasKey); }
623623

624624
if (ShaderConfig.s_ProbeVolumesBilateralFilteringMode == ProbeVolumesBilateralFilteringModes.OctahedralDepth)
625625
{
626-
if (probeVolumeAtlasOctahedralDepth.IsTextureSlotAllocated(usedKey)) { probeVolumeAtlasOctahedralDepth.ReleaseTextureSlot(usedKey); }
626+
if (probeVolumeAtlasOctahedralDepth.IsTextureSlotAllocated(pipelineData.UsedAtlasKey)) { probeVolumeAtlasOctahedralDepth.ReleaseTextureSlot(pipelineData.UsedAtlasKey); }
627627
}
628628

629-
usedKey = ProbeVolume.ProbeVolumeAtlasKey.empty;
629+
pipelineData.UsedAtlasKey = ProbeVolume.ProbeVolumeAtlasKey.empty;
630+
pipelineData.EngineDataIndex = -1;
630631
}
631632

632633
internal void EnsureStaleDataIsFlushedFromAtlases(ProbeVolumeHandle volume, bool isOctahedralDepthAtlasEnabled)

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeManager.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,13 @@ internal void DeRegisterVolume(ProbeVolume volume)
7171
return;
7272

7373
var handle = new ProbeVolumeHandle(this, index);
74-
ReleaseVolumeFromAtlas(handle);
75-
volume.CleanupBuffers();
76-
ProbeVolumeDynamicGI.instance.CleanupPropagation(handle);
74+
ProbeVolume.ReleaseVolumeFromAtlas(handle);
75+
ProbeVolume.CleanupBuffers(handle);
76+
ProbeVolumeDynamicGI.CleanupPropagation(handle);
7777

7878
m_Volumes.RemoveAt(index);
7979
}
8080

81-
public void ReleaseVolumeFromAtlas(ProbeVolumeHandle volume)
82-
{
83-
if (RenderPipelineManager.currentPipeline is HDRenderPipeline hdrp)
84-
hdrp.ReleaseProbeVolumeFromAtlas(volume);
85-
}
86-
8781
public void AddProbeList(IProbeVolumeList list)
8882
{
8983
m_AdditionalProbeLists.Add(list);
@@ -142,8 +136,8 @@ void OnBakeCompleted()
142136

143137
// cleanup buffers
144138
var handle = new ProbeVolumeHandle(this, index);
145-
volume.CleanupBuffers();
146-
ProbeVolumeDynamicGI.instance.CleanupPropagation(handle);
139+
ProbeVolume.CleanupBuffers(handle);
140+
ProbeVolumeDynamicGI.CleanupPropagation(handle);
147141
}
148142

149143
if (volumesSelected.Count > 0)

0 commit comments

Comments
 (0)