|
18 | 18 | import me.jellysquid.mods.sodium.common.util.collections.DequeDrain; |
19 | 19 | import net.minecraft.client.MinecraftClient; |
20 | 20 | import net.minecraft.client.util.math.Vector3d; |
| 21 | +import net.minecraft.util.math.MathHelper; |
21 | 22 | import net.minecraft.client.world.ClientWorld; |
22 | 23 | import net.minecraft.world.World; |
23 | 24 | import org.apache.logging.log4j.LogManager; |
@@ -58,7 +59,24 @@ public class ChunkBuilder<T extends ChunkGraphicsState> { |
58 | 59 | public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend<T> backend) { |
59 | 60 | this.vertexType = vertexType; |
60 | 61 | 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(); |
62 | 80 | } |
63 | 81 |
|
64 | 82 | /** |
@@ -202,14 +220,6 @@ public void init(ClientWorld world, BlockRenderPassManager renderPassManager) { |
202 | 220 | this.startWorkers(); |
203 | 221 | } |
204 | 222 |
|
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 | | - |
213 | 223 | /** |
214 | 224 | * Creates a rebuild task and defers it to the work queue. When the task is completed, it will be moved onto the |
215 | 225 | * completed uploads queued which will then be drained during the next available synchronization point with the |
|
0 commit comments