Smarter translucency sorting #42
No files matched your search
+25
-3
@@ -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.render.viewport.frustum.ShadowSearchFrustum;
|
||||||
import org.embeddedt.embeddium.impl.util.PositionUtil;
|
import org.embeddedt.embeddium.impl.util.PositionUtil;
|
||||||
import org.embeddedt.embeddium.impl.util.iterator.ByteIterator;
|
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.CutPlaneIndex;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.sorting.PartitionTree;
|
import org.embeddedt.embeddium.impl.render.chunk.sorting.PartitionTree;
|
||||||
import org.embeddedt.embeddium.impl.render.chunk.sorting.SortState;
|
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 CutPlaneIndex<RenderSection> cutPlaneIndex = new CutPlaneIndex<>();
|
||||||
|
|
||||||
|
private final ChunkJobMetricsTracker.MetricsData treeSortMetrics = new ChunkJobMetricsTracker.MetricsData();
|
||||||
|
private long treeStatsWindowStart = System.nanoTime();
|
||||||
|
private int treeTriggersThisSecond, treeTriggersLastSecond;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final RenderPassConfiguration<?> renderPassConfiguration;
|
private final RenderPassConfiguration<?> renderPassConfiguration;
|
||||||
|
|
||||||
@@ -272,6 +277,14 @@ public abstract class RenderSectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkTranslucencyChange() {
|
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)
|
if(cameraBlockPosition == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -358,6 +371,8 @@ public abstract class RenderSectionManager {
|
|||||||
this.previousCameraPosition.x, this.previousCameraPosition.y, this.previousCameraPosition.z,
|
this.previousCameraPosition.x, this.previousCameraPosition.y, this.previousCameraPosition.z,
|
||||||
this.cameraPosition.x, this.cameraPosition.y, this.cameraPosition.z,
|
this.cameraPosition.x, this.cameraPosition.y, this.cameraPosition.z,
|
||||||
section -> {
|
section -> {
|
||||||
|
this.treeTriggersThisSecond++;
|
||||||
|
|
||||||
ChunkUpdateType update = ChunkUpdateType.getPromotionUpdateType(section.getPendingUpdate(),
|
ChunkUpdateType update = ChunkUpdateType.getPromotionUpdateType(section.getPendingUpdate(),
|
||||||
(allowImportant && this.shouldPrioritizeRebuild(section)) ? ChunkUpdateType.IMPORTANT_SORT : ChunkUpdateType.SORT);
|
(allowImportant && this.shouldPrioritizeRebuild(section)) ? ChunkUpdateType.IMPORTANT_SORT : ChunkUpdateType.SORT);
|
||||||
|
|
||||||
@@ -732,6 +747,10 @@ public abstract class RenderSectionManager {
|
|||||||
while ((result = this.buildResults.poll()) != null) {
|
while ((result = this.buildResults.poll()) != null) {
|
||||||
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
|
if (result instanceof ChunkJobResult.Success<? extends ChunkTaskOutput> successfulResult) {
|
||||||
this.jobMetricsTracker.collectMetrics(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);
|
results.add(successfulResult);
|
||||||
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
|
} else if (result instanceof ChunkJobResult.Failure<? extends ChunkTaskOutput> failure) {
|
||||||
failure.abort();
|
failure.abort();
|
||||||
@@ -1087,14 +1106,13 @@ public abstract class RenderSectionManager {
|
|||||||
|
|
||||||
var rebuildLists = this.getCurrentRenderListManager().getRebuildLists();
|
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(),
|
this.buildResults.size(),
|
||||||
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_REBUILD),
|
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_REBUILD),
|
||||||
rebuildLists.getUpdateCount(ChunkUpdateType.REBUILD),
|
rebuildLists.getUpdateCount(ChunkUpdateType.REBUILD),
|
||||||
rebuildLists.getUpdateCount(ChunkUpdateType.INITIAL_BUILD),
|
rebuildLists.getUpdateCount(ChunkUpdateType.INITIAL_BUILD),
|
||||||
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_SORT),
|
rebuildLists.getUpdateCount(ChunkUpdateType.IMPORTANT_SORT),
|
||||||
rebuildLists.getUpdateCount(ChunkUpdateType.SORT),
|
rebuildLists.getUpdateCount(ChunkUpdateType.SORT)
|
||||||
this.cutPlaneIndex.size()
|
|
||||||
));
|
));
|
||||||
|
|
||||||
var debugStats = renderListManager.getDebugStatistics();
|
var debugStats = renderListManager.getDebugStatistics();
|
||||||
@@ -1118,6 +1136,10 @@ public abstract class RenderSectionManager {
|
|||||||
|
|
||||||
if (renderListManager.getRenderLists().getPasses().stream().anyMatch(TerrainRenderPass::isSorted)) {
|
if (renderListManager.getRenderLists().getPasses().stream().anyMatch(TerrainRenderPass::isSorted)) {
|
||||||
list.add(debugStats.getSortingString());
|
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;
|
return list;
|
||||||
|
|||||||
+6
-2
@@ -64,6 +64,11 @@ public class ChunkJobMetricsTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void flipInterval() {
|
||||||
|
this.observationsInLastTimeInterval = this.observationsInCurrentTimeInterval;
|
||||||
|
this.observationsInCurrentTimeInterval = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public int getObservationsInLastTimeInterval() {
|
public int getObservationsInLastTimeInterval() {
|
||||||
return this.observationsInLastTimeInterval;
|
return this.observationsInLastTimeInterval;
|
||||||
}
|
}
|
||||||
@@ -103,8 +108,7 @@ public class ChunkJobMetricsTracker {
|
|||||||
long time = System.nanoTime();
|
long time = System.nanoTime();
|
||||||
if ((time - lastTimeIntervalFlip) >= OBSERVATION_COUNT_TIME) {
|
if ((time - lastTimeIntervalFlip) >= OBSERVATION_COUNT_TIME) {
|
||||||
for (var data : metricsByTask.values()) {
|
for (var data : metricsByTask.values()) {
|
||||||
data.observationsInLastTimeInterval = data.observationsInCurrentTimeInterval;
|
data.flipInterval();
|
||||||
data.observationsInCurrentTimeInterval = 0;
|
|
||||||
}
|
}
|
||||||
lastTimeIntervalFlip = time;
|
lastTimeIntervalFlip = time;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -23,6 +23,8 @@ public final class CutPlaneIndex<T> {
|
|||||||
|
|
||||||
private final ReferenceOpenHashSet<T> reported = new ReferenceOpenHashSet<>();
|
private final ReferenceOpenHashSet<T> reported = new ReferenceOpenHashSet<>();
|
||||||
|
|
||||||
|
private int planeCount;
|
||||||
|
|
||||||
public void put(T owner, float[][] cutsByAxis, int originX, int originY, int originZ) {
|
public void put(T owner, float[][] cutsByAxis, int originX, int originY, int originZ) {
|
||||||
remove(owner);
|
remove(owner);
|
||||||
|
|
||||||
@@ -31,6 +33,8 @@ public final class CutPlaneIndex<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.planeCount += cutsByAxis[0].length + cutsByAxis[1].length + cutsByAxis[2].length;
|
||||||
|
|
||||||
int[] origin = { originX, originY, originZ };
|
int[] origin = { originX, originY, originZ };
|
||||||
long[][] buckets = new long[3][];
|
long[][] buckets = new long[3][];
|
||||||
|
|
||||||
@@ -66,6 +70,8 @@ public final class CutPlaneIndex<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.planeCount -= registration.cuts[0].length + registration.cuts[1].length + registration.cuts[2].length;
|
||||||
|
|
||||||
for (int axis = 0; axis < 3; axis++) {
|
for (int axis = 0; axis < 3; axis++) {
|
||||||
var map = this.bucketsByAxis[axis];
|
var map = this.bucketsByAxis[axis];
|
||||||
|
|
||||||
@@ -152,4 +158,8 @@ public final class CutPlaneIndex<T> {
|
|||||||
public int size() {
|
public int size() {
|
||||||
return this.registrations.size();
|
return this.registrations.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int planeCount() {
|
||||||
|
return this.planeCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user