set thread count to max(1,self-sodium)
This commit is contained in:
@@ -4,11 +4,13 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import me.cortex.voxy.client.RenderStatistics;
|
import me.cortex.voxy.client.RenderStatistics;
|
||||||
import me.cortex.voxy.client.VoxyClientInstance;
|
import me.cortex.voxy.client.VoxyClientInstance;
|
||||||
import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
|
import me.cortex.voxy.client.core.IGetVoxyRenderSystem;
|
||||||
|
import me.cortex.voxy.client.mixin.sodium.AccessorSodiumWorldRenderer;
|
||||||
import me.cortex.voxy.common.util.cpu.CpuLayout;
|
import me.cortex.voxy.common.util.cpu.CpuLayout;
|
||||||
import me.cortex.voxy.commonImpl.VoxyCommon;
|
import me.cortex.voxy.commonImpl.VoxyCommon;
|
||||||
import net.caffeinemc.mods.sodium.client.gui.options.*;
|
import net.caffeinemc.mods.sodium.client.gui.options.*;
|
||||||
import net.caffeinemc.mods.sodium.client.gui.options.control.SliderControl;
|
import net.caffeinemc.mods.sodium.client.gui.options.control.SliderControl;
|
||||||
import net.caffeinemc.mods.sodium.client.gui.options.control.TickBoxControl;
|
import net.caffeinemc.mods.sodium.client.gui.options.control.TickBoxControl;
|
||||||
|
import net.caffeinemc.mods.sodium.client.render.SodiumWorldRenderer;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
@@ -60,8 +62,18 @@ public abstract class VoxyConfigScreenPages {
|
|||||||
s.serviceThreads = v;
|
s.serviceThreads = v;
|
||||||
var instance = VoxyCommon.getInstance();
|
var instance = VoxyCommon.getInstance();
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
|
var swr = SodiumWorldRenderer.instanceNullable();
|
||||||
|
if (swr != null) {
|
||||||
|
var rsm = ((AccessorSodiumWorldRenderer)swr).getRenderSectionManager();
|
||||||
|
if (rsm!=null) {
|
||||||
|
instance.setNumThreads(Math.max(1, v-rsm.getBuilder().getTotalThreadCount()));
|
||||||
|
} else {
|
||||||
instance.setNumThreads(v);
|
instance.setNumThreads(v);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
instance.setNumThreads(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, s -> s.serviceThreads)
|
}, s -> s.serviceThreads)
|
||||||
.setImpact(OptionImpact.HIGH)
|
.setImpact(OptionImpact.HIGH)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package me.cortex.voxy.client.mixin.sodium;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||||
|
import net.caffeinemc.mods.sodium.client.render.SodiumWorldRenderer;
|
||||||
|
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
|
||||||
|
import net.caffeinemc.mods.sodium.client.render.chunk.map.ChunkTracker;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(value = SodiumWorldRenderer.class, remap = false)
|
||||||
|
public interface AccessorSodiumWorldRenderer {
|
||||||
|
@Accessor
|
||||||
|
RenderSectionManager getRenderSectionManager();
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import me.cortex.voxy.commonImpl.WorldIdentifier;
|
|||||||
import net.caffeinemc.mods.sodium.client.gl.device.CommandList;
|
import net.caffeinemc.mods.sodium.client.gl.device.CommandList;
|
||||||
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
|
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSection;
|
||||||
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
|
import net.caffeinemc.mods.sodium.client.render.chunk.RenderSectionManager;
|
||||||
|
import net.caffeinemc.mods.sodium.client.render.chunk.compile.executor.ChunkBuilder;
|
||||||
import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo;
|
import net.caffeinemc.mods.sodium.client.render.chunk.data.BuiltSectionInfo;
|
||||||
import net.caffeinemc.mods.sodium.client.render.chunk.map.ChunkTrackerHolder;
|
import net.caffeinemc.mods.sodium.client.render.chunk.map.ChunkTrackerHolder;
|
||||||
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.SortBehavior;
|
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.SortBehavior;
|
||||||
@@ -35,6 +36,8 @@ public class MixinRenderSectionManager {
|
|||||||
|
|
||||||
@Shadow @Final private ClientWorld level;
|
@Shadow @Final private ClientWorld level;
|
||||||
|
|
||||||
|
@Shadow @Final private ChunkBuilder builder;
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void voxy$resetChunkTracker(ClientWorld level, int renderDistance, SortBehavior sortBehavior, CommandList commandList, CallbackInfo ci) {
|
private void voxy$resetChunkTracker(ClientWorld level, int renderDistance, SortBehavior sortBehavior, CommandList commandList, CallbackInfo ci) {
|
||||||
if (level.worldRenderer != null) {
|
if (level.worldRenderer != null) {
|
||||||
@@ -44,6 +47,14 @@ public class MixinRenderSectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.bottomSectionY = this.level.getBottomY()>>4;
|
this.bottomSectionY = this.level.getBottomY()>>4;
|
||||||
|
|
||||||
|
{
|
||||||
|
//TODO: put in a better position
|
||||||
|
var instance = VoxyCommon.getInstance();
|
||||||
|
if (instance != null) {
|
||||||
|
instance.setNumThreads(Math.max(1, VoxyConfig.CONFIG.serviceThreads - this.builder.getTotalThreadCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "onChunkRemoved", at = @At("HEAD"))
|
@Inject(method = "onChunkRemoved", at = @At("HEAD"))
|
||||||
|
|||||||
@@ -25,15 +25,16 @@ public class UnifiedServiceThreadPool {
|
|||||||
|
|
||||||
private final void release(int i) {this.groupSemaphore.pooledRelease(i);}
|
private final void release(int i) {this.groupSemaphore.pooledRelease(i);}
|
||||||
|
|
||||||
public void setNumThreads(int threads) {
|
public boolean setNumThreads(int threads) {
|
||||||
synchronized (this.threads) {
|
synchronized (this.threads) {
|
||||||
int diff = threads - this.threads.size();
|
int diff = threads - this.threads.size();
|
||||||
if (diff==0) return;//Already correct
|
if (diff==0) return false;//Already correct
|
||||||
if (diff<0) {//Remove threads
|
if (diff<0) {//Remove threads
|
||||||
this.selfBlock.release(-diff);
|
this.selfBlock.release(-diff);
|
||||||
} else {//Add threads
|
} else {//Add threads
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
var t = new Thread(this.dedicatedPool, this::workerThread);
|
var t = new Thread(this.dedicatedPool, this::workerThread);
|
||||||
|
t.setPriority(3);
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
this.threads.add(t);
|
this.threads.add(t);
|
||||||
t.start();
|
t.start();
|
||||||
@@ -42,7 +43,7 @@ public class UnifiedServiceThreadPool {
|
|||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized (this.threads) {
|
synchronized (this.threads) {
|
||||||
if (this.threads.size() == threads) return;
|
if (this.threads.size() == threads) return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
|
|||||||
@@ -60,7 +60,10 @@ public abstract class VoxyInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNumThreads(int threads) {
|
public void setNumThreads(int threads) {
|
||||||
this.threadPool.setNumThreads(threads);
|
if (threads<0) throw new IllegalArgumentException("Num threads <0");
|
||||||
|
if (this.threadPool.setNumThreads(threads)) {
|
||||||
|
Logger.info("Dedicated voxy thread pool size: " + threads);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ImportManager createImportManager() {
|
protected ImportManager createImportManager() {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"minecraft.MixinWorldRenderer",
|
"minecraft.MixinWorldRenderer",
|
||||||
"nvidium.MixinRenderPipeline",
|
"nvidium.MixinRenderPipeline",
|
||||||
"sodium.AccessorChunkTracker",
|
"sodium.AccessorChunkTracker",
|
||||||
|
"sodium.AccessorSodiumWorldRenderer",
|
||||||
"sodium.MixinChunkJobQueue",
|
"sodium.MixinChunkJobQueue",
|
||||||
"sodium.MixinDefaultChunkRenderer",
|
"sodium.MixinDefaultChunkRenderer",
|
||||||
"sodium.MixinRenderSectionManager",
|
"sodium.MixinRenderSectionManager",
|
||||||
|
|||||||
Reference in New Issue
Block a user