Skip to content

Commit

Permalink
Renderdoc support, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xirreal committed May 6, 2024
1 parent 5763f9f commit d3590c0
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The NVIDIA SDK DLL included is licensed under: https://docs.nvidia.com/nsight-graphics/CopyrightAndLicenses/index.html
For issues regarding licensing, please contact "me@xirreal.dev".
For issues regarvding licensing, please contact "me@xirreal.dev".
12 changes: 12 additions & 0 deletions LICENSE.renderdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The MIT License (MIT)
Copyright (c) 2015-2024 Baldur Karlsson

Copyright (c) 2014 Crytek

Copyright (c) 1998-2018 Third party code and tools

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# NSight Loader
### actually this loads Renderdoc too but whatever

This version-agnostic Fabric mod allows you to inject NSight or Renderdoc into Minecraft, allowing you to attach at any time instead of having to launch the game through the GUI either manually or by launching the launcher (wow that sucks to say).

### Usage

1. Install Fabric (1.18.2 or later, as long as the loader is 0.15.0 or newer)
2. Drop the mod into your mods folder
3. Launch the game, pick the debugger you want to use
4. Attach to the game process via your debugger of choice
5. Profit?

### Advanced usage

You can skip the dialog (useful for some dev environments) by setting the `debugging` flag to the debugger you want.
Allowed options are:
```shell
-Ddebugger=nsight
-Ddebugger=renderdoc
```
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ minecraft_version=1.18.2
yarn_mappings=1.18.2+build.4
loader_version=0.15.6

mod_version=1.0.1
mod_version=1.1.0
maven_group=dev.xirreal
archives_base_name=nsight-loader

Expand Down
94 changes: 77 additions & 17 deletions src/main/java/dev/xirreal/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,19 @@
import java.io.InputStream;
import java.util.List;

import javax.swing.*;

public class Main implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("nsight-loader");
@Override
public void onInitialize() {
String os = System.getProperty("os.name").toLowerCase();
if(!os.contains("win")) {
LOGGER.error("Unsupported OS: " + os);
return;
}
String arch = System.getProperty("os.arch").toLowerCase();
if(!arch.contains("64")) {
LOGGER.error("Unsupported architecture: " + arch);
return;
}

String assetPath = "/assets/nsight-loader/NGFX_Injection.dll";
String NGFX_DLL;

public static String unpackResource(String resourceName) {
String assetPath = "/assets/nsight-loader/" + resourceName;
try (InputStream in = Main.class.getResourceAsStream(assetPath)) {
if (in == null) {
throw new RuntimeException("DLL not found: " + assetPath);
}
File tempFile = File.createTempFile("NGFX_Injection", ".dll");
tempFile.deleteOnExit();
NGFX_DLL = tempFile.getAbsolutePath();

try (FileOutputStream out = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
Expand All @@ -44,9 +32,81 @@ public void onInitialize() {
out.write(buffer, 0, bytesRead);
}
}

return tempFile.getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("Failed to load DLL from " + assetPath, e);
}
}

@Override
public void onInitialize() {
String os = System.getProperty("os.name").toLowerCase();
if(!os.contains("win")) {
LOGGER.error("Unsupported OS: " + os);
return;
}
String arch = System.getProperty("os.arch").toLowerCase();
if(!arch.contains("64")) {
LOGGER.error("Unsupported architecture: " + arch);
return;
}

int option = -1;
String optionString = System.getProperty("debugger");
if(optionString != null) {
if(optionString.equalsIgnoreCase("renderdoc")) {
option = JOptionPane.NO_OPTION;
} else if(optionString.equalsIgnoreCase("nsight")) {
option = JOptionPane.YES_OPTION;
}
}

if(option == -1) {
System.setProperty("java.awt.headless", "false");

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ReflectiveOperationException | UnsupportedLookAndFeelException ignored) {
}

String[] options = {"NSight", "Renderdoc"};

JFrame frame = new JFrame("Shader debugging");

frame.setUndecorated( true );
frame.setVisible( true );
frame.setLocationRelativeTo( null );
frame.requestFocus();

option = JOptionPane.showOptionDialog(frame, "Pick the debugger to be loaded", "Shader debugging", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, null);

frame.dispose();

System.setProperty("java.awt.headless", "true"); // In case not having headless mode breaks something down the line...
}

if (option == JOptionPane.CLOSED_OPTION) {
LOGGER.info("Skipping injection...");
return;
}

if(option != JOptionPane.OK_OPTION) {
LOGGER.info("Loading Renderdoc injector...");
String RENDERDOC_DLL = unpackResource("renderdoc.dll");
try {
System.load(RENDERDOC_DLL);
LOGGER.info("Renderdoc loaded successfully");
} catch (UnsatisfiedLinkError e) {
LOGGER.error("Failed to load Renderdoc: ", e);
}
return;
}

LOGGER.info("Loading NSight...");

String NGFX_DLL = unpackResource("NGFX_Injection.dll");

try {
NGFX ngfx = new NGFX(NGFX_DLL);
Expand All @@ -67,7 +127,7 @@ public void onInitialize() {
LOGGER.error("No installations found");
return;
}
LOGGER.info("Found installation: " + newestInstallation.installationPath);
LOGGER.info("Found installation on " + newestInstallation.installationPath + ": drive");

List<Activity> activities = ngfx.EnumerateActivities(newestInstallation);
Activity activity = activities.stream().filter(a -> a.type == Activity.ActivityType.NGFX_INJECTION_ACTIVITY_FRAME_DEBUGGER).findFirst().orElse(null);
Expand Down
Binary file not shown.

0 comments on commit d3590c0

Please sign in to comment.