aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/makamys/neodymium/renderer
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2023-03-18 14:19:19 +0100
committermakamys <makamys@outlook.com>2023-03-18 14:31:08 +0100
commitf206874e4f177f7b1bba67bf58ef2fa75b64e7ab (patch)
tree30020701f373db99e71f2edd884ce20607003d7e /src/main/java/makamys/neodymium/renderer
parent3b7c5e178a327e4370c75b9b3ecc0129605d8e0c (diff)
downloadNeodymium-f206874e4f177f7b1bba67bf58ef2fa75b64e7ab.tar.gz
Neodymium-f206874e4f177f7b1bba67bf58ef2fa75b64e7ab.tar.bz2
Neodymium-f206874e4f177f7b1bba67bf58ef2fa75b64e7ab.zip
Improve handling of VRAM fullness
Now the renderer gets reloaded, and Neodymium only gets disabled if the VRAM repeatedly gets full in a short span of time.
Diffstat (limited to 'src/main/java/makamys/neodymium/renderer')
-rw-r--r--src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java21
-rw-r--r--src/main/java/makamys/neodymium/renderer/NeoRenderer.java19
2 files changed, 29 insertions, 11 deletions
diff --git a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java
index 34fafd9..16a72d5 100644
--- a/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java
+++ b/src/main/java/makamys/neodymium/renderer/GPUMemoryManager.java
@@ -6,12 +6,15 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import makamys.neodymium.Compat;
import makamys.neodymium.Neodymium;
import makamys.neodymium.config.Config;
import makamys.neodymium.renderer.Mesh.GPUStatus;
import makamys.neodymium.util.GuiHelper;
import makamys.neodymium.util.ChatUtil;
+import static makamys.neodymium.Constants.LOGGER;
+
/** Manages dynamic memory allocation inside a fixed buffer on the GPU. */
public class GPUMemoryManager {
@@ -25,7 +28,10 @@ public class GPUMemoryManager {
private long usedVRAM;
private long lastUsedVRAMUpdate;
- private static final long USED_VRAM_UPDATE_RATE = 1_000_000_000;
+ private static final long USED_VRAM_UPDATE_RATE = 1_000_000_000L;
+
+ private static final long MAX_VRAM_FULLNESS_INTERVAL = 30L * 1_000_000_000L;
+ private static long lastVRAMFullness = -1;
public GPUMemoryManager() {
VBO = glGenBuffers();
@@ -99,9 +105,18 @@ public class GPUMemoryManager {
}
if(end() + mesh.bufferSize() >= bufferSize) {
- ChatUtil.showNeoChatMessage("VRAM is full! Reverting to vanilla renderer. Try increasing the VRAM buffer size in the config, if possible.", ChatUtil.MessageVerbosity.ERROR);
Neodymium.renderer.destroyPending = true;
- // TODO restart renderer with more VRAM allocated when this happens.
+
+ long t = System.nanoTime();
+
+ if(lastVRAMFullness != -1 && t - lastVRAMFullness < MAX_VRAM_FULLNESS_INTERVAL) {
+ ChatUtil.showNeoChatMessage("VRAM keeps getting full! Reverting to vanilla renderer. Try increasing the VRAM buffer size in the config, if possible.", ChatUtil.MessageVerbosity.ERROR, false);
+ Compat.onNotEnoughVRAM(Config.VRAMSize);
+ } else {
+ LOGGER.debug("Reloading renderer because VRAM is full.");
+ // TODO restart renderer with more VRAM allocated when this happens.
+ }
+ lastVRAMFullness = t;
return;
}
diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
index 0ba82d1..74daa4f 100644
--- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
+++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java
@@ -159,18 +159,21 @@ public class NeoRenderer {
}
public void onRenderTickEnd() {
- if(destroyPending) {
+ if(Neodymium.isActive()) {
+ if(reloadPending) {
+ Minecraft.getMinecraft().renderGlobal.loadRenderers();
+ }
+ if(showMemoryDebugger && mem != null) {
+ GuiHelper.begin();
+ mem.drawInfo();
+ GuiHelper.end();
+ }
+ } else if(destroyPending) {
destroy();
+ destroyPending = false;
Neodymium.renderer = null;
- return;
- } else if(reloadPending) {
Minecraft.getMinecraft().renderGlobal.loadRenderers();
}
- if(showMemoryDebugger && mem != null) {
- GuiHelper.begin();
- mem.drawInfo();
- GuiHelper.end();
- }
}
private void sort(boolean pass0, boolean pass1) {