57
57
import java .util .concurrent .ConcurrentLinkedDeque ;
58
58
import java .util .concurrent .ExecutorService ;
59
59
import java .util .concurrent .Executors ;
60
+ import java .util .stream .Collectors ;
60
61
61
62
public class RenderSectionManager {
62
63
private static final float NEARBY_REBUILD_DISTANCE = Mth .square (16.0f );
@@ -70,8 +71,11 @@ public class RenderSectionManager {
70
71
private final Long2ReferenceMap <RenderSection > sectionByPosition = new Long2ReferenceOpenHashMap <>();
71
72
72
73
private final ConcurrentLinkedDeque <ChunkJobResult <? extends BuilderTaskOutput >> buildResults = new ConcurrentLinkedDeque <>();
73
- private ChunkJobCollector lastBlockingCollector ;
74
74
private final JobEffortEstimator jobEffortEstimator = new JobEffortEstimator ();
75
+ private ChunkJobCollector lastBlockingCollector ;
76
+ private long thisFrameBlockingTasks ;
77
+ private long nextFrameBlockingTasks ;
78
+ private long deferredTasks ;
75
79
76
80
private final ChunkRenderer chunkRenderer ;
77
81
@@ -653,6 +657,10 @@ public void cleanupAndFlip() {
653
657
}
654
658
655
659
public void updateChunks (boolean updateImmediately ) {
660
+ this .thisFrameBlockingTasks = 0 ;
661
+ this .nextFrameBlockingTasks = 0 ;
662
+ this .deferredTasks = 0 ;
663
+
656
664
var thisFrameBlockingCollector = this .lastBlockingCollector ;
657
665
this .lastBlockingCollector = null ;
658
666
if (thisFrameBlockingCollector == null ) {
@@ -664,6 +672,7 @@ public void updateChunks(boolean updateImmediately) {
664
672
// and add all tasks to it so that they're waited on
665
673
this .submitSectionTasks (thisFrameBlockingCollector , thisFrameBlockingCollector , thisFrameBlockingCollector );
666
674
675
+ this .thisFrameBlockingTasks = thisFrameBlockingCollector .getSubmittedTaskCount ();
667
676
thisFrameBlockingCollector .awaitCompletion (this .builder );
668
677
} else {
669
678
var nextFrameBlockingCollector = new ChunkJobCollector (this .buildResults ::add );
@@ -678,6 +687,10 @@ public void updateChunks(boolean updateImmediately) {
678
687
this .submitSectionTasks (nextFrameBlockingCollector , nextFrameBlockingCollector , deferredCollector );
679
688
}
680
689
690
+ this .thisFrameBlockingTasks = thisFrameBlockingCollector .getSubmittedTaskCount ();
691
+ this .nextFrameBlockingTasks = nextFrameBlockingCollector .getSubmittedTaskCount ();
692
+ this .deferredTasks = deferredCollector .getSubmittedTaskCount ();
693
+
681
694
// wait on this frame's blocking collector which contains the important tasks from this frame
682
695
// and semi-important tasks from the last frame
683
696
thisFrameBlockingCollector .awaitCompletion (this .builder );
@@ -998,19 +1011,29 @@ public Collection<String> getDebugStrings() {
998
1011
count ++;
999
1012
}
1000
1013
1001
- // TODO: information about pending async culling tasks, restore some information about task scheduling?
1002
-
1003
1014
list .add (String .format ("Geometry Pool: %d/%d MiB (%d buffers)" , MathUtil .toMib (deviceUsed ), MathUtil .toMib (deviceAllocated ), count ));
1004
1015
list .add (String .format ("Transfer Queue: %s" , this .regions .getStagingBuffer ().toString ()));
1005
1016
1006
- list .add (String .format ("Chunk Builder: Permits =%02d (%04d%%) | Busy=%02d | Total=%02d" ,
1007
- this .builder .getScheduledJobCount (), ( int )(this .builder .getBusyFraction (this .lastFrameDuration ) * 100 ), this . builder . getBusyThreadCount ( ), this .builder .getTotalThreadCount ())
1017
+ list .add (String .format ("Chunk Builder: Schd =%02d | Busy=%02d (%04d%%) | Total=%02d" ,
1018
+ this .builder .getScheduledJobCount (), this . builder . getBusyThreadCount (), ( int )(this .builder .getBusyFraction (this .lastFrameDuration ) * 100 ), this .builder .getTotalThreadCount ())
1008
1019
);
1009
1020
1010
- list .add (String .format ("Chunk Queues: U=%02d" , this .buildResults .size ()));
1021
+ list .add (String .format ("Tasks: N0=%03d | N1=%03d | Def=%03d, Recv=%03d" ,
1022
+ this .thisFrameBlockingTasks , this .nextFrameBlockingTasks , this .deferredTasks , this .buildResults .size ())
1023
+ );
1011
1024
1012
1025
this .sortTriggering .addDebugStrings (list );
1013
1026
1027
+ var taskSlots = new String [AsyncTaskType .VALUES .length ];
1028
+ for (var task : this .pendingTasks ) {
1029
+ var type = task .getTaskType ();
1030
+ taskSlots [type .ordinal ()] = type .abbreviation ;
1031
+ }
1032
+ list .add ("Tree Builds: " + Arrays
1033
+ .stream (taskSlots )
1034
+ .map (slot -> slot == null ? "_" : slot )
1035
+ .collect (Collectors .joining (" " )));
1036
+
1014
1037
return list ;
1015
1038
}
1016
1039
@@ -1036,11 +1059,7 @@ private String getCullTypeName() {
1036
1059
}
1037
1060
var cullTypeName = "-" ;
1038
1061
if (renderTreeCullType != null ) {
1039
- cullTypeName = switch (renderTreeCullType ) {
1040
- case WIDE -> "W" ;
1041
- case REGULAR -> "R" ;
1042
- case FRUSTUM -> "F" ;
1043
- };
1062
+ cullTypeName = renderTreeCullType .abbreviation ;
1044
1063
}
1045
1064
return cullTypeName ;
1046
1065
}
0 commit comments