mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 14:44:28 +00:00
Initial commit for shader-loading-optimizations (#2213)
This commit is contained in:
1 parent
10922edca3
commit
38af64f10c
35 files changed
+1239
-194
No files matched your search
@@ -0,0 +1,96 @@
|
||||
package com.gtnewhorizons.angelica.iris;
|
||||
|
||||
import com.gtnewhorizons.angelica.utils.AngelicaJar;
|
||||
import net.coderbot.iris.Iris;
|
||||
import net.coderbot.iris.parsing.IrisFunctions;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Prepares for the first shader pack load on a background thread while the game sits at the main menu.
|
||||
*/
|
||||
public final class ShaderWarmup {
|
||||
private static final Logger LOGGER = LogManager.getLogger("Angelica/ShaderWarmup");
|
||||
private static final String[] PACKAGES = { "net/coderbot/iris/", "kroppeb/stareval/" };
|
||||
private static final String SKIPPED_PACKAGE = "net/coderbot/iris/compat/dh/";
|
||||
|
||||
private static boolean started;
|
||||
|
||||
private ShaderWarmup() {}
|
||||
|
||||
/** Main thread only */
|
||||
public static void start() {
|
||||
if (started) return;
|
||||
started = true;
|
||||
final Runnable readSelectedPack = Iris.prepareSelectedShaderPack();
|
||||
final Thread thread = new Thread(() -> {
|
||||
preloadClasses();
|
||||
if (readSelectedPack != null) readSelectedPack.run();
|
||||
}, "Angelica-Shader-Warmup");
|
||||
thread.setDaemon(true);
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static void preloadClasses() {
|
||||
final List<String> names;
|
||||
try {
|
||||
names = listClasses();
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug("Could not list shader classes to preload", e);
|
||||
return;
|
||||
}
|
||||
final ClassLoader loader = Iris.class.getClassLoader();
|
||||
for (String name : names) {
|
||||
try {
|
||||
Class.forName(name, false, loader);
|
||||
} catch (Throwable ignored) {
|
||||
// A class that cannot load here fails the same way when the pipeline reaches it
|
||||
}
|
||||
}
|
||||
try {
|
||||
Class.forName(IrisFunctions.class.getName(), true, loader);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> listClasses() throws Exception {
|
||||
final Path source = AngelicaJar.location();
|
||||
final List<String> names = new ArrayList<>();
|
||||
if (source == null) return names;
|
||||
if (Files.isDirectory(source)) {
|
||||
try (Stream<Path> files = Files.walk(source)) {
|
||||
files.forEach(file -> addIfShaderClass(names, source.relativize(file).toString().replace('\\', '/')));
|
||||
}
|
||||
} else {
|
||||
try (ZipFile jar = new ZipFile(source.toFile())) {
|
||||
final Enumeration<? extends ZipEntry> entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
addIfShaderClass(names, entries.nextElement().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
}
|
||||
|
||||
private static void addIfShaderClass(List<String> names, String entry) {
|
||||
if (!entry.endsWith(".class") || entry.startsWith(SKIPPED_PACKAGE)) return;
|
||||
for (String packagePath : PACKAGES) {
|
||||
if (entry.startsWith(packagePath)) {
|
||||
names.add(entry.substring(0, entry.length() - ".class".length()).replace('/', '.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.gtnewhorizons.angelica.debug.DebugKeyHandler;
|
||||
import com.gtnewhorizons.angelica.rendering.culling.GpuCulling;
|
||||
import static com.gtnewhorizons.angelica.AngelicaMod.MOD_ID;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.Locale;
|
||||
@@ -41,7 +40,6 @@ import com.gtnewhorizon.gtnhlib.client.renderer.vao.VAOManager;
|
||||
import com.gtnewhorizons.angelica.client.font.DarkModeUtils;
|
||||
import com.gtnewhorizons.angelica.commands.AngelicaCommand;
|
||||
import com.gtnewhorizons.angelica.AngelicaMod;
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import com.gtnewhorizons.angelica.common.BlockError;
|
||||
import com.gtnewhorizons.angelica.common.BlockIsbrhTest;
|
||||
import com.gtnewhorizons.angelica.compat.ModStatus;
|
||||
@@ -65,9 +63,9 @@ import com.gtnewhorizons.angelica.glsm.GLStateManager;
|
||||
import com.gtnewhorizons.angelica.glsm.backend.BackendStartGuard;
|
||||
import com.gtnewhorizons.angelica.glsm.backend.VSyncMode;
|
||||
import com.gtnewhorizons.angelica.glsm.profiling.Tracy;
|
||||
import com.gtnewhorizons.angelica.glsm.shader.ShaderDiskCache;
|
||||
import com.gtnewhorizons.angelica.hudcaching.HUDCaching;
|
||||
import com.gtnewhorizons.angelica.iris.IrisGLSMBridge;
|
||||
import com.gtnewhorizons.angelica.iris.ShaderWarmup;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.IGameSettingsExt;
|
||||
import com.gtnewhorizons.angelica.render.CloudRenderer;
|
||||
import com.gtnewhorizons.angelica.render.EmissiveTextureAutoloader;
|
||||
@@ -84,6 +82,7 @@ import com.gtnewhorizons.angelica.rendering.celeritas.threading.ThreadedChunkTas
|
||||
import com.gtnewhorizons.angelica.rendering.items.BlockRenderListManager;
|
||||
import com.gtnewhorizons.angelica.rendering.items.ItemRenderListManager;
|
||||
import com.gtnewhorizons.angelica.rendering.tesr.TesrLifecycle;
|
||||
import com.gtnewhorizons.angelica.utils.AngelicaJar;
|
||||
import com.gtnewhorizons.angelica.utils.AnimationMode;
|
||||
import com.gtnewhorizons.angelica.utils.ManagedEnum;
|
||||
import com.gtnewhorizons.angelica.zoom.Zoom;
|
||||
@@ -149,11 +148,7 @@ public final class ClientProxy extends CommonProxy {
|
||||
BlockIsbrhTest.renderId = RenderingRegistry.getNextAvailableRenderId();
|
||||
RenderingRegistry.registerBlockHandler(BlockIsbrhTest.renderId, new IsbrhTestRenderer());
|
||||
}
|
||||
final File source = event.getSourceFile();
|
||||
if (source != null && source.isFile()) {
|
||||
ShaderDiskCache.configure(Minecraft.getMinecraft().mcDataDir.toPath().resolve("angelica").resolve("shadercache"),
|
||||
Tags.VERSION + "|" + source.length() + "|" + source.lastModified());
|
||||
}
|
||||
AngelicaJar.configureShaderDiskCache(event.getSourceFile());
|
||||
if (AngelicaConfig.enableIris) {
|
||||
IrisGLSMBridge.installImmediateExtendedHandler();
|
||||
Iris.warmupShaderTransforms();
|
||||
@@ -391,6 +386,7 @@ public final class ClientProxy extends CommonProxy {
|
||||
if (event.gui instanceof GuiMainMenu && gameStartTime == -1) {
|
||||
gameStartTime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000f;
|
||||
LOGGER.info("The game loaded in {} seconds.", gameStartTime);
|
||||
if (AngelicaConfig.enableIris) ShaderWarmup.start();
|
||||
}
|
||||
|
||||
// force reset zoom when a GUI is opened
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.gtnewhorizons.angelica.utils;
|
||||
|
||||
import com.gtnewhorizons.angelica.Tags;
|
||||
import com.gtnewhorizons.angelica.glsm.shader.ShaderDiskCache;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public final class AngelicaJar {
|
||||
private AngelicaJar() {}
|
||||
|
||||
/** The jar or classes directory Angelica was loaded from, or null if something really went wrong. */
|
||||
@Nullable
|
||||
public static Path location() {
|
||||
try {
|
||||
String location = AngelicaJar.class.getProtectionDomain().getCodeSource().getLocation().toString();
|
||||
if (location.startsWith("jar:")) {
|
||||
final int separator = location.indexOf("!/");
|
||||
location = location.substring("jar:".length(), separator < 0 ? location.length() : separator);
|
||||
}
|
||||
return Paths.get(new URI(location));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void configureShaderDiskCache(@Nullable File jar) {
|
||||
if (jar == null || !jar.isFile()) return;
|
||||
ShaderDiskCache.configure(Minecraft.getMinecraft().mcDataDir.toPath().resolve("angelica").resolve("shadercache"),
|
||||
Tags.VERSION + "|" + jar.length() + "|" + jar.lastModified());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user