Skip to content

Commit 74cbb80

Browse files
alex-vazquez-unity3dEvergreen
authored andcommitted
[Rendering Debugger] GPU Resident Drawer : Avoid recreating the tool on messageCallback when the state of initialization changes.
1 parent 70ca8b2 commit 74cbb80

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Panel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public VisualElement Create(DebugUI.Context context)
5656
container.AddToClassList("unity-inspector-element");
5757

5858
var content = new VisualElement();
59+
5960
foreach (var child in children)
6061
{
6162
if (context == Context.Editor && child.isRuntimeOnly)
@@ -67,6 +68,7 @@ public VisualElement Create(DebugUI.Context context)
6768
if (childUIElement != null)
6869
content.Add(childUIElement);
6970
}
71+
7072
container.Add(content);
7173

7274
return container;

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/Debug/DebugDisplayGPUResidentDrawer.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,11 @@ private static DebugUI.Table.Row AddOcclusionContextDataRow(int index)
234234
};
235235
}
236236

237-
static bool s_GRDWasEnabled;
238-
239237
[DisplayInfo(name = "Rendering", order = 5)]
240238
private class SettingsPanel : DebugDisplaySettingsPanel
241239
{
242240
public SettingsPanel(DebugDisplayGPUResidentDrawer data)
243241
{
244-
s_GRDWasEnabled = GPUResidentDrawer.IsInitialized();
245-
246242
DocumentationUtils.TryGetHelpURL(typeof(DebugDisplayGPUResidentDrawer), out var documentationUrl);
247243
var foldout = new DebugUI.Foldout()
248244
{
@@ -257,21 +253,16 @@ public SettingsPanel(DebugDisplayGPUResidentDrawer data)
257253
style = MessageBox.Style.Warning,
258254
messageCallback = () =>
259255
{
260-
// HACK: Reload the UI if GRD enabled state changes
261-
if (s_GRDWasEnabled != GPUResidentDrawer.IsInitialized())
262-
{
263-
s_GRDWasEnabled = GPUResidentDrawer.IsInitialized();
264-
DebugManager.instance.Reset();
265-
}
266-
267256
var settings = GPUResidentDrawer.GetGlobalSettingsFromRPAsset();
268257
return GPUResidentDrawer.IsGPUResidentDrawerSupportedBySRP(settings, out var msg, out var _) ? string.Empty : msg;
269258
},
270259
isHiddenCallback = () => GPUResidentDrawer.IsInitialized()
271260
};
272261
foldout.children.Add(helpBox);
273262

274-
// HACK: Avoid creating GRD debug modes when it's not enabled.
263+
GPUResidentDrawer.initializedChanged += OnGPUResidentDrawerInitialzedChanged;
264+
265+
// Avoid creating GRD debug modes when it's not enabled.
275266
// This debug UI currently creates ~650 DebugUI Widgets (over 80% of all debug widgets in URP).
276267
// To avoid the overhead, we don't create them if GRD is not enabled. If GRD gets enabled while window is open,
277268
// we refresh the window. It would probably be a good idea to rethink how the stats tables are implemented.
@@ -307,6 +298,21 @@ public SettingsPanel(DebugDisplayGPUResidentDrawer data)
307298
AddInstanceCullingStatsWidget(data);
308299
}
309300

301+
private void OnGPUResidentDrawerInitialzedChanged(bool previousValue, bool currentValue)
302+
{
303+
// Reload the UI if GRD enabled state changes, from disabled to enabled only, as the UI did not have all the widgets and we need to add them
304+
// in assembly reloads, or entering playmode we do not have this code path and the SettingsPanel will be recreated itself by the Rendering Debugger
305+
// reconstruction.
306+
if ( previousValue == false && currentValue == true )
307+
DebugManager.instance.Reset();
308+
}
309+
310+
public override void Dispose()
311+
{
312+
base.Dispose();
313+
GPUResidentDrawer.initializedChanged -= OnGPUResidentDrawerInitialzedChanged;
314+
}
315+
310316
private void AddInstanceCullingStatsWidget(DebugDisplayGPUResidentDrawer data)
311317
{
312318
var instanceCullerStats = new DebugUI.Foldout

Packages/com.unity.render-pipelines.core/Runtime/GPUDriven/GPUResidentDrawer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ internal static void Reinitialize()
340340
#endif
341341
}
342342

343+
internal static Action<bool, bool> initializedChanged; // previousValue, currentValue
344+
343345
private static void Cleanup()
344346
{
345347
if (s_Instance == null)
@@ -352,6 +354,8 @@ private static void Cleanup()
352354

353355
private static void Recreate(GPUResidentDrawerSettings settings)
354356
{
357+
bool wasInitialized = IsInitialized();
358+
355359
Cleanup();
356360

357361
if (IsGPUResidentDrawerSupportedBySRP(settings, out var message, out var severity))
@@ -363,6 +367,10 @@ private static void Recreate(GPUResidentDrawerSettings settings)
363367
{
364368
LogMessage(message, severity);
365369
}
370+
371+
bool isInitialized = IsInitialized();
372+
if (wasInitialized != isInitialized)
373+
initializedChanged?.Invoke(wasInitialized, isInitialized);
366374
}
367375

368376
private IntPtr m_ContextIntPtr = IntPtr.Zero;

0 commit comments

Comments
 (0)