Skip to content

Commit 7d98b4e

Browse files
committed
Set auto default value for render thread count
1 parent 2d4c23c commit 7d98b4e

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static class SpeedrunSettings implements SpeedrunConfigStorage {
3939
public boolean showEntityCulling = true;
4040
public boolean showFogOcclusion = true;
4141

42-
@Config.Numbers.Whole.Bounds(min = 1, max = 32)
43-
public int renderThreads = 1;
42+
@Config.Numbers.Whole.Bounds(min = 0, max = 32)
43+
public int renderThreads = 0;
4444
}
4545

4646
{

src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import me.jellysquid.mods.sodium.common.util.collections.DequeDrain;
1919
import net.minecraft.client.MinecraftClient;
2020
import net.minecraft.client.util.math.Vector3d;
21+
import net.minecraft.util.math.MathHelper;
2122
import net.minecraft.client.world.ClientWorld;
2223
import net.minecraft.world.World;
2324
import org.apache.logging.log4j.LogManager;
@@ -58,7 +59,24 @@ public class ChunkBuilder<T extends ChunkGraphicsState> {
5859
public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend<T> backend) {
5960
this.vertexType = vertexType;
6061
this.backend = backend;
61-
this.limitThreads = SodiumClientMod.options().speedrun.renderThreads;
62+
this.limitThreads = getThreadCount();
63+
}
64+
65+
/**
66+
* Returns the "optimal" number of threads to be used for chunk build tasks. This will always return at least one
67+
* thread.
68+
*/
69+
private static int getOptimalThreadCount() {
70+
return MathHelper.clamp(Math.max(getMaxThreadCount() / 3, getMaxThreadCount() - 6), 1, 10);
71+
}
72+
73+
private static int getThreadCount() {
74+
int requested = SodiumClientMod.options().speedrun.renderThreads;
75+
return requested == 0 ? getOptimalThreadCount() : Math.min(requested, getMaxThreadCount());
76+
}
77+
78+
private static int getMaxThreadCount() {
79+
return Runtime.getRuntime().availableProcessors();
6280
}
6381

6482
/**
@@ -202,14 +220,6 @@ public void init(ClientWorld world, BlockRenderPassManager renderPassManager) {
202220
this.startWorkers();
203221
}
204222

205-
/**
206-
* Returns the "optimal" number of threads to be used for chunk build tasks. This is always at least one thread,
207-
* but can be up to the number of available processor threads on the system.
208-
*/
209-
private static int getOptimalThreadCount() {
210-
return Math.max(1, Runtime.getRuntime().availableProcessors());
211-
}
212-
213223
/**
214224
* Creates a rebuild task and defers it to the work queue. When the task is completed, it will be moved onto the
215225
* completed uploads queued which will then be drained during the next available synchronization point with the

src/main/resources/assets/sodium/lang/en_us.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
"speedrunapi.config.sodium.option.speedrun:showFogOcclusion": "Show Fog Occlusion",
3232
"speedrunapi.config.sodium.option.speedrun:showFogOcclusion.description": "If enabled, Fog Occlusion will be added to the vanilla menu so it can be toggled while in a world.",
3333
"speedrunapi.config.sodium.option.speedrun:renderThreads": "Render Threads",
34-
"speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)"
34+
"speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)",
35+
"speedrunapi.config.sodium.option.speedrun:renderThreads.value.0": "Auto"
3536
}

0 commit comments

Comments
 (0)