@@ -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
0 commit comments