diff --git a/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java b/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java index 39dcc8ad..d65f9355 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/gui/SodiumGameOptions.java @@ -19,6 +19,8 @@ public class SodiumGameOptions implements SpeedrunConfig { public final SpeedrunSettings speedrun = new SpeedrunSettings(); public static class AdvancedSettings implements SpeedrunConfigStorage { + @Config.Numbers.Whole.Bounds(min = 0, max = 32) + public int chunkUpdateThreads = 0; public boolean useChunkMultidraw = true; public boolean useBlockFaceCulling = true; public boolean useCompactVertexFormat = true; diff --git a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java index f52b7769..b94c9850 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuilder.java @@ -1,5 +1,6 @@ package me.jellysquid.mods.sodium.client.render.chunk.compile; +import me.jellysquid.mods.sodium.client.SodiumClientMod; import me.jellysquid.mods.sodium.client.gl.device.RenderDevice; import me.jellysquid.mods.sodium.client.model.vertex.type.ChunkVertexType; import me.jellysquid.mods.sodium.client.render.chunk.ChunkGraphicsState; @@ -17,6 +18,7 @@ import me.jellysquid.mods.sodium.common.util.collections.DequeDrain; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.Vector3d; +import net.minecraft.util.math.MathHelper; import net.minecraft.client.world.ClientWorld; import net.minecraft.world.World; import org.apache.logging.log4j.LogManager; @@ -57,7 +59,24 @@ public class ChunkBuilder { public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend backend) { this.vertexType = vertexType; this.backend = backend; - this.limitThreads = getOptimalThreadCount(); + this.limitThreads = getThreadCount(); + } + + /** + * Returns the "optimal" number of threads to be used for chunk build tasks. This will always return at least one + * thread. + */ + private static int getOptimalThreadCount() { + return MathHelper.clamp(Math.max(getMaxThreadCount() / 3, getMaxThreadCount() - 6), 1, 10); + } + + private static int getThreadCount() { + int requested = SodiumClientMod.options().advanced.chunkUpdateThreads; + return requested == 0 ? getOptimalThreadCount() : Math.min(requested, getMaxThreadCount()); + } + + private static int getMaxThreadCount() { + return Runtime.getRuntime().availableProcessors(); } /** @@ -201,14 +220,6 @@ public void init(ClientWorld world, BlockRenderPassManager renderPassManager) { this.startWorkers(); } - /** - * Returns the "optimal" number of threads to be used for chunk build tasks. This is always at least one thread, - * but can be up to the number of available processor threads on the system. - */ - private static int getOptimalThreadCount() { - return Math.max(1, Runtime.getRuntime().availableProcessors()); - } - /** * Creates a rebuild task and defers it to the work queue. When the task is completed, it will be moved onto the * completed uploads queued which will then be drained during the next available synchronization point with the diff --git a/src/main/resources/assets/sodium/lang/en_us.json b/src/main/resources/assets/sodium/lang/en_us.json index df25c0fb..4578531c 100644 --- a/src/main/resources/assets/sodium/lang/en_us.json +++ b/src/main/resources/assets/sodium/lang/en_us.json @@ -4,6 +4,9 @@ "speedrunapi.config.sodium.category.speedrun": "Speedrun", "speedrunapi.config.sodium.option.quality:enableVignette": "Vignette", "speedrunapi.config.sodium.option.quality:enableVignette.description": "If enabled, a vignette effect will be rendered on the player's view. This is very unlikely to make a difference to frame rates unless you are fill-rate limited.", + "speedrunapi.config.sodium.option.advanced:chunkUpdateThreads": "Chunk Update Threads", + "speedrunapi.config.sodium.option.advanced:chunkUpdateThreads.description": "How many chunk update threads to create (lower = less F3+F lag)", + "speedrunapi.config.sodium.option.advanced:chunkUpdateThreads.value.0": "Auto", "speedrunapi.config.sodium.option.advanced:useChunkMultidraw": "Use Chunk Multi-Draw", "speedrunapi.config.sodium.option.advanced:useChunkMultidraw.description": "Multi-draw allows multiple chunks to be rendered with fewer draw calls, greatly reducing CPU overhead when rendering the world while also potentially allowing for more efficient GPU utilization. This optimization may cause issues with some graphics drivers, so you should try disabling it if you are experiencing glitches.", "speedrunapi.config.sodium.option.advanced:useVertexArrayObjects": "Use Vertex Array Objects",