Skip to content

Commit 22b5b7f

Browse files
authored
[HDRP] Fix GC allocs (#3136)
* Fix gc alloc errors * Avoid setting the name of an object during render (gc alloc) * Avoid gc allocs (for real this time)
1 parent eb1d074 commit 22b5b7f

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

com.unity.render-pipelines.high-definition/Runtime/Compositor/AlphaInjection.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public override void Setup()
2727
var hdrpAsset = HDRenderPipeline.defaultAsset;
2828
if (hdrpAsset != null)
2929
m_Material = CoreUtils.CreateEngineMaterial(hdrpAsset.renderPipelineResources.shaders.alphaInjectionPS);
30-
31-
name = "AlphaInjection"; // Needed to get a scope name in RenderDoc captures
3230
}
3331

3432
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)

com.unity.render-pipelines.high-definition/Runtime/Compositor/ChromaKeying.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public override void Setup()
3030
var hdrpAsset = HDRenderPipeline.defaultAsset;
3131
if (hdrpAsset != null)
3232
m_Material = CoreUtils.CreateEngineMaterial(hdrpAsset.renderPipelineResources.shaders.chromaKeyingPS);
33-
34-
name = "ChromaKeying"; // Needed to get a scope name in RenderDoc captures
3533
}
3634

3735
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)

com.unity.render-pipelines.high-definition/Runtime/Compositor/CompositionManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ void OnDestroy()
551551
CoreUtils.Destroy(volume);
552552
}
553553
}
554+
555+
// We don't need the custom passes anymore
556+
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
557+
UnRegisterCustomPasses(hdPipeline);
554558
}
555559

556560
public void AddInputFilterAtLayer(CompositionFilter filter, int index)
@@ -929,14 +933,12 @@ static internal void RegisterCustomPasses(HDRenderPipeline hdPipeline)
929933
}
930934

931935
// If custom post processes are not registered in the HDRP asset, they are never executed so we have to add them manually
932-
int indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(ChromaKeying).AssemblyQualifiedName);
933-
if (indx < 0)
936+
if (!hdPipeline.asset.beforePostProcessCustomPostProcesses.Contains(typeof(ChromaKeying).AssemblyQualifiedName))
934937
{
935938
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(ChromaKeying).AssemblyQualifiedName);
936939
}
937940

938-
indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(AlphaInjection).AssemblyQualifiedName);
939-
if (indx < 0)
941+
if (!hdPipeline.asset.beforePostProcessCustomPostProcesses.Contains(typeof(AlphaInjection).AssemblyQualifiedName))
940942
{
941943
hdPipeline.asset.beforePostProcessCustomPostProcesses.Add(typeof(AlphaInjection).AssemblyQualifiedName);
942944
}
@@ -950,14 +952,12 @@ static internal void UnRegisterCustomPasses(HDRenderPipeline hdPipeline)
950952
return;
951953
}
952954

953-
int indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(ChromaKeying).AssemblyQualifiedName);
954-
if (indx >= 0)
955+
if (hdPipeline.asset.beforePostProcessCustomPostProcesses.Contains(typeof(ChromaKeying).AssemblyQualifiedName))
955956
{
956957
hdPipeline.asset.beforePostProcessCustomPostProcesses.Remove(typeof(ChromaKeying).AssemblyQualifiedName);
957958
}
958959

959-
indx = hdPipeline.asset.beforePostProcessCustomPostProcesses.FindIndex(x => x == typeof(AlphaInjection).AssemblyQualifiedName);
960-
if (indx >= 0)
960+
if (hdPipeline.asset.beforePostProcessCustomPostProcesses.Contains(typeof(AlphaInjection).AssemblyQualifiedName))
961961
{
962962
hdPipeline.asset.beforePostProcessCustomPostProcesses.Remove(typeof(AlphaInjection).AssemblyQualifiedName);
963963
}

0 commit comments

Comments
 (0)