1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using Unity . Collections ;
4
+ #if UNITY_EDITOR
5
+ using UnityEditor ;
6
+ #endif
4
7
using static UnityEngine . Rendering . DebugUI ;
5
8
using static UnityEngine . Rendering . DebugUI . Widget ;
6
9
@@ -106,6 +109,7 @@ private static InstanceOcclusionEventStats GetInstanceOcclusionEventStats(int pa
106
109
else
107
110
return new InstanceOcclusionEventStats ( ) ;
108
111
}
112
+
109
113
static class Strings
110
114
{
111
115
public const string drawerSettingsContainerName = "GPU Resident Drawer Settings" ;
@@ -144,6 +148,7 @@ private static int GetInstanceOcclusionEventCount()
144
148
{
145
149
return GPUResidentDrawer . GetDebugStats ( ) ? . instanceOcclusionEventStats . Length ?? 0 ;
146
150
}
151
+
147
152
private static DebugUI . Table . Row AddInstanceCullerViewDataRow ( int viewIndex )
148
153
{
149
154
return new DebugUI . Table . Row
@@ -154,9 +159,32 @@ private static DebugUI.Table.Row AddInstanceCullerViewDataRow(int viewIndex)
154
159
children =
155
160
{
156
161
new DebugUI . Value { displayName = "View Type" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceCullerViewStats ( viewIndex ) . viewType } ,
157
- new DebugUI . Value { displayName = "View Instance ID" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceCullerViewStats ( viewIndex ) . viewInstanceID } ,
162
+ new DebugUI . Value { displayName = "View Instance ID" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
163
+ {
164
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
165
+ #if UNITY_EDITOR
166
+ Object view = EditorUtility . InstanceIDToObject ( viewStats . viewInstanceID ) ;
167
+ if ( view )
168
+ {
169
+ return $ "{ viewStats . viewInstanceID } ({ view . name } )";
170
+ }
171
+ #endif
172
+ return viewStats . viewInstanceID ;
173
+ }
174
+ } ,
158
175
new DebugUI . Value { displayName = "Split Index" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceCullerViewStats ( viewIndex ) . splitIndex } ,
159
- new DebugUI . Value { displayName = "Visible Instances" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceCullerViewStats ( viewIndex ) . visibleInstances } ,
176
+ new DebugUI . Value { displayName = "Visible Instances CPU | GPU" , tooltip = "Visible instances after CPU culling and after GPU culling." , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
177
+ {
178
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
179
+ return $ "{ viewStats . visibleInstancesOnCPU } | { viewStats . visibleInstancesOnGPU } ";
180
+ }
181
+ } ,
182
+ new DebugUI . Value { displayName = "Visible Primitives CPU | GPU" , tooltip = "Visible primitives after CPU culling and after GPU culling." , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
183
+ {
184
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
185
+ return $ "{ viewStats . visiblePrimitivesOnCPU } | { viewStats . visiblePrimitivesOnGPU } ";
186
+ }
187
+ } ,
160
188
new DebugUI . Value { displayName = "Draw Commands" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceCullerViewStats ( viewIndex ) . drawCommands } ,
161
189
}
162
190
} ;
@@ -182,6 +210,16 @@ private static object CulledInstancesString(in InstanceOcclusionEventStats stats
182
210
return ( stats . eventType == InstanceOcclusionEventType . OcclusionTest ) ? stats . culledInstances : "-" ;
183
211
}
184
212
213
+ private static object VisiblePrimitivesString ( in InstanceOcclusionEventStats stats )
214
+ {
215
+ return ( stats . eventType == InstanceOcclusionEventType . OcclusionTest ) ? stats . visiblePrimitives : "-" ;
216
+ }
217
+
218
+ private static object CulledPrimitivesString ( in InstanceOcclusionEventStats stats )
219
+ {
220
+ return ( stats . eventType == InstanceOcclusionEventType . OcclusionTest ) ? stats . culledPrimitives : "-" ;
221
+ }
222
+
185
223
private static DebugUI . Table . Row AddInstanceOcclusionPassDataRow ( int eventIndex )
186
224
{
187
225
return new DebugUI . Table . Row
@@ -191,13 +229,27 @@ private static DebugUI.Table.Row AddInstanceOcclusionPassDataRow(int eventIndex)
191
229
isHiddenCallback = ( ) => { return eventIndex >= GetInstanceOcclusionEventCount ( ) ; } ,
192
230
children =
193
231
{
194
- new DebugUI . Value { displayName = "View Instance ID" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => GetInstanceOcclusionEventStats ( eventIndex ) . viewInstanceID } ,
232
+ new DebugUI . Value { displayName = "View Instance ID" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
233
+ {
234
+ var eventStats = GetInstanceOcclusionEventStats ( eventIndex ) ;
235
+ #if UNITY_EDITOR
236
+ Object view = EditorUtility . InstanceIDToObject ( eventStats . viewInstanceID ) ;
237
+ if ( view )
238
+ {
239
+ return $ "{ eventStats . viewInstanceID } ({ view . name } )";
240
+ }
241
+ #endif
242
+ return eventStats . viewInstanceID ;
243
+ }
244
+ } ,
195
245
new DebugUI . Value { displayName = "Event Type" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => $ "{ GetInstanceOcclusionEventStats ( eventIndex ) . eventType } " } ,
196
246
new DebugUI . Value { displayName = "Occluder Version" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => OccluderVersionString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } ,
197
247
new DebugUI . Value { displayName = "Subview Mask" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => $ "0x{ GetInstanceOcclusionEventStats ( eventIndex ) . subviewMask : X} " } ,
198
248
new DebugUI . Value { displayName = "Occlusion Test" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => $ "{ OcclusionTestString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } " } ,
199
249
new DebugUI . Value { displayName = "Visible Instances" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => VisibleInstancesString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } ,
200
250
new DebugUI . Value { displayName = "Culled Instances" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => CulledInstancesString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } ,
251
+ new DebugUI . Value { displayName = "Visible Primitives" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => VisiblePrimitivesString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } ,
252
+ new DebugUI . Value { displayName = "Culled Primitives" , refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) => CulledPrimitivesString ( GetInstanceOcclusionEventStats ( eventIndex ) ) } ,
201
253
}
202
254
} ;
203
255
}
@@ -298,6 +350,104 @@ private void AddInstanceCullingStatsWidget(DebugDisplayGPUResidentDrawer data)
298
350
}
299
351
} ) ;
300
352
353
+ instanceCullerStats . children . Add ( new DebugUI . ValueTuple ( )
354
+ {
355
+ displayName = "Total Visible Instances (Cameras | Lights | Both)" ,
356
+ values = new [ ]
357
+ {
358
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
359
+ {
360
+ int totalGRDInstances = 0 ;
361
+
362
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
363
+ {
364
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
365
+ if ( viewStats . viewType == BatchCullingViewType . Camera )
366
+ totalGRDInstances += viewStats . visibleInstancesOnGPU ;
367
+ }
368
+ return totalGRDInstances ;
369
+ }
370
+ } ,
371
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
372
+ {
373
+ int totalGRDInstances = 0 ;
374
+
375
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
376
+ {
377
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
378
+ if ( viewStats . viewType == BatchCullingViewType . Light )
379
+ totalGRDInstances += viewStats . visibleInstancesOnGPU ;
380
+ }
381
+ return totalGRDInstances ;
382
+ }
383
+ } ,
384
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
385
+ {
386
+ int totalGRDInstances = 0 ;
387
+
388
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
389
+ {
390
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
391
+ if ( viewStats . viewType != BatchCullingViewType . Filtering
392
+ && viewStats . viewType != BatchCullingViewType . Picking
393
+ && viewStats . viewType != BatchCullingViewType . SelectionOutline )
394
+ totalGRDInstances += viewStats . visibleInstancesOnGPU ;
395
+ }
396
+ return totalGRDInstances ;
397
+ }
398
+ } ,
399
+ }
400
+ } ) ;
401
+
402
+ instanceCullerStats . children . Add ( new DebugUI . ValueTuple ( )
403
+ {
404
+ displayName = "Total Visible Primitives (Cameras | Lights | Both)" ,
405
+ values = new [ ]
406
+ {
407
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
408
+ {
409
+ int totalGRDPrimitives = 0 ;
410
+
411
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
412
+ {
413
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
414
+ if ( viewStats . viewType == BatchCullingViewType . Camera )
415
+ totalGRDPrimitives += viewStats . visiblePrimitivesOnGPU ;
416
+ }
417
+ return totalGRDPrimitives ;
418
+ }
419
+ } ,
420
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
421
+ {
422
+ int totalGRDPrimitives = 0 ;
423
+
424
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
425
+ {
426
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
427
+ if ( viewStats . viewType == BatchCullingViewType . Light )
428
+ totalGRDPrimitives += viewStats . visiblePrimitivesOnGPU ;
429
+ }
430
+ return totalGRDPrimitives ;
431
+ }
432
+ } ,
433
+ new DebugUI . Value { refreshRate = k_RefreshRate , formatString = k_FormatString , getter = ( ) =>
434
+ {
435
+ int totalGRDPrimitives = 0 ;
436
+
437
+ for ( int viewIndex = 0 ; viewIndex < GetInstanceCullerViewCount ( ) ; viewIndex ++ )
438
+ {
439
+ var viewStats = GetInstanceCullerViewStats ( viewIndex ) ;
440
+ if ( viewStats . viewType != BatchCullingViewType . Filtering
441
+ && viewStats . viewType != BatchCullingViewType . Picking
442
+ && viewStats . viewType != BatchCullingViewType . SelectionOutline )
443
+ totalGRDPrimitives += viewStats . visiblePrimitivesOnGPU ;
444
+ }
445
+ return totalGRDPrimitives ;
446
+ }
447
+ } ,
448
+ }
449
+ } ) ;
450
+
301
451
DebugUI . Table viewTable = new DebugUI . Table
302
452
{
303
453
displayName = "" ,
0 commit comments