Skip to content

Commit 0bffebd

Browse files
pastasfutureDeployer User
authored andcommitted
Clean out some unnecessary GC.Allocs, and make HybridRendererCommandBuffer warnings sticky so that they do not spill every frame in the event that the command buffer is not getting flushed by OnRender() in the builds. (#87)
1 parent 015c047 commit 0bffebd

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,7 @@ ProbeVolumeDebugOverlayParameters PrepareProbeVolumeOverlayParameters(LightingDe
14261426
#if UNITY_EDITOR
14271427
if (UnityEditor.Selection.activeGameObject != null)
14281428
{
1429-
var selectedProbeVolume = UnityEditor.Selection.activeGameObject.GetComponent<ProbeVolume>();
1430-
if (selectedProbeVolume != null)
1429+
if (UnityEditor.Selection.activeGameObject.TryGetComponent(out ProbeVolume selectedProbeVolume))
14311430
{
14321431
// User currently has a probe volume selected.
14331432
// Compute a scaleBias term so that atlas view automatically zooms into selected probe volume.

com.unity.render-pipelines.high-definition/Runtime/Material/MaskVolume/MaskVolumeRendering.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,7 @@ MaskVolumeDebugOverlayParameters PrepareMaskVolumeOverlayParameters(LightingDebu
828828
#if UNITY_EDITOR
829829
if (UnityEditor.Selection.activeGameObject != null)
830830
{
831-
var selectedMaskVolume = UnityEditor.Selection.activeGameObject.GetComponent<MaskVolume>();
832-
if (selectedMaskVolume != null)
831+
if (UnityEditor.Selection.activeGameObject.TryGetComponent(out MaskVolume selectedMaskVolume))
833832
{
834833
// User currently has a probe volume selected.
835834
// Compute a scaleBias term so that atlas view automatically zooms into selected probe volume.

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.HybridRendererCommandBuffer.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public override int GetHashCode()
7979

8080
return hash;
8181
}
82+
83+
public static readonly HybridRendererCommandBufferSystemHandle zero = new HybridRendererCommandBufferSystemHandle()
84+
{
85+
systemID = 0,
86+
worldID = 0
87+
};
8288
}
8389

8490
private class HybridRendererCommandBufferData
@@ -89,6 +95,10 @@ private class HybridRendererCommandBufferData
8995
private bool immediateModeEnabled = false;
9096
private bool immediateModeEnabledNext = false;
9197

98+
#if !UNITY_EDITOR
99+
private HybridRendererCommandBufferSystemHandle commandBufferSubmissionStickyWarningHandle = HybridRendererCommandBufferSystemHandle.zero;
100+
#endif
101+
92102
public void EnsureProfilingSampler(string name, HybridRendererCommandBufferSystemHandle handle)
93103
{
94104
if (!profilingSamplers.TryGetValue(handle.systemID, out var profilingSampler))
@@ -120,9 +130,19 @@ public CommandBuffer Begin(HybridRendererCommandBufferSystemHandle handle)
120130
SubmitImmediate();
121131

122132
#if !UNITY_EDITOR
123-
Debug.LogWarning("Warning: HybridRendererCommandBuffer: Encountered unexpected case of a command buffer having not been submitted between Simulation Update loops. It should have been submitted in the HDRenderPipeline::Render() loop.");
133+
if (commandBufferSubmissionStickyWarningHandle != handle)
134+
{
135+
commandBufferSubmissionStickyWarningHandle = handle;
136+
Debug.LogWarning("Warning: HybridRendererCommandBuffer: Encountered unexpected case of a command buffer having not been submitted between Simulation Update loops. It should have been submitted in the HDRenderPipeline::Render() loop.");
137+
}
124138
#endif
125139
}
140+
#if !UNITY_EDITOR
141+
else if (handle == commandBufferSubmissionStickyWarningHandle)
142+
{
143+
commandBufferSubmissionStickyWarningHandle = HybridRendererCommandBufferSystemHandle.zero;
144+
}
145+
#endif
126146
debugSubmittedSystemState.Add(handle, false);
127147

128148
var cmd = EnsureCommandBuffer();
@@ -134,7 +154,12 @@ public void End(HybridRendererCommandBufferSystemHandle handle)
134154
{
135155
if (debugSubmittedSystemState.TryGetValue(handle, out bool submitted))
136156
{
137-
Debug.AssertFormat(submitted == false, "Error: Encountered Hybrid Rendering System {0} with an already submitted command buffer. Was End() already called in this Simulation Update?", profilingSamplers[handle.systemID].name);
157+
if (submitted)
158+
{
159+
// Guard assert in if block so that we do not pay the GC.Alloc cost of accessing a ProfilingSampler.name.
160+
Debug.AssertFormat(false, "Error: Encountered Hybrid Rendering System {0} with an already submitted command buffer. Was End() already called in this Simulation Update?", profilingSamplers[handle.systemID].name);
161+
}
162+
138163
}
139164
else
140165
{

0 commit comments

Comments
 (0)