Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -57,7 +59,24 @@ public class ChunkBuilder<T extends ChunkGraphicsState> {
public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend<T> 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();
}

/**
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/sodium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down