Skip to content

Commit 13fcc70

Browse files
Partner/crazyhunter 10.7.0 custom.1 bursted shadowrequests (#97)
* Remove temp allocation and clamp array ranges * Added two missing Dispose calls
1 parent 902c0a7 commit 13fcc70

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDGpuLightsBuilder.LightLoop.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private unsafe void CalculateAllLightDataTextureInfo(
397397

398398
int directionalLightCount = visibleLights.sortedDirectionalLightCounts;
399399
int lightCounts = visibleLights.sortedLightCounts;
400-
NativeArray<int> shadowIndices = new NativeArray<int>(lightCounts, Allocator.Temp);
400+
NativeArray<int> shadowIndices = lightEntities.GetShadowIndicesScratchpadArray(lightCounts);
401401
HDAdditionalLightData.CalculateShadowIndices(hdCamera, in cullResults, visibleLights, lightEntities, hdShadowSettings, debugDisplaySettings,
402402
m_ShadowManager, m_Asset, shadowIndices, ref m_DebugSelectedLightShadowIndex, ref m_DebugSelectedLightShadowCount);
403403

@@ -486,8 +486,6 @@ private unsafe void CalculateAllLightDataTextureInfo(
486486
}
487487
}
488488
}
489-
490-
shadowIndices.Dispose();
491489
}
492490
}
493491
}

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,22 @@ internal NativeBitArray GetValidIndexScratchpadArray(int minLightCount)
356356
return m_IsValidIndexScratchpadArray;
357357
}
358358

359+
internal NativeArray<int> GetShadowIndicesScratchpadArray(int minLightCount)
360+
{
361+
if (m_ShadowIndicesScratchpadArray.IsCreated && m_ShadowIndicesScratchpadArray.Length < minLightCount)
362+
{
363+
m_ShadowIndicesScratchpadArray.Dispose();
364+
m_ShadowIndicesScratchpadArray = default;
365+
}
366+
367+
if (!m_ShadowIndicesScratchpadArray.IsCreated)
368+
{
369+
m_ShadowIndicesScratchpadArray = new NativeArray<int>(minLightCount, Allocator.Persistent);
370+
}
371+
372+
return m_ShadowIndicesScratchpadArray.GetSubArray(0, minLightCount);
373+
}
374+
359375
#if UNITY_EDITOR
360376
internal NativeArray<int> GetShadowRequestCountsScratchpad(int requestCount)
361377
{
@@ -370,7 +386,7 @@ internal NativeArray<int> GetShadowRequestCountsScratchpad(int requestCount)
370386
m_ShadowRequestCountsScratchpad = new NativeArray<int>(requestCount, Allocator.Persistent);
371387
}
372388

373-
return m_ShadowRequestCountsScratchpad;
389+
return m_ShadowRequestCountsScratchpad.GetSubArray(0, requestCount);
374390
}
375391
#endif
376392

@@ -596,6 +612,7 @@ internal struct LightEntityInfo
596612
private NativeList<ShadowIndicesAndVisibleLightData> m_VisibleLightsAndIndicesBuffer = new NativeList<ShadowIndicesAndVisibleLightData>(Allocator.Persistent);
597613
private NativeList<ShadowIndicesAndVisibleLightData> m_SplitVisibleLightsAndIndicesBuffer = new NativeList<ShadowIndicesAndVisibleLightData>(Allocator.Persistent);
598614
private NativeBitArray m_IsValidIndexScratchpadArray = new NativeBitArray(256, Allocator.Persistent);
615+
private NativeArray<int> m_ShadowIndicesScratchpadArray;
599616
#if UNITY_EDITOR
600617
NativeArray<int> m_ShadowRequestCountsScratchpad;
601618
#endif
@@ -655,6 +672,26 @@ private void RemoveAtSwapBackArrays(int removeIndexAt)
655672

656673
private void DeleteArrays()
657674
{
675+
if (m_IsValidIndexScratchpadArray.IsCreated)
676+
{
677+
m_IsValidIndexScratchpadArray.Dispose();
678+
m_IsValidIndexScratchpadArray = default;
679+
}
680+
681+
if (m_ShadowIndicesScratchpadArray.IsCreated)
682+
{
683+
m_ShadowIndicesScratchpadArray.Dispose();
684+
m_ShadowIndicesScratchpadArray = default;
685+
}
686+
687+
688+
#if UNITY_EDITOR
689+
if (m_ShadowRequestCountsScratchpad.IsCreated)
690+
{
691+
m_ShadowRequestCountsScratchpad.Dispose();
692+
m_ShadowRequestCountsScratchpad = default;
693+
}
694+
#endif
658695
if (m_Capacity == 0)
659696
return;
660697

@@ -680,25 +717,13 @@ private void DeleteArrays()
680717
m_VisibleLightsAndIndicesBuffer = default;
681718
m_SplitVisibleLightsAndIndicesBuffer.Dispose();
682719
m_SplitVisibleLightsAndIndicesBuffer = default;
683-
if (m_IsValidIndexScratchpadArray.IsCreated)
684-
{
685-
m_IsValidIndexScratchpadArray.Dispose();
686-
m_IsValidIndexScratchpadArray = default;
687-
}
688-
689-
690-
#if UNITY_EDITOR
691-
if (m_ShadowRequestCountsScratchpad.IsCreated)
692-
{
693-
m_ShadowRequestCountsScratchpad.Dispose();
694-
m_ShadowRequestCountsScratchpad = default;
695-
}
696-
#endif
697720

698721
m_HDShadowRequestStorage.Dispose();
699722
m_HDShadowRequestStorage = default;
700723
m_HDShadowRequestIndicesStorage.Dispose();
701724
m_HDShadowRequestIndicesStorage = default;
725+
m_CachedViewPositionsStorage.Dispose();
726+
m_CachedViewPositionsStorage = default;
702727
m_FrustumPlanesStorage.Dispose();
703728
m_FrustumPlanesStorage = default;
704729
m_HDShadowRequestsCreated = false;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ public override void Dispose()
860860
m_RegisteredLightDataPendingPlacement = default;
861861
m_RecordsPendingPlacement.Dispose();
862862
m_RecordsPendingPlacement = default;
863+
m_TransformCaches.Dispose();
864+
m_TransformCaches = default;
863865
}
864866
}
865867

0 commit comments

Comments
 (0)