From d376d8c3fdfd2275f072ce751d72c0c682807b81 Mon Sep 17 00:00:00 2001 From: xCollateral <103696619+xCollateral@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:58:22 +0200 Subject: [PATCH] Add Vulkan devices report in crash report --- .../debug/crash_report/SystemReportM.java | 18 ++++++++++++ .../vulkan/device/DeviceManager.java | 29 ++++++++++--------- src/main/resources/vulkanmod.mixins.json | 1 + 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 src/main/java/net/vulkanmod/mixin/debug/crash_report/SystemReportM.java diff --git a/src/main/java/net/vulkanmod/mixin/debug/crash_report/SystemReportM.java b/src/main/java/net/vulkanmod/mixin/debug/crash_report/SystemReportM.java new file mode 100644 index 000000000..621a389a7 --- /dev/null +++ b/src/main/java/net/vulkanmod/mixin/debug/crash_report/SystemReportM.java @@ -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()); + } +} diff --git a/src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java b/src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java index e6f768410..18fd202a0 100644 --- a/src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java +++ b/src/main/java/net/vulkanmod/vulkan/device/DeviceManager.java @@ -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); } } @@ -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() { diff --git a/src/main/resources/vulkanmod.mixins.json b/src/main/resources/vulkanmod.mixins.json index 40f082703..674e07398 100644 --- a/src/main/resources/vulkanmod.mixins.json +++ b/src/main/resources/vulkanmod.mixins.json @@ -27,6 +27,7 @@ "compatibility.gl.GL15M", "compatibility.gl.GL30M", + "debug.crash_report.SystemReportM", "debug.DebugScreenOverlayM", "debug.GlDebugInfoM", "debug.KeyboardHandlerM",