Skip to content

Commit

Permalink
update debug info to be relevant and useful again
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Nov 25, 2024
1 parent f966f8c commit eca45dc
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

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

private final ConcurrentLinkedDeque<ChunkJobResult<? extends BuilderTaskOutput>> buildResults = new ConcurrentLinkedDeque<>();
private ChunkJobCollector lastBlockingCollector;
private final JobEffortEstimator jobEffortEstimator = new JobEffortEstimator();
private ChunkJobCollector lastBlockingCollector;
private long thisFrameBlockingTasks;
private long nextFrameBlockingTasks;
private long deferredTasks;

private final ChunkRenderer chunkRenderer;

Expand Down Expand Up @@ -653,6 +657,10 @@ public void cleanupAndFlip() {
}

public void updateChunks(boolean updateImmediately) {
this.thisFrameBlockingTasks = 0;
this.nextFrameBlockingTasks = 0;
this.deferredTasks = 0;

var thisFrameBlockingCollector = this.lastBlockingCollector;
this.lastBlockingCollector = null;
if (thisFrameBlockingCollector == null) {
Expand All @@ -664,6 +672,7 @@ public void updateChunks(boolean updateImmediately) {
// and add all tasks to it so that they're waited on
this.submitSectionTasks(thisFrameBlockingCollector, thisFrameBlockingCollector, thisFrameBlockingCollector);

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

this.thisFrameBlockingTasks = thisFrameBlockingCollector.getSubmittedTaskCount();
this.nextFrameBlockingTasks = nextFrameBlockingCollector.getSubmittedTaskCount();
this.deferredTasks = deferredCollector.getSubmittedTaskCount();

// wait on this frame's blocking collector which contains the important tasks from this frame
// and semi-important tasks from the last frame
thisFrameBlockingCollector.awaitCompletion(this.builder);
Expand Down Expand Up @@ -998,19 +1011,29 @@ public Collection<String> getDebugStrings() {
count++;
}

// TODO: information about pending async culling tasks, restore some information about task scheduling?

list.add(String.format("Geometry Pool: %d/%d MiB (%d buffers)", MathUtil.toMib(deviceUsed), MathUtil.toMib(deviceAllocated), count));
list.add(String.format("Transfer Queue: %s", this.regions.getStagingBuffer().toString()));

list.add(String.format("Chunk Builder: Permits=%02d (%04d%%) | Busy=%02d | Total=%02d",
this.builder.getScheduledJobCount(), (int)(this.builder.getBusyFraction(this.lastFrameDuration) * 100), this.builder.getBusyThreadCount(), this.builder.getTotalThreadCount())
list.add(String.format("Chunk Builder: Schd=%02d | Busy=%02d (%04d%%) | Total=%02d",
this.builder.getScheduledJobCount(), this.builder.getBusyThreadCount(), (int)(this.builder.getBusyFraction(this.lastFrameDuration) * 100), this.builder.getTotalThreadCount())
);

list.add(String.format("Chunk Queues: U=%02d", this.buildResults.size()));
list.add(String.format("Tasks: N0=%03d | N1=%03d | Def=%03d, Recv=%03d",
this.thisFrameBlockingTasks, this.nextFrameBlockingTasks, this.deferredTasks, this.buildResults.size())
);

this.sortTriggering.addDebugStrings(list);

var taskSlots = new String[AsyncTaskType.VALUES.length];
for (var task : this.pendingTasks) {
var type = task.getTaskType();
taskSlots[type.ordinal()] = type.abbreviation;
}
list.add("Tree Builds: " + Arrays
.stream(taskSlots)
.map(slot -> slot == null ? "_" : slot)
.collect(Collectors.joining(" ")));

return list;
}

Expand All @@ -1036,11 +1059,7 @@ private String getCullTypeName() {
}
var cullTypeName = "-";
if (renderTreeCullType != null) {
cullTypeName = switch (renderTreeCullType) {
case WIDE -> "W";
case REGULAR -> "R";
case FRUSTUM -> "F";
};
cullTypeName = renderTreeCullType.abbreviation;
}
return cullTypeName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ public T call() throws Exception {
}

protected abstract T runTask();

public abstract AsyncTaskType getTaskType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.caffeinemc.mods.sodium.client.render.chunk.async;

import net.caffeinemc.mods.sodium.client.render.chunk.occlusion.CullType;

public enum AsyncTaskType {
FRUSTUM_CULL(CullType.FRUSTUM.abbreviation),
REGULAR_CULL(CullType.REGULAR.abbreviation),
WIDE_CULL(CullType.WIDE.abbreviation),
FRUSTUM_TASK_COLLECTION("T");

public static final AsyncTaskType[] VALUES = values();

public final String abbreviation;

AsyncTaskType(String abbreviation) {
this.abbreviation = abbreviation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ protected CullTask(Viewport viewport, float buildDistance, int frame, OcclusionC
}

public abstract CullType getCullType();

protected int getOcclusionToken() {
return (this.getCullType().ordinal() << 28) ^ this.frame;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public PendingTaskCollector.TaskListCollection getFrustumTaskLists() {
};
}

@Override
public AsyncTaskType getTaskType() {
return AsyncTaskType.FRUSTUM_CULL;
}

@Override
public CullType getCullType() {
return CullType.FRUSTUM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import it.unimi.dsi.fastutil.longs.Long2ReferenceMap;
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
import net.caffeinemc.mods.sodium.client.render.chunk.lists.FrustumTaskCollector;
import net.caffeinemc.mods.sodium.client.render.chunk.lists.PendingTaskCollector;
import net.caffeinemc.mods.sodium.client.render.chunk.lists.TaskSectionTree;
import net.caffeinemc.mods.sodium.client.render.viewport.Viewport;

Expand All @@ -25,4 +24,9 @@ public FrustumTaskListsResult runTask() {
var frustumTaskLists = collector.getPendingTaskLists();
return () -> frustumTaskLists;
}

@Override
public AsyncTaskType getTaskType() {
return AsyncTaskType.FRUSTUM_TASK_COLLECTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public PendingTaskCollector.TaskListCollection getGlobalTaskLists() {
};
}

@Override
public AsyncTaskType getTaskType() {
return switch (this.cullType) {
case WIDE -> AsyncTaskType.WIDE_CULL;
case REGULAR -> AsyncTaskType.REGULAR_CULL;
default -> throw new IllegalStateException("Unexpected value: " + this.cullType);
};
}

@Override
public CullType getCullType() {
return this.cullType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public void addSubmittedJob(ChunkJob job) {
public boolean hasBudgetRemaining() {
return this.duration > 0;
}

public long getSubmittedTaskCount() {
return this.submitted.size();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package net.caffeinemc.mods.sodium.client.render.chunk.occlusion;

public enum CullType {
WIDE(1, false, false),
REGULAR(0, false, false),
FRUSTUM(0, true, true);
WIDE("W", 1, false, false),
REGULAR("R", 0, false, false),
FRUSTUM("F", 0, true, true);

public final String abbreviation;
public final int bfsWidth;
public final boolean isFrustumTested;
public final boolean isFogCulled;

CullType(int bfsWidth, boolean isFrustumTested, boolean isFogCulled) {
CullType(String abbreviation, int bfsWidth, boolean isFrustumTested, boolean isFogCulled) {
this.abbreviation = abbreviation;
this.bfsWidth = bfsWidth;
this.isFrustumTested = isFrustumTested;
this.isFogCulled = isFogCulled;
Expand Down

0 comments on commit eca45dc

Please sign in to comment.