Skip to content

Commit 19d591e

Browse files
committed
Remove redundant code for implementation of the sort task defer mode.
There was previously an implementation for controlling sort task deferring as part of the sorting code. A different implementation of essentially the same concept but for rebuild tasks was added later. Now they both use the newer approach, which simplifies the task submit code.
1 parent 9da93ab commit 19d591e

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public static boolean isRebuildWithSort(int type) {
3737
return (isRebuild(type) || isInitialBuild(type)) && isSort(type);
3838
}
3939

40-
public static TaskQueueType getQueueType(int type, TaskQueueType importantRebuildQueueType) {
40+
public static TaskQueueType getQueueType(int type, TaskQueueType importantRebuildQueueType, TaskQueueType importantSortQueueType) {
4141
if (isInitialBuild(type)) {
4242
return TaskQueueType.INITIAL_BUILD;
4343
}
4444
if (isImportant(type)) {
4545
if (isRebuild(type)) {
4646
return importantRebuildQueueType;
4747
} else { // implies important sort task
48-
return TaskQueueType.ZERO_FRAME_DEFER;
48+
return importantSortQueueType;
4949
}
5050
} else {
5151
return TaskQueueType.ALWAYS_DEFER;

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
public class RenderSectionManager {
6464
private static final float NEARBY_REBUILD_DISTANCE = Mth.square(16.0f);
6565
private static final float NEARBY_SORT_DISTANCE = Mth.square(25.0f);
66-
66+
6767
private static final float FRAME_DURATION_UPLOAD_FRACTION = 0.1f;
6868
private static final long MIN_UPLOAD_DURATION_BUDGET = 2_000_000L; // 2ms
6969

@@ -117,7 +117,7 @@ public class RenderSectionManager {
117117

118118
public RenderSectionManager(ClientLevel level, int renderDistance, SortBehavior sortBehavior, CommandList commandList) {
119119
this.meshTaskSizeEstimator = new MeshTaskSizeEstimator(level);
120-
120+
121121
this.chunkRenderer = new DefaultChunkRenderer(RenderDevice.INSTANCE, ChunkMeshFormats.COMPACT);
122122

123123
this.level = level;
@@ -177,14 +177,15 @@ private boolean createTerrainRenderList(Camera camera, Viewport viewport, FogPar
177177

178178
RenderListProvider renderListProvider;
179179
var importantRebuildQueueType = SodiumClientMod.options().performance.chunkBuildDeferMode.getImportantRebuildQueueType();
180+
var importantSortQueueType = this.sortBehavior.getDeferMode().getImportantRebuildQueueType();
180181
if (this.isOutOfGraph(viewport.getChunkCoord())) {
181-
var visitor = new TreeSectionCollector(frame, importantRebuildQueueType, this.sectionByPosition);
182+
var visitor = new TreeSectionCollector(frame, importantRebuildQueueType, importantSortQueueType, this.sectionByPosition);
182183
this.renderableSectionTree.prepareForTraversal();
183184
this.renderableSectionTree.traverse(visitor, viewport, searchDistance);
184185

185186
renderListProvider = visitor;
186187
} else {
187-
var visitor = new OcclusionSectionCollector(frame, importantRebuildQueueType);
188+
var visitor = new OcclusionSectionCollector(frame, importantRebuildQueueType, importantSortQueueType);
188189
this.occlusionCuller.findVisible(visitor, viewport, searchDistance, useOcclusionCulling, frame);
189190

190191
renderListProvider = visitor;
@@ -511,19 +512,13 @@ public void updateChunks(boolean updateImmediately) {
511512
// an estimator is used estimate task duration and limit the execution time to the available worker capacity.
512513
// separately, tasks are limited by their estimated upload size and duration.
513514
var uploadBudget = new LimitedResourceBudget(
514-
Math.max((long)(this.averageFrameDuration * FRAME_DURATION_UPLOAD_FRACTION), MIN_UPLOAD_DURATION_BUDGET),
515+
Math.max((long) (this.averageFrameDuration * FRAME_DURATION_UPLOAD_FRACTION), MIN_UPLOAD_DURATION_BUDGET),
515516
this.regions.getStagingBuffer().getUploadSizeLimit(this.averageFrameDuration));
516517

517518
var nextFrameBlockingCollector = new ChunkJobCollector(this.buildResults::add);
518519
var deferredCollector = new ChunkJobCollector(remainingDuration, this.buildResults::add);
519520

520-
// if zero frame delay is allowed, submit important sorts with the current frame blocking collector.
521-
// otherwise submit with the collector that the next frame is blocking on.
522-
if (this.sortBehavior.getDeferMode() == DeferMode.ZERO_FRAMES) {
523-
this.submitSectionTasks(thisFrameBlockingCollector, nextFrameBlockingCollector, deferredCollector, uploadBudget);
524-
} else {
525-
this.submitSectionTasks(nextFrameBlockingCollector, nextFrameBlockingCollector, deferredCollector, uploadBudget);
526-
}
521+
this.submitSectionTasks(thisFrameBlockingCollector, nextFrameBlockingCollector, deferredCollector, uploadBudget);
527522

528523
this.thisFrameBlockingTasks = thisFrameBlockingCollector.getSubmittedTaskCount();
529524
this.nextFrameBlockingTasks = nextFrameBlockingCollector.getSubmittedTaskCount();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* collect the visible chunks.
88
*/
99
public class OcclusionSectionCollector extends SectionCollector {
10-
public OcclusionSectionCollector(int frame, TaskQueueType importantRebuildQueueType) {
11-
super(frame, importantRebuildQueueType);
10+
public OcclusionSectionCollector(int frame, TaskQueueType importantRebuildQueueType, TaskQueueType importantSortQueueType) {
11+
super(frame, importantRebuildQueueType, importantSortQueueType);
1212
}
1313

1414
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
public abstract class SectionCollector implements RenderListProvider, RenderSectionVisitor {
1515
private final int frame;
1616
private final TaskQueueType importantRebuildQueueType;
17+
private final TaskQueueType importantSortQueueType;
1718
private final ObjectArrayList<ChunkRenderList> renderLists;
1819
private final EnumMap<TaskQueueType, ArrayDeque<RenderSection>> sortedTaskLists;
1920
private boolean needsRevisitForPendingUpdates = false;
2021

2122
private static int[] sortItems = new int[RenderRegion.REGION_SIZE];
2223

23-
public SectionCollector(int frame, TaskQueueType importantRebuildQueueType) {
24+
public SectionCollector(int frame, TaskQueueType importantRebuildQueueType, TaskQueueType importantSortQueueType) {
2425
this.frame = frame;
2526
this.importantRebuildQueueType = importantRebuildQueueType;
27+
this.importantSortQueueType = importantSortQueueType;
2628

2729
this.renderLists = new ObjectArrayList<>();
2830
this.sortedTaskLists = new EnumMap<>(TaskQueueType.class);
@@ -60,7 +62,7 @@ public void visit(RenderSection section) {
6062
return;
6163
}
6264

63-
var queueType = ChunkUpdateTypes.getQueueType(pendingUpdate, this.importantRebuildQueueType);
65+
var queueType = ChunkUpdateTypes.getQueueType(pendingUpdate, this.importantRebuildQueueType, this.importantSortQueueType);
6466
Queue<RenderSection> queue = this.sortedTaskLists.get(queueType);
6567

6668
if (queue.size() < queueType.queueSizeLimit()) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
public class TreeSectionCollector extends SectionCollector implements CoordinateSectionVisitor {
1212
private final Long2ReferenceMap<RenderSection> sections;
1313

14-
public TreeSectionCollector(int frame, TaskQueueType importantRebuildQueueType, Long2ReferenceMap<RenderSection> sections) {
15-
super(frame, importantRebuildQueueType);
14+
public TreeSectionCollector(int frame, TaskQueueType importantRebuildQueueType, TaskQueueType importantSortQueueType, Long2ReferenceMap<RenderSection> sections) {
15+
super(frame, importantRebuildQueueType, importantSortQueueType);
1616
this.sections = sections;
1717
}
1818

0 commit comments

Comments
 (0)