Skip to content

Commit

Permalink
Add Vulkan devices report in crash report
Browse files Browse the repository at this point in the history
  • Loading branch information
xCollateral committed Sep 23, 2024
1 parent fbed533 commit d376d8c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.vulkanmod.mixin.debug.crash_report;

import net.minecraft.SystemReport;
import net.vulkanmod.vulkan.device.DeviceManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(SystemReport.class)
public class SystemReportM {

@Inject(method = "appendToCrashReportString", at = @At("RETURN"))
private void addVulkanDevicesInfo(StringBuilder stringBuilder, CallbackInfo ci) {
stringBuilder.append("\n\n -- VulkanMod Device Report --");
stringBuilder.append(DeviceManager.getAvailableDevicesInfo());
}
}
29 changes: 16 additions & 13 deletions src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public static void init(VkInstance instance) {
DeviceManager.pickPhysicalDevice();
DeviceManager.createLogicalDevice();
} catch (Exception e) {
logUnsupportedExtensions();

e.printStackTrace();
throw new RuntimeException();
Initializer.LOGGER.info(getAvailableDevicesInfo());
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -319,29 +317,34 @@ private static int findSupportedFormat(int tiling, int features, int... formatCa
throw new RuntimeException("Failed to find supported format");
}

static void logUnsupportedExtensions() {
public static String getAvailableDevicesInfo() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("\n");

if (availableDevices == null)
return;
if (availableDevices == null) {
stringBuilder.append("\tDevice Manager not initialized");
return stringBuilder.toString();
}

if (availableDevices.isEmpty()) {
stringBuilder.append("No available device found");
stringBuilder.append("\tNo available device found");
}

for (Device device : availableDevices) {
stringBuilder.append("Device: %s\n".formatted(device.deviceName));
stringBuilder.append("\tDevice: %s\n".formatted(device.deviceName));

stringBuilder.append("\t\tVulkan Version: %s\n".formatted(device.vkVersion));

var unsupported = device.getUnsupportedExtensions(Vulkan.REQUIRED_EXTENSION);
if (unsupported.isEmpty()) {
stringBuilder.append("\t\t");
var unsupportedExtensions = device.getUnsupportedExtensions(Vulkan.REQUIRED_EXTENSION);
if (unsupportedExtensions.isEmpty()) {
stringBuilder.append("All required extensions are supported\n");
} else {
stringBuilder.append("Unsupported extension: %s\n".formatted(unsupported));
stringBuilder.append("Unsupported extension: %s\n".formatted(unsupportedExtensions));
}
}

Initializer.LOGGER.info(stringBuilder.toString());
return stringBuilder.toString();
}

public static void destroy() {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/vulkanmod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"compatibility.gl.GL15M",
"compatibility.gl.GL30M",

"debug.crash_report.SystemReportM",
"debug.DebugScreenOverlayM",
"debug.GlDebugInfoM",
"debug.KeyboardHandlerM",
Expand Down

0 comments on commit d376d8c

Please sign in to comment.