Smarter translucency sorting #42

Merged
embeddedt merged 24 commits from rdh/celeritas:ts into stonecutter 2026-09-16 11:25:42 -04:00
3 changed files with 41 additions and 5 deletions
Showing only changes of commit 00724cb613 - Show all commits

No files matched your search

@@ -38,6 +38,7 @@ import org.embeddedt.embeddium.impl.render.viewport.Viewport;
import org.embeddedt.embeddium.impl.render.viewport.frustum.ShadowSearchFrustum;
import org.embeddedt.embeddium.impl.util.PositionUtil;
import org.embeddedt.embeddium.impl.util.iterator.ByteIterator;
import org.embeddedt.embeddium.impl.render.chunk.compile.ChunkSortOutput;
import org.embeddedt.embeddium.impl.render.chunk.sorting.CutPlaneIndex;
import org.embeddedt.embeddium.impl.render.chunk.sorting.PartitionTree;
import org.embeddedt.embeddium.impl.render.chunk.sorting.SortState;
@@ -94,6 +95,10 @@ public abstract class RenderSectionManager {
private final CutPlaneIndex<RenderSection> cutPlaneIndex = new CutPlaneIndex<>();
private final ChunkJobMetricsTracker.MetricsData treeSortMetrics = new ChunkJobMetricsTracker.MetricsData();
private long treeStatsWindowStart = System.nanoTime();
private int treeTriggersThisSecond, treeTriggersLastSecond;
@Getter
private final RenderPassConfiguration<?> renderPassConfiguration;
@@ -272,6 +277,14 @@ public abstract class RenderSectionManager {
}
private void checkTranslucencyChange() {
long now = System.nanoTime();
if (now - this.treeStatsWindowStart >= ChunkJobMetricsTracker.OBSERVATION_COUNT_TIME) {
this.treeTriggersLastSecond = this.treeTriggersThisSecond;
this.treeTriggersThisSecond = 0;
this.treeSortMetrics.flipInterval();
this.treeStatsWindowStart = now;
}
if(cameraBlockPosition == null)
return;
@@ -358,6 +371,8 @@ public abstract class RenderSectionManager {
this.previousCameraPosition.x, this.previousCameraPosition.y, this.previousCameraPosition.z,
this.cameraPosition.x, this.cameraPosition.y, this.cameraPosition.z,
section -> {
this.treeTriggersThisSecond++;
ChunkUpdateType update = ChunkUpdateType.getPromotionUpdateType(section.getPendingUpdate(),
(allowImportant && this.shouldPrioritizeRebuild(section)) ? ChunkUpdateType.IMPORTANT_SORT : ChunkUpdateType.SORT);
@@ -732,6 +747,10 @@ public abstract class RenderSectionManager {
while ((result = this.buildResults.poll()) != null) {
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
this.jobMetricsTracker.collectMetrics(successfulResult);
if (successfulResult.output() instanceof ChunkSortOutput sort && sort.render.isTreeSorted() && successfulResult.executionTimeNanos() >= 0) {
this.treeSortMetrics.collect(successfulResult.executionTimeNanos());
}
results.add(successfulResult);
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
failure.abort();
@@ -1087,14 +1106,13 @@ public abstract class RenderSectionManager {
var rebuildLists = this.getCurrentRenderListManager().getRebuildLists();
list.add(String.format("Chunk Queues: U=%02d (P0=%03d | P1=%03d | P2=%03d) S=%03d/%03d I=%03d",
list.add(String.format("Chunk Queues: U=%02d (P0=%03d | P1=%03d | P2=%03d) S=%03d/%03d",
this.buildResults.size(),
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_REBUILD),
rebuildLists.getUpdateCount(ChunkUpdateType.REBUILD),
rebuildLists.getUpdateCount(ChunkUpdateType.INITIAL_BUILD),
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_SORT),
rebuildLists.getUpdateCount(ChunkUpdateType.SORT),
this.cutPlaneIndex.size()
rebuildLists.getUpdateCount(ChunkUpdateType.SORT)
));
var debugStats = renderListManager.getDebugStatistics();
@@ -1118,6 +1136,10 @@ public abstract class RenderSectionManager {
if (renderListManager.getRenderLists().getPasses().stream().anyMatch(TerrainRenderPass::isSorted)) {
list.add(debugStats.getSortingString());
list.add(String.format("Tree Sort: %d planes, %d trig/s, %d sorts/s, %s avg",
this.cutPlaneIndex.planeCount(), this.treeTriggersLastSecond,
this.treeSortMetrics.getObservationsInLastTimeInterval(),
TimeUtil.stringifyTime((long) this.treeSortMetrics.getAverageNanos(0), TimeUnit.NANOSECONDS)));
}
return list;
@@ -64,6 +64,11 @@ public class ChunkJobMetricsTracker {
}
}
public void flipInterval() {
this.observationsInLastTimeInterval = this.observationsInCurrentTimeInterval;
this.observationsInCurrentTimeInterval = 0;
}
public int getObservationsInLastTimeInterval() {
return this.observationsInLastTimeInterval;
}
@@ -103,8 +108,7 @@ public class ChunkJobMetricsTracker {
long time = System.nanoTime();
if ((time - lastTimeIntervalFlip) >= OBSERVATION_COUNT_TIME) {
for (var data : metricsByTask.values()) {
data.observationsInLastTimeInterval = data.observationsInCurrentTimeInterval;
data.observationsInCurrentTimeInterval = 0;
data.flipInterval();
}
lastTimeIntervalFlip = time;
}
@@ -23,6 +23,8 @@ public final class CutPlaneIndex<T> {
private final ReferenceOpenHashSet<T> reported = new ReferenceOpenHashSet<>();
private int planeCount;
public void put(T owner, float[][] cutsByAxis, int originX, int originY, int originZ) {
remove(owner);
@@ -31,6 +33,8 @@ public final class CutPlaneIndex<T> {
return;
}
this.planeCount += cutsByAxis[0].length + cutsByAxis[1].length + cutsByAxis[2].length;
int[] origin = { originX, originY, originZ };
long[][] buckets = new long[3][];
@@ -66,6 +70,8 @@ public final class CutPlaneIndex<T> {
return;
}
this.planeCount -= registration.cuts[0].length + registration.cuts[1].length + registration.cuts[2].length;
for (int axis = 0; axis < 3; axis++) {
var map = this.bucketsByAxis[axis];
@@ -152,4 +158,8 @@ public final class CutPlaneIndex<T> {
public int size() {
return this.registrations.size();
}
public int planeCount() {
return this.planeCount;
}
}