Skip to content

Commit 6a8b4d5

Browse files
AndrewSaraevUnityDeployer User
authored andcommitted
Fix ProbeVolume buffers not being reset after disable (#95)
Fixed ProbeVolume BuffersDataVersion not being reset on disable. Also clear EngineDataIndex and simulationFrameTick. Unified clearing methods.
1 parent aa63084 commit 6a8b4d5

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ internal void DispatchPropagationOutputDynamicSH(
958958
cmd.DispatchCompute(shader, kernel, dispatchX, 1, 1);
959959
}
960960

961-
internal bool CleanupPropagation(ProbeVolumeHandle probeVolume)
961+
internal static bool CleanupPropagation(ProbeVolumeHandle probeVolume)
962962
{
963963
ref var propagationPipelineData = ref probeVolume.GetPropagationPipelineData();
964964

@@ -969,6 +969,7 @@ internal bool CleanupPropagation(ProbeVolumeHandle probeVolume)
969969
didDispose |= ProbeVolume.CleanupBuffer(propagationPipelineData.hitRadianceCache);
970970

971971
propagationPipelineData.buffersDataVersion = -1;
972+
propagationPipelineData.simulationFrameTick = -1;
972973

973974
return didDispose;
974975
}

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
@@ -969,13 +969,10 @@ internal void EnsureVolumeBuffers()
969969
pipelineData.BuffersDataVersion = probeVolumeAsset.dataVersion;
970970
}
971971

972-
internal void CleanupBuffers()
973-
{
974-
CleanupBuffers(pipelineData);
975-
}
976-
977-
public static void CleanupBuffers(ProbeVolumePipelineData pipelineData)
972+
public static void CleanupBuffers(ProbeVolumeHandle probeVolume)
978973
{
974+
ref var pipelineData = ref probeVolume.GetPipelineData();
975+
979976
CleanupBuffer(pipelineData.SHL01Buffer);
980977
CleanupBuffer(pipelineData.SHL2Buffer);
981978
CleanupBuffer(pipelineData.ValidityBuffer);
@@ -1020,6 +1017,12 @@ public static void SetBuffer<T>(ComputeBuffer buffer, T[] data)
10201017
}
10211018
}
10221019

1020+
public static void ReleaseVolumeFromAtlas(ProbeVolumeHandle probeVolume)
1021+
{
1022+
if (RenderPipelineManager.currentPipeline is HDRenderPipeline hdrp)
1023+
hdrp.ReleaseProbeVolumeFromAtlas(probeVolume);
1024+
}
1025+
10231026
#if UNITY_EDITOR
10241027
internal VolumeGlobalUniqueID GetBakeID()
10251028
{

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)