Skip to content

Commit eca45dc

Browse files
committed
update debug info to be relevant and useful again
1 parent f966f8c commit eca45dc

File tree

9 files changed

+79
-20
lines changed

9 files changed

+79
-20
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/RenderSectionManager.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.util.concurrent.ConcurrentLinkedDeque;
5858
import java.util.concurrent.ExecutorService;
5959
import java.util.concurrent.Executors;
60+
import java.util.stream.Collectors;
6061

6162
public class RenderSectionManager {
6263
private static final float NEARBY_REBUILD_DISTANCE = Mth.square(16.0f);
@@ -70,8 +71,11 @@ public class RenderSectionManager {
7071
private final Long2ReferenceMap<RenderSection> sectionByPosition = new Long2ReferenceOpenHashMap<>();
7172

7273
private final ConcurrentLinkedDeque<ChunkJobResult<? extends BuilderTaskOutput>> buildResults = new ConcurrentLinkedDeque<>();
73-
private ChunkJobCollector lastBlockingCollector;
7474
private final JobEffortEstimator jobEffortEstimator = new JobEffortEstimator();
75+
private ChunkJobCollector lastBlockingCollector;
76+
private long thisFrameBlockingTasks;
77+
private long nextFrameBlockingTasks;
78+
private long deferredTasks;
7579

7680
private final ChunkRenderer chunkRenderer;
7781

@@ -653,6 +657,10 @@ public void cleanupAndFlip() {
653657
}
654658

655659
public void updateChunks(boolean updateImmediately) {
660+
this.thisFrameBlockingTasks = 0;
661+
this.nextFrameBlockingTasks = 0;
662+
this.deferredTasks = 0;
663+
656664
var thisFrameBlockingCollector = this.lastBlockingCollector;
657665
this.lastBlockingCollector = null;
658666
if (thisFrameBlockingCollector == null) {
@@ -664,6 +672,7 @@ public void updateChunks(boolean updateImmediately) {
664672
// and add all tasks to it so that they're waited on
665673
this.submitSectionTasks(thisFrameBlockingCollector, thisFrameBlockingCollector, thisFrameBlockingCollector);
666674

675+
this.thisFrameBlockingTasks = thisFrameBlockingCollector.getSubmittedTaskCount();
667676
thisFrameBlockingCollector.awaitCompletion(this.builder);
668677
} else {
669678
var nextFrameBlockingCollector = new ChunkJobCollector(this.buildResults::add);
@@ -678,6 +687,10 @@ public void updateChunks(boolean updateImmediately) {
678687
this.submitSectionTasks(nextFrameBlockingCollector, nextFrameBlockingCollector, deferredCollector);
679688
}
680689

690+
this.thisFrameBlockingTasks = thisFrameBlockingCollector.getSubmittedTaskCount();
691+
this.nextFrameBlockingTasks = nextFrameBlockingCollector.getSubmittedTaskCount();
692+
this.deferredTasks = deferredCollector.getSubmittedTaskCount();
693+
681694
// wait on this frame's blocking collector which contains the important tasks from this frame
682695
// and semi-important tasks from the last frame
683696
thisFrameBlockingCollector.awaitCompletion(this.builder);
@@ -998,19 +1011,29 @@ public Collection<String> getDebugStrings() {
9981011
count++;
9991012
}
10001013

1001-
// TODO: information about pending async culling tasks, restore some information about task scheduling?
1002-
10031014
list.add(String.format("Geometry Pool: %d/%d MiB (%d buffers)", MathUtil.toMib(deviceUsed), MathUtil.toMib(deviceAllocated), count));
10041015
list.add(String.format("Transfer Queue: %s", this.regions.getStagingBuffer().toString()));
10051016

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())
10081019
);
10091020

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+
);
10111024

10121025
this.sortTriggering.addDebugStrings(list);
10131026

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+
10141037
return list;
10151038
}
10161039

@@ -1036,11 +1059,7 @@ private String getCullTypeName() {
10361059
}
10371060
var cullTypeName = "-";
10381061
if (renderTreeCullType != null) {
1039-
cullTypeName = switch (renderTreeCullType) {
1040-
case WIDE -> "W";
1041-
case REGULAR -> "R";
1042-
case FRUSTUM -> "F";
1043-
};
1062+
cullTypeName = renderTreeCullType.abbreviation;
10441063
}
10451064
return cullTypeName;
10461065
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/async/AsyncRenderTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ public T call() throws Exception {
7373
}
7474

7575
protected abstract T runTask();
76+
77+
public abstract AsyncTaskType getTaskType();
7678
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.caffeinemc.mods.sodium.client.render.chunk.async;
2+
3+
import net.caffeinemc.mods.sodium.client.render.chunk.occlusion.CullType;
4+
5+
public enum AsyncTaskType {
6+
FRUSTUM_CULL(CullType.FRUSTUM.abbreviation),
7+
REGULAR_CULL(CullType.REGULAR.abbreviation),
8+
WIDE_CULL(CullType.WIDE.abbreviation),
9+
FRUSTUM_TASK_COLLECTION("T");
10+
11+
public static final AsyncTaskType[] VALUES = values();
12+
13+
public final String abbreviation;
14+
15+
AsyncTaskType(String abbreviation) {
16+
this.abbreviation = abbreviation;
17+
}
18+
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/async/CullTask.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ protected CullTask(Viewport viewport, float buildDistance, int frame, OcclusionC
1515
}
1616

1717
public abstract CullType getCullType();
18-
19-
protected int getOcclusionToken() {
20-
return (this.getCullType().ordinal() << 28) ^ this.frame;
21-
}
2218
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/async/FrustumCullTask.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public PendingTaskCollector.TaskListCollection getFrustumTaskLists() {
4949
};
5050
}
5151

52+
@Override
53+
public AsyncTaskType getTaskType() {
54+
return AsyncTaskType.FRUSTUM_CULL;
55+
}
56+
5257
@Override
5358
public CullType getCullType() {
5459
return CullType.FRUSTUM;

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/async/FrustumTaskCollectionTask.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
44
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
55
import net.caffeinemc.mods.sodium.client.render.chunk.lists.FrustumTaskCollector;
6-
import net.caffeinemc.mods.sodium.client.render.chunk.lists.PendingTaskCollector;
76
import net.caffeinemc.mods.sodium.client.render.chunk.lists.TaskSectionTree;
87
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;
98

@@ -25,4 +24,9 @@ public FrustumTaskListsResult runTask() {
2524
var frustumTaskLists = collector.getPendingTaskLists();
2625
return () -> frustumTaskLists;
2726
}
27+
28+
@Override
29+
public AsyncTaskType getTaskType() {
30+
return AsyncTaskType.FRUSTUM_TASK_COLLECTION;
31+
}
2832
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/async/GlobalCullTask.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ public PendingTaskCollector.TaskListCollection getGlobalTaskLists() {
6363
};
6464
}
6565

66+
@Override
67+
public AsyncTaskType getTaskType() {
68+
return switch (this.cullType) {
69+
case WIDE -> AsyncTaskType.WIDE_CULL;
70+
case REGULAR -> AsyncTaskType.REGULAR_CULL;
71+
default -> throw new IllegalStateException("Unexpected value: " + this.cullType);
72+
};
73+
}
74+
6675
@Override
6776
public CullType getCullType() {
6877
return this.cullType;

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/executor/ChunkJobCollector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ public void addSubmittedJob(ChunkJob job) {
5353
public boolean hasBudgetRemaining() {
5454
return this.duration > 0;
5555
}
56+
57+
public long getSubmittedTaskCount() {
58+
return this.submitted.size();
59+
}
5660
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/occlusion/CullType.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package net.caffeinemc.mods.sodium.client.render.chunk.occlusion;
22

33
public enum CullType {
4-
WIDE(1, false, false),
5-
REGULAR(0, false, false),
6-
FRUSTUM(0, true, true);
4+
WIDE("W", 1, false, false),
5+
REGULAR("R", 0, false, false),
6+
FRUSTUM("F", 0, true, true);
77

8+
public final String abbreviation;
89
public final int bfsWidth;
910
public final boolean isFrustumTested;
1011
public final boolean isFogCulled;
1112

12-
CullType(int bfsWidth, boolean isFrustumTested, boolean isFogCulled) {
13+
CullType(String abbreviation, int bfsWidth, boolean isFrustumTested, boolean isFogCulled) {
14+
this.abbreviation = abbreviation;
1315
this.bfsWidth = bfsWidth;
1416
this.isFrustumTested = isFrustumTested;
1517
this.isFogCulled = isFogCulled;

0 commit comments

Comments
 (0)