From 0b8e361eec0d06a0ac934b0ee7106365f989b134 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Wed, 7 Aug 2024 19:43:12 +0200 Subject: [PATCH] RenderDoc support --- .../java/net/neoforged/devlaunch/Main.java | 6 ++-- .../devlaunch/RenderDocIntegration.java | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/neoforged/devlaunch/RenderDocIntegration.java diff --git a/src/main/java/net/neoforged/devlaunch/Main.java b/src/main/java/net/neoforged/devlaunch/Main.java index ecaa485..6064ab9 100644 --- a/src/main/java/net/neoforged/devlaunch/Main.java +++ b/src/main/java/net/neoforged/devlaunch/Main.java @@ -30,6 +30,8 @@ public class Main { public static void main(String[] args) throws Throwable { + RenderDocIntegration.init(); + if (args.length == 0) { throw new IllegalArgumentException("DevLaunch requires at least one argument: an @-file to expand, or the main class."); } @@ -46,13 +48,13 @@ public static void main(String[] args) throws Throwable { Method mainMethod; try { - mainMethod = Class.forName(newArgs.get(0)).getMethod("main", String[].class); + mainMethod = Class.forName(newArgs.remove(0)).getMethod("main", String[].class); } catch (ReflectiveOperationException e) { throw new IllegalArgumentException("Could not find main class or main method. Given main class: " + newArgs.get(0), e); } try { - mainMethod.invoke(null, (Object) newArgs.subList(1, newArgs.size()).toArray(String[]::new)); + mainMethod.invoke(null, (Object) newArgs.toArray(String[]::new)); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (ReflectiveOperationException e) { diff --git a/src/main/java/net/neoforged/devlaunch/RenderDocIntegration.java b/src/main/java/net/neoforged/devlaunch/RenderDocIntegration.java new file mode 100644 index 0000000..279fd20 --- /dev/null +++ b/src/main/java/net/neoforged/devlaunch/RenderDocIntegration.java @@ -0,0 +1,32 @@ +package net.neoforged.devlaunch; + +import java.io.File; + +/** + * Loads the RenderDoc DLL, allowing attaching from the RenderDoc UI. + * On Linux, this should have the same effect as LD_PRELOAD since at no point + * have any OpenGL DLLs be loaded yet. + */ +final class RenderDocIntegration { + private static final String SYSTEM_PROPERTY = "devLaunch.renderDocLibrary"; + + private RenderDocIntegration() { + } + + public static void init() { + String renderDocLibrary = System.getProperty(SYSTEM_PROPERTY); + if (renderDocLibrary == null) { + return; + } + + var libraryFile = new File(renderDocLibrary); + if (!libraryFile.isFile()) { + System.err.println("The RenderDoc library specified by the system property " + SYSTEM_PROPERTY + + " does not exist: " + libraryFile); + System.exit(2); + } + + System.out.println("Loading renderdoc from " + libraryFile.getAbsolutePath()); + System.load(libraryFile.getAbsolutePath()); + } +}