From 2d4c23cfe29286f615b4e53d138987574c8b0e32 Mon Sep 17 00:00:00 2001 From: jojoe77777 Date: Thu, 14 Nov 2024 21:30:45 +1100 Subject: [PATCH 1/3] Added render threads option --- .../jellysquid/mods/sodium/client/gui/SodiumGameOptions.java | 3 +++ .../mods/sodium/client/render/chunk/compile/ChunkBuilder.java | 3 ++- src/main/resources/assets/sodium/lang/en_us.json | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) 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..f3140de5 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 @@ -38,6 +38,9 @@ public static class SpeedrunSettings implements SpeedrunConfigStorage { public boolean usePlanarFog = true; public boolean showEntityCulling = true; public boolean showFogOcclusion = true; + + @Config.Numbers.Whole.Bounds(min = 1, max = 32) + public int renderThreads = 1; } { 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..1db72db5 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; @@ -57,7 +58,7 @@ public class ChunkBuilder { public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend backend) { this.vertexType = vertexType; this.backend = backend; - this.limitThreads = getOptimalThreadCount(); + this.limitThreads = SodiumClientMod.options().speedrun.renderThreads; } /** diff --git a/src/main/resources/assets/sodium/lang/en_us.json b/src/main/resources/assets/sodium/lang/en_us.json index df25c0fb..8e3a9242 100644 --- a/src/main/resources/assets/sodium/lang/en_us.json +++ b/src/main/resources/assets/sodium/lang/en_us.json @@ -29,5 +29,7 @@ "speedrunapi.config.sodium.option.speedrun:showEntityCulling": "Show Entity Culling", "speedrunapi.config.sodium.option.speedrun:showEntityCulling.description": "If enabled, Entity Culling will be added to the vanilla menu so it can be toggled while in a world.", "speedrunapi.config.sodium.option.speedrun:showFogOcclusion": "Show Fog Occlusion", - "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." + "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.", + "speedrunapi.config.sodium.option.speedrun:renderThreads": "Render Threads", + "speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)" } From 7d98b4e65e9fd7e4e85d45bbb9cd63ed9250dac8 Mon Sep 17 00:00:00 2001 From: jojoe77777 Date: Fri, 15 Nov 2024 18:43:52 +1100 Subject: [PATCH 2/3] Set auto default value for render thread count --- .../sodium/client/gui/SodiumGameOptions.java | 4 +-- .../render/chunk/compile/ChunkBuilder.java | 28 +++++++++++++------ .../resources/assets/sodium/lang/en_us.json | 3 +- 3 files changed, 23 insertions(+), 12 deletions(-) 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 f3140de5..5fcfc7d1 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 @@ -39,8 +39,8 @@ public static class SpeedrunSettings implements SpeedrunConfigStorage { public boolean showEntityCulling = true; public boolean showFogOcclusion = true; - @Config.Numbers.Whole.Bounds(min = 1, max = 32) - public int renderThreads = 1; + @Config.Numbers.Whole.Bounds(min = 0, max = 32) + public int renderThreads = 0; } { 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 1db72db5..0263a4a7 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 @@ -18,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; @@ -58,7 +59,24 @@ public class ChunkBuilder { public ChunkBuilder(ChunkVertexType vertexType, ChunkRenderBackend backend) { this.vertexType = vertexType; this.backend = backend; - this.limitThreads = SodiumClientMod.options().speedrun.renderThreads; + 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().speedrun.renderThreads; + return requested == 0 ? getOptimalThreadCount() : Math.min(requested, getMaxThreadCount()); + } + + private static int getMaxThreadCount() { + return Runtime.getRuntime().availableProcessors(); } /** @@ -202,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 8e3a9242..cf9234f9 100644 --- a/src/main/resources/assets/sodium/lang/en_us.json +++ b/src/main/resources/assets/sodium/lang/en_us.json @@ -31,5 +31,6 @@ "speedrunapi.config.sodium.option.speedrun:showFogOcclusion": "Show Fog Occlusion", "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.", "speedrunapi.config.sodium.option.speedrun:renderThreads": "Render Threads", - "speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)" + "speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)", + "speedrunapi.config.sodium.option.speedrun:renderThreads.value.0": "Auto" } From 9a37e42bb304bff3277785c836123a4bedd92660 Mon Sep 17 00:00:00 2001 From: jojoe77777 Date: Sun, 17 Nov 2024 14:28:32 +1100 Subject: [PATCH 3/3] Rename renderThreads to chunkUpdateThreads and moved category --- .../mods/sodium/client/gui/SodiumGameOptions.java | 5 ++--- .../sodium/client/render/chunk/compile/ChunkBuilder.java | 2 +- src/main/resources/assets/sodium/lang/en_us.json | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) 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 5fcfc7d1..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; @@ -38,9 +40,6 @@ public static class SpeedrunSettings implements SpeedrunConfigStorage { public boolean usePlanarFog = true; public boolean showEntityCulling = true; public boolean showFogOcclusion = true; - - @Config.Numbers.Whole.Bounds(min = 0, max = 32) - public int renderThreads = 0; } { 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 0263a4a7..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 @@ -71,7 +71,7 @@ private static int getOptimalThreadCount() { } private static int getThreadCount() { - int requested = SodiumClientMod.options().speedrun.renderThreads; + int requested = SodiumClientMod.options().advanced.chunkUpdateThreads; return requested == 0 ? getOptimalThreadCount() : Math.min(requested, getMaxThreadCount()); } diff --git a/src/main/resources/assets/sodium/lang/en_us.json b/src/main/resources/assets/sodium/lang/en_us.json index cf9234f9..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", @@ -29,8 +32,5 @@ "speedrunapi.config.sodium.option.speedrun:showEntityCulling": "Show Entity Culling", "speedrunapi.config.sodium.option.speedrun:showEntityCulling.description": "If enabled, Entity Culling will be added to the vanilla menu so it can be toggled while in a world.", "speedrunapi.config.sodium.option.speedrun:showFogOcclusion": "Show Fog Occlusion", - "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.", - "speedrunapi.config.sodium.option.speedrun:renderThreads": "Render Threads", - "speedrunapi.config.sodium.option.speedrun:renderThreads.description": "How many render threads to create (lower = less F3+F lag)", - "speedrunapi.config.sodium.option.speedrun:renderThreads.value.0": "Auto" + "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." }