diff options
author | makamys <makamys@outlook.com> | 2023-03-18 14:19:19 +0100 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2023-03-18 14:31:08 +0100 |
commit | f206874e4f177f7b1bba67bf58ef2fa75b64e7ab (patch) | |
tree | 30020701f373db99e71f2edd884ce20607003d7e | |
parent | 3b7c5e178a327e4370c75b9b3ecc0129605d8e0c (diff) | |
download | Neodymium-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.
5 files changed, 50 insertions, 13 deletions
diff --git a/src/main/java/makamys/neodymium/Compat.java b/src/main/java/makamys/neodymium/Compat.java index e6bedea..f37c1f4 100644 --- a/src/main/java/makamys/neodymium/Compat.java +++ b/src/main/java/makamys/neodymium/Compat.java @@ -10,6 +10,7 @@ import org.lwjgl.opengl.GLContext; import com.falsepattern.triangulator.api.ToggleableTessellator; import cpw.mods.fml.common.Loader; +import makamys.neodymium.config.Config; import makamys.neodymium.util.OFUtil; import makamys.neodymium.util.virtualjar.IVirtualJar; import makamys.neodymium.util.virtualjar.VirtualJar; @@ -20,6 +21,8 @@ public class Compat { private static boolean wasAdvancedOpenGLEnabled; + private static int notEnoughVRAMAmountMB = -1; + public static void applyCompatibilityTweaks() { if (Loader.isModLoaded("triangulator")) { disableTriangulator(); @@ -53,6 +56,9 @@ public class Compat { if(!GLContext.getCapabilities().OpenGL33) { criticalWarns.add("OpenGL 3.3 is not supported."); } + if(detectedNotEnoughVRAM()) { + criticalWarns.add("Not enough VRAM"); + } } public static boolean hasChanged() { @@ -66,6 +72,18 @@ public class Compat { return changed; } + + public static void onNotEnoughVRAM(int amountMB) { + notEnoughVRAMAmountMB = amountMB; + } + + public static void reset() { + notEnoughVRAMAmountMB = -1; + } + + private static boolean detectedNotEnoughVRAM() { + return Config.VRAMSize == notEnoughVRAMAmountMB; + } public static void forceEnableOptiFineDetectionOfFastCraft() { if(Compat.class.getResource("/fastcraft/Tweaker.class") != null) { diff --git a/src/main/java/makamys/neodymium/Neodymium.java b/src/main/java/makamys/neodymium/Neodymium.java index 5340550..b140a3c 100644 --- a/src/main/java/makamys/neodymium/Neodymium.java +++ b/src/main/java/makamys/neodymium/Neodymium.java @@ -86,6 +86,7 @@ public class Neodymium { Config.reloadConfig(); ChatUtil.resetShownChatMessages(); + Compat.reset(); } private void onPlayerWorldChanged(World newWorld) { @@ -167,7 +168,7 @@ public class Neodymium renderer.forceRenderFog = true; } } else if(event.phase == TickEvent.Phase.END) { - if(isActive()) { + if(renderer != null) { renderer.onRenderTickEnd(); } } 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) { diff --git a/src/main/java/makamys/neodymium/util/ChatUtil.java b/src/main/java/makamys/neodymium/util/ChatUtil.java index 7c2337f..06b4ee4 100644 --- a/src/main/java/makamys/neodymium/util/ChatUtil.java +++ b/src/main/java/makamys/neodymium/util/ChatUtil.java @@ -31,7 +31,7 @@ public class ChatUtil { } public static void showNeoChatMessage(String text, MessageVerbosity verbosity, boolean once) { - if(shownChatMessages.contains(text)) return; + if(once && shownChatMessages.contains(text)) return; String verbosityText = verbosity == MessageVerbosity.WARNING |