Skip to content

Commit c9e3a3a

Browse files
svc-reach-platform-supportEvergreen
authored and
Evergreen
committed
[Port] [6000.0] [UUM-83271] made streaming scratch buffers having different size not leak into the pool and dispose immediately
JIRA: [UUM-83271](https://jira.unity3d.com/browse/UUM-83271) This PR is to prevent APV streaming buffer from not leaking into the current pool having different chunk size. Because NativeArray with fixed size is used while streaming in & out, memory contemination happens especially when the current pool's chunk size is bigger than the released scratch buffer's, and the behaviour tends to cause editor crash. In the JIRA ticket's repro case, the issue occurs because Lobby scene's baking set with greater chunk size becomes active while requests from MainMenu scene having smaller chunk size are cancelled and their attached scratch buffers leak into the newly created free buffer pool. The case happens in editor only, but as it doesn't seem like the only repro case the modification is applied into the player land. From this PR's inverstigation, refactorying the structure reagarding disk streaming scratch buffer and its pool will be more fundamental solution especially by changing the pool to be capable of managing various sizes & layouts. Please let me know which way you think more proper.
1 parent bfe1703 commit c9e3a3a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Streaming.cs

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ internal class CellStreamingScratchBuffer
114114
public CellStreamingScratchBuffer(int chunkCount, int chunkSize, bool allocateGraphicsBuffers)
115115
{
116116
this.chunkCount = chunkCount;
117+
this.chunkSize = chunkSize;
117118

118119
// With a stride of 4 (one uint)
119120
// Number of elements for chunk data: chunkCount * chunkSize / 4
@@ -152,6 +153,7 @@ public void Dispose()
152153
public GraphicsBuffer buffer => m_GraphicsBuffers[m_CurrentBuffer];
153154
public NativeArray<byte> stagingBuffer; // Contains data streamed from disk. To be copied into the graphics buffer.
154155
public int chunkCount { get; }
156+
public int chunkSize { get; }
155157

156158
int m_CurrentBuffer;
157159
GraphicsBuffer[] m_GraphicsBuffers = new GraphicsBuffer[2];

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeScratchBufferPool.cs

+6
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ public bool AllocateScratchBuffer(int chunkCount, out CellStreamingScratchBuffer
232232

233233
public void ReleaseScratchBuffer(CellStreamingScratchBuffer scratchBuffer)
234234
{
235+
if (scratchBuffer.chunkSize != chunkSize)
236+
{
237+
scratchBuffer.Dispose();
238+
return;
239+
}
240+
235241
s_ChunkCount = scratchBuffer.chunkCount;
236242
var pool = m_Pools.Find((o) => o.chunkCount == s_ChunkCount);
237243
Debug.Assert(pool != null);

0 commit comments

Comments
 (0)