55import org .jetbrains .annotations .Nullable ;
66
77import dev .engine_room .flywheel .api .visualization .VisualizationManager ;
8+ import dev .engine_room .flywheel .backend .engine .AbstractInstancer ;
9+ import dev .engine_room .flywheel .backend .engine .DrawManager ;
810import dev .engine_room .flywheel .backend .gl .GlCompat ;
911import dev .engine_room .flywheel .impl .visualization .VisualizationManagerImpl ;
1012import dev .engine_room .flywheel .lib .memory .FlwMemoryTracker ;
1113import dev .engine_room .flywheel .lib .util .StringUtil ;
14+ import it .unimi .dsi .fastutil .ints .IntArrayList ;
15+ import it .unimi .dsi .fastutil .ints .IntComparators ;
16+ import it .unimi .dsi .fastutil .ints .IntList ;
1217import net .minecraft .ChatFormatting ;
1318import net .minecraft .client .Minecraft ;
1419import net .minecraft .core .Vec3i ;
@@ -32,10 +37,15 @@ public static StringBuilder appendLine(StringBuilder dst, String str) {
3237 }
3338
3439 /**
35- * Append a header to the given StringBuilder, preceded by two new lines for separation .
40+ * Append a header to the given StringBuilder.
3641 */
3742 public static void appendHeader (StringBuilder dst , String str ) {
38- dst .append ("\n \n ## " );
43+ dst .append ("\n ## " );
44+ dst .append (str );
45+ }
46+
47+ public static void appendHeader2 (StringBuilder dst , String str ) {
48+ dst .append ("\n ### " );
3949 dst .append (str );
4050 }
4151
@@ -92,7 +102,93 @@ private static void addBackendDebugInfo(@Nullable VisualizationManagerImpl manag
92102 var lut = engineImpl .lightStorage ()
93103 .createLut ();
94104
95- appendLine (out , "Light LUT Size: " ).append (lut .size () * Integer .BYTES );
105+ appendLine (out , "Light LUT Size: " ).append (lut .size () * Integer .BYTES )
106+ .append (" bytes" );
107+
108+ DrawManager <? extends AbstractInstancer <?>> drawManager = engineImpl .drawManager ();
109+ addMeshDebugInfo (out , drawManager );
110+ addInstancerDebugInfo (out , drawManager );
111+ }
112+
113+ private static void addInstancerDebugInfo (StringBuilder out , DrawManager <? extends AbstractInstancer <?>> drawManager ) {
114+ appendHeader2 (out , "Instancers" );
115+
116+ var instancers = drawManager .instancers ();
117+
118+ appendLine (out , "Count: " ).append (instancers .size ());
119+
120+ {
121+ IntList meshCountsToSort = new IntArrayList ();
122+ for (var instancerKey : instancers .keySet ()) {
123+ meshCountsToSort .add (instancerKey .model ()
124+ .meshes ()
125+ .size ());
126+ }
127+ appendPercentiles (out , "Mesh Count Percentiles" , meshCountsToSort );
128+ }
129+
130+ {
131+ int totalInstanceCount = 0 ;
132+ IntList instanceCountsToSort = new IntArrayList ();
133+ for (var instancer : instancers .values ()) {
134+ var instanceCount = instancer .instanceCount ();
135+ totalInstanceCount += instanceCount ;
136+ instanceCountsToSort .add (instanceCount );
137+ }
138+ appendLine (out , "Total Instance Count: " ).append (totalInstanceCount );
139+ appendPercentiles (out , "Instance Count Percentiles" , instanceCountsToSort );
140+ }
141+ }
142+
143+ private static void addMeshDebugInfo (StringBuilder out , DrawManager <? extends AbstractInstancer <?>> drawManager ) {
144+ var meshPool = drawManager .meshPool ()
145+ .pooledMeshes ();
146+
147+ appendHeader2 (out , "Meshes" );
148+
149+ var numMeshes = meshPool .size ();
150+
151+ appendLine (out , "Count: " ).append (numMeshes );
152+
153+ {
154+ int totalVertices = 0 ;
155+ IntList vertexCountsToSort = new IntArrayList ();
156+ for (var pooledMesh : meshPool ) {
157+ int vertexCount = pooledMesh .vertexCount ();
158+
159+ vertexCountsToSort .add (vertexCount );
160+ totalVertices += vertexCount ;
161+ }
162+
163+ appendLine (out , "Total Vertex Count: " ).append (totalVertices );
164+ appendPercentiles (out , "Vertex Count Percentiles" , vertexCountsToSort );
165+ }
166+ }
167+
168+ private static void appendPercentiles (StringBuilder out , String prefix , IntList unsortedCounts ) {
169+ var size = unsortedCounts .size ();
170+
171+ if (size == 0 ) {
172+ // Append
173+ appendLine (out , "Empty dataset, no percentiles." );
174+ return ;
175+ }
176+
177+ unsortedCounts .sort (IntComparators .NATURAL_COMPARATOR );
178+
179+ int p10Index = Math .min (size / 10 , size - 1 );
180+ int p50Index = Math .min (size / 2 , size - 1 );
181+ int p90Index = Math .min (size * 9 / 10 , size - 1 );
182+
183+ appendLine (out , prefix ).append (":\n " )
184+ .append ("P10: " )
185+ .append (unsortedCounts .getInt (p10Index ))
186+ .append (", P50: " )
187+ .append (unsortedCounts .getInt (p50Index ))
188+ .append (", P90: " )
189+ .append (unsortedCounts .getInt (p90Index ))
190+ .append (", Max: " )
191+ .append (unsortedCounts .getInt (size - 1 ));
96192 }
97193
98194 private static void addVisualizationManagerDebugInfo (@ Nullable VisualizationManagerImpl manager , StringBuilder out ) {
@@ -137,8 +233,10 @@ private static void addSystemDebugInfo(StringBuilder out) {
137233 .append (" (" )
138234 .append (System .getProperty ("os.arch" ))
139235 .append (")" );
140- appendLine (out , "Flw CPU Memory: " ).append (FlwMemoryTracker .getCpuMemory ());
141- appendLine (out , "Flw GPU Memory: " ).append (FlwMemoryTracker .getGpuMemory ());
236+ appendLine (out , "Flw CPU Memory: " ).append (FlwMemoryTracker .getCpuMemory ())
237+ .append (" bytes" );
238+ appendLine (out , "Flw GPU Memory: " ).append (FlwMemoryTracker .getGpuMemory ())
239+ .append (" bytes" );
142240 }
143241
144242 private static void addOpenGLDebugInfo (StringBuilder out ) {
0 commit comments