Attempted improvements to frametime (dont think it helped)

This commit is contained in:
mcrcortex
2025-05-02 17:48:12 +10:00
parent b78d389a06
commit 6aebddb773
5 changed files with 47 additions and 57 deletions

View File

@@ -71,7 +71,6 @@ public class TimingStatistics {
} }
public static TimeSampler all = new TimeSampler(); public static TimeSampler all = new TimeSampler();
public static TimeSampler setup = new TimeSampler();
public static TimeSampler main = new TimeSampler(); public static TimeSampler main = new TimeSampler();
public static TimeSampler dynamic = new TimeSampler(); public static TimeSampler dynamic = new TimeSampler();

View File

@@ -16,6 +16,7 @@ import me.cortex.voxy.client.core.rendering.post.PostProcessing;
import me.cortex.voxy.client.core.rendering.util.DownloadStream; import me.cortex.voxy.client.core.rendering.util.DownloadStream;
import me.cortex.voxy.client.core.rendering.util.PrintfDebugUtil; import me.cortex.voxy.client.core.rendering.util.PrintfDebugUtil;
import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer; import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer;
import me.cortex.voxy.client.core.rendering.util.UploadStream;
import me.cortex.voxy.client.core.util.IrisUtil; import me.cortex.voxy.client.core.util.IrisUtil;
import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.Logger;
import me.cortex.voxy.common.thread.ServiceThreadPool; import me.cortex.voxy.common.thread.ServiceThreadPool;
@@ -107,17 +108,21 @@ public class VoxyRenderSystem {
downstream.submit(); downstream.submit();
downstream.tick(); downstream.tick();
}*/ }*/
}
TimingStatistics.all.start(); private void autoBalanceSubDivSize() {
TimingStatistics.setup.start(); //only increase quality while there are very few mesh queues, this stops,
this.renderDistanceTracker.setCenterAndProcess(camera.getBlockPos().getX(), camera.getBlockPos().getZ()); // e.g. while flying and is rendering alot of low quality chunks
boolean canDecreaseSize = this.renderer.getMeshQueueCount() < 5000;
float CHANGE_PER_SECOND = 30;
//Auto fps targeting
if (MinecraftClient.getInstance().getCurrentFps() < 45) {
VoxyConfig.CONFIG.subDivisionSize = Math.min(VoxyConfig.CONFIG.subDivisionSize + CHANGE_PER_SECOND / Math.max(1f, MinecraftClient.getInstance().getCurrentFps()), 256);
}
//Done here as is allows less gl state resetup if (55 < MinecraftClient.getInstance().getCurrentFps() && canDecreaseSize) {
this.renderer.tickModelService(); VoxyConfig.CONFIG.subDivisionSize = Math.max(VoxyConfig.CONFIG.subDivisionSize - CHANGE_PER_SECOND / Math.max(1f, MinecraftClient.getInstance().getCurrentFps()), 30);
}
PrintfDebugUtil.tick();
TimingStatistics.setup.stop();
TimingStatistics.all.stop();
} }
private static Matrix4f makeProjectionMatrix(float near, float far) { private static Matrix4f makeProjectionMatrix(float near, float far) {
@@ -147,30 +152,17 @@ public class VoxyRenderSystem {
if (IrisUtil.irisShadowActive()) { if (IrisUtil.irisShadowActive()) {
return; return;
} }
TimingStatistics.all.start();
TimingStatistics.main.start();
if (false) {
//only increase quality while there are very few mesh queues, this stops,
// e.g. while flying and is rendering alot of low quality chunks
boolean canDecreaseSize = this.renderer.getMeshQueueCount() < 5000;
float CHANGE_PER_SECOND = 30;
//Auto fps targeting
if (MinecraftClient.getInstance().getCurrentFps() < 45) {
VoxyConfig.CONFIG.subDivisionSize = Math.min(VoxyConfig.CONFIG.subDivisionSize + CHANGE_PER_SECOND / Math.max(1f, MinecraftClient.getInstance().getCurrentFps()), 256);
}
if (55 < MinecraftClient.getInstance().getCurrentFps() && canDecreaseSize) {
VoxyConfig.CONFIG.subDivisionSize = Math.max(VoxyConfig.CONFIG.subDivisionSize - CHANGE_PER_SECOND / Math.max(1f, MinecraftClient.getInstance().getCurrentFps()), 30);
}
}
//Do some very cheeky stuff for MiB //Do some very cheeky stuff for MiB
if (false) { if (false) {
int sector = (((int)Math.floor(cameraX)>>4)+512)>>10; int sector = (((int)Math.floor(cameraX)>>4)+512)>>10;
cameraX -= sector<<14;//10+4 cameraX -= sector<<14;//10+4
cameraY += (16+(256-32-sector*30))*16; cameraY += (16+(256-32-sector*30))*16;
} }
long startTime = System.nanoTime();
TimingStatistics.all.start();
TimingStatistics.main.start();
//this.autoBalanceSubDivSize();
var projection = computeProjectionMat(matrices.projection());//RenderSystem.getProjectionMatrix(); var projection = computeProjectionMat(matrices.projection());//RenderSystem.getProjectionMatrix();
//var projection = new Matrix4f(matrices.projection()); //var projection = new Matrix4f(matrices.projection());
@@ -196,13 +188,9 @@ public class VoxyRenderSystem {
this.chunkBoundRenderer.render(viewport); this.chunkBoundRenderer.render(viewport);
//TODO: use the raw depth buffer texture instead
//int boundDepthBuffer = glGetNamedFramebufferAttachmentParameteri(boundFB, GL_DEPTH_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME);
//TODO:FIXME!!! ??
this.postProcessing.setup(target.textureWidth, target.textureHeight, boundFB); this.postProcessing.setup(target.textureWidth, target.textureHeight, boundFB);
this.renderer.renderFarAwayOpaque(viewport, this.chunkBoundRenderer.getDepthBoundTexture()); this.renderer.renderFarAwayOpaque(viewport, this.chunkBoundRenderer.getDepthBoundTexture(), startTime);
//Compute the SSAO of the rendered terrain, TODO: fix it breaking depth or breaking _something_ am not sure what //Compute the SSAO of the rendered terrain, TODO: fix it breaking depth or breaking _something_ am not sure what
this.postProcessing.computeSSAO(viewport.MVP); this.postProcessing.computeSSAO(viewport.MVP);
@@ -212,6 +200,20 @@ public class VoxyRenderSystem {
this.postProcessing.renderPost(projection, matrices.projection(), boundFB); this.postProcessing.renderPost(projection, matrices.projection(), boundFB);
PrintfDebugUtil.tick();
//As much dynamic runtime stuff here
{
//Tick upload stream (this is ok to do here as upload ticking is just memory management)
UploadStream.INSTANCE.tick();
this.renderDistanceTracker.setCenterAndProcess(cameraX, cameraZ);
//Done here as is allows less gl state resetup
this.renderer.tickModelService(4_000_000-(System.nanoTime()-startTime));
}
glBindFramebuffer(GlConst.GL_FRAMEBUFFER, oldFB); glBindFramebuffer(GlConst.GL_FRAMEBUFFER, oldFB);
TimingStatistics.main.stop(); TimingStatistics.main.stop();
TimingStatistics.all.stop(); TimingStatistics.all.stop();
@@ -222,7 +224,7 @@ public class VoxyRenderSystem {
this.renderer.addDebugData(debug); this.renderer.addDebugData(debug);
{ {
TimingStatistics.update(); TimingStatistics.update();
debug.add("Voxy frame runtime (millis): " + TimingStatistics.setup.pVal() + ", " + TimingStatistics.dynamic.pVal() + ", " + TimingStatistics.main.pVal()+ ", " + TimingStatistics.all.pVal()); debug.add("Voxy frame runtime (millis): " + TimingStatistics.dynamic.pVal() + ", " + TimingStatistics.main.pVal()+ ", " + TimingStatistics.all.pVal());
} }
PrintfDebugUtil.addToOut(debug); PrintfDebugUtil.addToOut(debug);
} }
@@ -273,7 +275,7 @@ public class VoxyRenderSystem {
{ {
//Bake everything //Bake everything
while (!modelService.areQueuesEmpty()) { while (!modelService.areQueuesEmpty()) {
modelService.tick(); modelService.tick(5_000_000);
glFinish(); glFinish();
} }
} }
@@ -314,7 +316,7 @@ public class VoxyRenderSystem {
} }
int i = 0; int i = 0;
while (true) { while (true) {
modelService.tick(); modelService.tick(5_000_000);
if (i++%5000==0) if (i++%5000==0)
System.out.println(completedCounter.get()); System.out.println(completedCounter.get());
glFinish(); glFinish();
@@ -344,7 +346,7 @@ public class VoxyRenderSystem {
while (true) { while (true) {
//if (i++%5000==0) //if (i++%5000==0)
// System.out.println(completedCounter.get()); // System.out.println(completedCounter.get());
modelService.tick(); modelService.tick(5_000_000);
glFinish(); glFinish();
List<String> a = new ArrayList<>(); List<String> a = new ArrayList<>();
generationService.addDebugData(a); generationService.addDebugData(a);

View File

@@ -35,7 +35,7 @@ public class ModelBakerySubsystem {
this.factory = new ModelFactory(mapper, this.storage); this.factory = new ModelFactory(mapper, this.storage);
} }
public void tick() { public void tick(long totalBudget) {
//Upload all biomes //Upload all biomes
while (!this.biomeQueue.isEmpty()) { while (!this.biomeQueue.isEmpty()) {
var biome = this.biomeQueue.poll(); var biome = this.biomeQueue.poll();
@@ -65,12 +65,11 @@ public class ModelBakerySubsystem {
this.factory.addEntry(est[j]); this.factory.addEntry(est[j]);
} }
}*/ }*/
long totalBudget = 2_000_000;
//TimingStatistics.modelProcess.start(); //TimingStatistics.modelProcess.start();
long start = System.nanoTime(); long start = System.nanoTime();
VarHandle.fullFence(); VarHandle.fullFence();
{ {
long budget = Math.min(totalBudget-200_000, totalBudget-(this.factory.resultJobs.size()*20_000L))-200_000; long budget = Math.min(totalBudget-150_000, totalBudget-(this.factory.resultJobs.size()*10_000L))-150_000;
if (budget > 50_000) { if (budget > 50_000) {
Integer i = this.blockIdQueue.poll(); Integer i = this.blockIdQueue.poll();
if (i != null) { if (i != null) {

View File

@@ -103,11 +103,11 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
this.nodeManager.removeTopLevelNode(pos); this.nodeManager.removeTopLevelNode(pos);
} }
public void tickModelService() { public void tickModelService(long budget) {
this.modelService.tick(); this.modelService.tick(budget);
} }
public void renderFarAwayOpaque(J viewport, GlTexture depthBoundTexture) { public void renderFarAwayOpaque(J viewport, GlTexture depthBoundTexture, long frameStart) {
//LightMapHelper.tickLightmap(); //LightMapHelper.tickLightmap();
//Render previous geometry with the abstract renderer //Render previous geometry with the abstract renderer
@@ -133,25 +133,15 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
{ {
TimingStatistics.main.stop(); TimingStatistics.main.stop();
TimingStatistics.dynamic.start(); TimingStatistics.dynamic.start();
long start = System.nanoTime();
VarHandle.fullFence();
//Tick download stream //Tick download stream
//TODO: make this so that can
DownloadStream.INSTANCE.tick(); DownloadStream.INSTANCE.tick();
//Tick upload stream (this is ok to do here as upload ticking is just memory management)
UploadStream.INSTANCE.tick();
this.sectionUpdateQueue.consume(128); this.sectionUpdateQueue.consume(128);
VarHandle.fullFence(); if (this.modelService.getProcessingCount() < 750) {//Very bad hack to try control things
long updateBudget = Math.max(1_000_000-(System.nanoTime()-start), 0); this.geometryUpdateQueue.consumeNano(1_500_000 - (System.nanoTime() - frameStart));
VarHandle.fullFence();
if (updateBudget > 50_000) {
//Cap the number of consumed sections per frame to 40 + 2% of the queue size, cap of 200
//int geoUpdateCap = 20;//Math.max(100, Math.min((int)(0.15*this.geometryUpdateQueue.count()), 260));
this.geometryUpdateQueue.consumeNano(updateBudget);
} }
this.nodeCleaner.tick(this.traversal.getNodeBuffer());//Probably do this here?? this.nodeCleaner.tick(this.traversal.getNodeBuffer());//Probably do this here??

View File

@@ -41,11 +41,11 @@ public class MessageQueue <T> {
} }
public int consumeNano(long budget) { public int consumeNano(long budget) {
if (budget < 25_000) return 0;
if (this.count.get() == 0) { if (this.count.get() == 0) {
return 0; return 0;
} }
int i = 0; int i = 0;
VarHandle.fullFence();
long nano = System.nanoTime(); long nano = System.nanoTime();
VarHandle.fullFence(); VarHandle.fullFence();
do { do {