From 70e6b6ade7263a87c4bada28aac7b6b23feb9c9e Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 3 Nov 2026 18:45:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E7=A1=AC=E4=BB=B6=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E5=8A=9F=E8=83=BD=E4=B8=8E=E5=85=B3=E4=BA=8E=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20(#7174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jackhuang/hmcl/ui/main/AboutPage.java | 2 +- .../hmcl/util/platform/linux/AVFSoCModel.java | 100 -------- .../util/platform/linux/LinuxArmSoCModel.java | 236 ++++++++++++++++++ .../util/platform/linux/LinuxCPUDetector.java | 50 +++- .../platform/windows/WindowsGPUDetector.java | 43 +++- 5 files changed, 312 insertions(+), 119 deletions(-) delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/AVFSoCModel.java create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxArmSoCModel.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java index d562184c8a..a14431efa4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/AboutPage.java @@ -68,7 +68,6 @@ public final class AboutPage extends SpinnerPane { system.setSubtitle((OperatingSystem.OS_RELEASE_PRETTY_NAME == null ? "%s %s".formatted(OperatingSystem.SYSTEM_NAME, OperatingSystem.SYSTEM_VERSION.getVersion()) : "%s (%s %s)".formatted(OperatingSystem.OS_RELEASE_PRETTY_NAME, OperatingSystem.SYSTEM_NAME, OperatingSystem.SYSTEM_VERSION.getVersion()))); - system.getTags().add(new Tag(Architecture.SYSTEM_ARCH.getDisplayName())); systemInfo.getContent().add(system); if (OperatingSystem.CURRENT_OS.isLinuxOrBSD() && SystemInfo.getDesktopEnvironment() != null) { @@ -109,6 +108,7 @@ public final class AboutPage extends SpinnerPane { pane.setTitle(title); pane.setSubtitle(subtitle); pane.setLeading(SVG.LUCIDE_CPU.createIcon(32)); + pane.getTags().add(new Tag(Architecture.SYSTEM_ARCH.getDisplayName())); deviceInfo.getContent().add(pane); } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/AVFSoCModel.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/AVFSoCModel.java deleted file mode 100644 index 687cd13937..0000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/AVFSoCModel.java +++ /dev/null @@ -1,100 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (C) 2026 The HMCL Authors -// SPDX-License-Identifier: GPL-3.0-or-later WITH AdditionRef-HMCL -package org.jackhuang.hmcl.util.platform.linux; - -import org.jackhuang.hmcl.util.platform.hardware.HardwareVendor; -import org.jetbrains.annotations.NotNullByDefault; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -/// SoC identities inferred from collected AVF guest CPU data. -@NotNullByDefault -enum AVFSoCModel { - /// Xiaomi XRING O3 physical topology, confirmed from host procfs: - /// - /// | CPU IDs | Count | Arm core | Implementer / part | Variant / revision | - /// |---------|-------|------------|--------------------|--------------------| - /// | 0–3 | 4 | C1-Pro | `0x41` / `0xd8b` | `1` / `2` | - /// | 4–7 | 4 | C1-Premium | `0x41` / `0xd90` | `1` / `0` | - /// | 8–9 | 2 | C1-Ultra | `0x41` / `0xd8c` | `1` / `0` | - /// - /// Core names follow [util-linux's Arm part mapping](https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-arm.c). - XIAOMI_XRING_O3("Xiaomi XRING O3", HardwareVendor.XIAOMI) { - /// Requires Pro at CPU 0–3, Premium at CPU 4–7 and Premium or Ultra at CPU 8–9. - /// Capacity and frequency are ignored; another SoC exposing the same ordered identities is indistinguishable. - @Override - boolean matches(Map> cpuInfo) { - if (cpuInfo.size() != 10) - return false; - - for (int id = 0; id < 10; id++) { - @Nullable Map fields = cpuInfo.get(id); - if (fields == null) - return false; - - boolean matches; - if (id < 4) { - matches = matchesArmCore(fields, 0xd8b, 1, 2); - } else if (id < 8) { - matches = matchesArmCore(fields, 0xd90, 1, 0); - } else { - // On the observed Android Terminal guest (6.12.92-android16), paused Ultra cores - // allowed vCPU 8–9 to run on Premium cores. Guest procfs retained Premium identities - // even after runtime MIDRs switched between Premium and Ultra under load. - matches = matchesArmCore(fields, 0xd90, 1, 0) - || matchesArmCore(fields, 0xd8c, 1, 0); - } - - if (!matches) - return false; - } - return true; - } - }; - - /// Display name assigned when this model matches. - private final String displayName; - - /// SoC manufacturer assigned when this model matches. - private final HardwareVendor vendor; - - /// Associates the model's matching rule with its display identity. - AVFSoCModel(String displayName, HardwareVendor vendor) { - this.displayName = displayName; - this.vendor = vendor; - } - - /// Returns the model's display name. - String getDisplayName() { - return displayName; - } - - /// Returns the SoC manufacturer. - HardwareVendor getVendor() { - return vendor; - } - - /// Matches procfs identities by CPU ID without I/O or modifying the supplied data. - abstract boolean matches(Map> cpuInfo); - - /// Matches an Arm core's part and revision, rejecting absent or malformed fields. - private static boolean matchesArmCore(Map fields, int part, int variant, int revision) { - return parseCPUField(fields.get("CPU implementer")) == 0x41 - && parseCPUField(fields.get("CPU part")) == part - && parseCPUField(fields.get("CPU variant")) == variant - && parseCPUField(fields.get("CPU revision")) == revision; - } - - /// Parses decimal or hexadecimal procfs identity fields, rejecting missing or negative values. - private static int parseCPUField(@Nullable String value) { - if (value == null) - throw new NumberFormatException("Missing CPU identity field"); - value = value.trim(); - int result = value.regionMatches(true, 0, "0x", 0, 2) - ? Integer.parseInt(value.substring(2), 16) : Integer.parseInt(value); - if (result < 0) - throw new NumberFormatException("Negative CPU identity field"); - return result; - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxArmSoCModel.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxArmSoCModel.java new file mode 100644 index 0000000000..0b5413c9af --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxArmSoCModel.java @@ -0,0 +1,236 @@ +// SPDX-FileCopyrightText: Copyright (C) 2026 The HMCL Authors +// SPDX-License-Identifier: GPL-3.0-or-later WITH AdditionRef-HMCL +package org.jackhuang.hmcl.util.platform.linux; + +import org.jackhuang.hmcl.util.platform.hardware.HardwareVendor; +import org.jetbrains.annotations.NotNullByDefault; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Map; + +/// SoC identities inferred from observed Linux Arm CPU data when direct names are unavailable. +/// Virtual CPUs can hide or duplicate host cores, so these rules are heuristics, not hardware identifiers. +@NotNullByDefault +enum LinuxArmSoCModel { + /// Xiaomi XRING O3 physical topology, confirmed from host procfs: + /// + /// | CPU IDs | Count | Arm core | Implementer / part | Variant / revision | + /// |---------|-------|------------|--------------------|--------------------| + /// | 0–3 | 4 | C1-Pro | `0x41` / `0xd8b` | `1` / `2` | + /// | 4–7 | 4 | C1-Premium | `0x41` / `0xd90` | `1` / `0` | + /// | 8–9 | 2 | C1-Ultra | `0x41` / `0xd8c` | `1` / `0` | + /// + /// Core names follow [util-linux's Arm part mapping](https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-arm.c). + XIAOMI_XRING_O3("Xiaomi XRING O3", HardwareVendor.XIAOMI) { + /// Requires Pro at CPU 0–3, Premium at CPU 4–7 and Premium or Ultra at CPU 8–9. + /// Capacity and frequency are ignored; another SoC exposing the same ordered identities is indistinguishable. + @Override + boolean matches(Map> cpuInfo) { + if (cpuInfo.size() != 10) + return false; + + for (int id = 0; id < 10; id++) { + @Nullable Map fields = cpuInfo.get(id); + if (fields == null) + return false; + + boolean matches; + if (id < 4) { + matches = matchesArmCore(fields, 0xd8b, 1, 2); + } else if (id < 8) { + matches = matchesArmCore(fields, 0xd90, 1, 0); + } else { + // On the observed Android Terminal guest (6.12.92-android16), paused Ultra cores + // allowed vCPU 8–9 to run on Premium cores. Guest procfs retained Premium identities + // even after runtime MIDRs switched between Premium and Ultra under load. + matches = matchesArmCore(fields, 0xd90, 1, 0) + || matchesArmCore(fields, 0xd8c, 1, 0); + } + + if (!matches) + return false; + } + return true; + } + }, + + /// SM8650: two Cortex-A520, five Cortex-A720 and one Cortex-X4, all r0p1. + /// Confirmed by the [Galaxy S24 Ultra procfs snapshot](https://github.com/ExperimentalMachines/execubench/blob/fffa8ee723ff95c053ed0cd41dcad29288c1af5e/data/devices/probe/2026-10-04-v2/SM-S928U1-android14/artifacts/probe/cpuinfo.txt). + QUALCOMM_SNAPDRAGON_8_GEN_3("Qualcomm Snapdragon 8 Gen 3", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x41, 0xd80, 0, 1), 2, + new CoreIdentity(0x41, 0xd81, 0, 1), 5, + new CoreIdentity(0x41, 0xd82, 0, 1), 1)), + + /// SM8735: seven Cortex-A720 and one Cortex-X4, all r0p1. + /// See the [POCO F7 hardware report](https://specdeviceinfo.com/devices/xiaomi/25053pc47g-112635/). + QUALCOMM_SNAPDRAGON_8S_GEN_4("Qualcomm Snapdragon 8s Gen 4", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x41, 0xd81, 0, 1), 7, + new CoreIdentity(0x41, 0xd82, 0, 1), 1)), + + /// SM8750: six Oryon r4p4 and two r3p4 cores, all part 1. + /// Confirmed by the [Galaxy S25 procfs snapshot](https://github.com/ExperimentalMachines/execubench/blob/fffa8ee723ff95c053ed0cd41dcad29288c1af5e/data/devices/probe/2026-10-04-v2/SM-S931U1-android16/artifacts/probe/cpuinfo.txt). + /// Seven-core models and guests with missing cores are intentionally not inferred. + QUALCOMM_SNAPDRAGON_8_ELITE("Qualcomm Snapdragon 8 Elite", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x51, 0x001, 4, 4), 6, + new CoreIdentity(0x51, 0x001, 3, 4), 2)), + + /// SM8845: six Oryon r5p0 and two r4p0 cores, all part 2. + /// See the [OnePlus 15R hardware report](https://specdeviceinfo.com/devices/oneplus/cph2767-121636/) + /// and its [MIDR identifier](https://browser.geekbench.com/v6/compute/6816477). + QUALCOMM_SNAPDRAGON_8_GEN_5("Qualcomm Snapdragon 8 Gen 5", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x51, 0x002, 5, 0), 6, + new CoreIdentity(0x51, 0x002, 4, 0), 2)), + + /// SM8850: six Oryon r2p1 and two r3p1 cores, all part 2. + /// Confirmed by the [Galaxy S26 procfs snapshot](https://github.com/ExperimentalMachines/execubench/blob/fffa8ee723ff95c053ed0cd41dcad29288c1af5e/data/devices/probe/2026-10-04-v2/SM-S942U1-android16/artifacts/probe/cpuinfo.txt). + QUALCOMM_SNAPDRAGON_8_ELITE_GEN_5("Qualcomm Snapdragon 8 Elite Gen 5", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x51, 0x002, 2, 1), 6, + new CoreIdentity(0x51, 0x002, 3, 1), 2)), + + /// Snapdragon X Elite observed in WSL2: 12 Oryon cores with MIDR `0x511f0011`. + /// The [Oryon part ID](https://github.com/util-linux/util-linux/blob/master/sys-utils/lscpu-arm.c) + /// and [12-core configuration](https://www.qualcomm.com/laptops/products/snapdragon-x-elite) + /// identify the family heuristically; they cannot distinguish retail SKUs or the developer kit. + QUALCOMM_SNAPDRAGON_X_ELITE("Qualcomm Snapdragon X Elite", HardwareVendor.QUALCOMM) { + /// Requires all 12 observed Oryon r1p1 cores; reduced CPU counts cannot distinguish X Elite from X Plus. + @Override + boolean matches(Map> cpuInfo) { + return cpuInfo.size() == 12 && cpuInfo.values().stream() + .allMatch(fields -> matchesCore(fields, 0x51, 0x001, 1, 1)); + } + }, + + /// X2 Elite: six performance and six prime cores, all Oryon part 2. + /// Variants follow [Glymur's CPU identities](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/glymur.dtsi); + /// counts follow the [X2 Elite product brief](https://www.qualcomm.com/content/dam/qcomm-martech/dm-assets/documents/Snapdragon-X2-Elite-Product-Brief.pdf). + /// Revisions are not specified by these sources; any valid revision is accepted. + QUALCOMM_SNAPDRAGON_X2_ELITE("Qualcomm Snapdragon X2 Elite", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x51, 0x002, 2, -1), 6, + new CoreIdentity(0x51, 0x002, 1, -1), 6)), + + /// The 18-core X2 Elite and Elite Extreme share six performance and twelve prime cores. + /// Both use the X2 Elite family name; counts and MIDRs cannot distinguish their SKUs. + /// A capped guest may also match the 12-core family. + QUALCOMM_SNAPDRAGON_X2_ELITE_18_CORE("Qualcomm Snapdragon X2 Elite", HardwareVendor.QUALCOMM, Map.of( + new CoreIdentity(0x51, 0x002, 2, -1), 6, + new CoreIdentity(0x51, 0x002, 1, -1), 12)); + + /// Display name assigned when this model matches. + private final String displayName; + + /// SoC manufacturer assigned when this model matches. + private final HardwareVendor vendor; + + /// Required core identities and counts, or an empty map for a model with a custom matching rule. + private final @Unmodifiable Map topology; + + /// Associates the model's matching rule with its display identity. + LinuxArmSoCModel(String displayName, HardwareVendor vendor) { + this(displayName, vendor, Map.of()); + } + + /// Associates an unordered, complete core signature with its display identity. + LinuxArmSoCModel(String displayName, HardwareVendor vendor, Map topology) { + this.displayName = displayName; + this.vendor = vendor; + this.topology = Map.copyOf(topology); + } + + /// Returns the model's display name. + String getDisplayName() { + return displayName; + } + + /// Returns the SoC manufacturer. + HardwareVendor getVendor() { + return vendor; + } + + /// Resolves exact Qualcomm device-tree SoC codes before using ambiguous CPU-only heuristics. + /// Unknown codes return `null`; frequency bins and Galaxy editions retain the base family name. + static @Nullable String qualcommCodeToName(String code) { + return switch (code) { + case "sm7675" -> "Qualcomm Snapdragon 7+ Gen 3"; + case "sm8635" -> "Qualcomm Snapdragon 8s Gen 3"; + case "sm8650" -> QUALCOMM_SNAPDRAGON_8_GEN_3.displayName; + case "sm8735" -> QUALCOMM_SNAPDRAGON_8S_GEN_4.displayName; + case "sm8750" -> QUALCOMM_SNAPDRAGON_8_ELITE.displayName; + case "sm8845" -> QUALCOMM_SNAPDRAGON_8_GEN_5.displayName; + case "sm8850", "kaanapali" -> QUALCOMM_SNAPDRAGON_8_ELITE_GEN_5.displayName; + // Gen 6 code mapping follows Fastfetch; complete per-core signatures are not established here. + // https://github.com/fastfetch-cli/fastfetch/blob/aeb22b408175fe811161c996075b78e0fb260c07/src/detection/cpu/cpu_linux.c#L216-L222 + case "sm8950" -> "Qualcomm Snapdragon 8 Elite Gen 6"; + case "sm8975" -> "Qualcomm Snapdragon 8 Elite Extreme Gen 6"; + default -> null; + }; + } + + /// Returns a matching heuristic, or `null` for unknown, incomplete or malformed CPU identities. + static @Nullable LinuxArmSoCModel detect(Map> cpuInfo) { + for (LinuxArmSoCModel model : values()) { + try { + if (model.matches(cpuInfo)) + return model; + } catch (NumberFormatException e) { + // Incomplete evidence for one rule must not prevent checking the remaining rules. + } + } + return null; + } + + /// Matches procfs identities without I/O or modifying the supplied data. + /// Throws `NumberFormatException` if a required identity field is absent or malformed. + boolean matches(Map> cpuInfo) { + if (topology.isEmpty() || cpuInfo.size() != topology.values().stream().mapToInt(Integer::intValue).sum()) + return false; + + for (var entry : topology.entrySet()) { + long count = cpuInfo.values().stream().filter(entry.getKey()::matches).count(); + if (count != entry.getValue()) + return false; + } + return true; + } + + /// One disjoint core identity in a complete topology signature. + /// + /// @param implementer MIDR implementer + /// @param part MIDR part number, not the marketed Oryon generation + /// @param variant MIDR variant, which can distinguish Qualcomm core types + /// @param revision MIDR revision, or `-1` to accept any valid revision + @NotNullByDefault + private record CoreIdentity(int implementer, int part, int variant, int revision) { + /// Tests one procfs processor against this identity. + boolean matches(Map fields) { + return matchesCore(fields, implementer, part, variant, revision); + } + } + + /// Matches an Arm core's part and revision, rejecting absent or malformed fields. + private static boolean matchesArmCore(Map fields, int part, int variant, int revision) { + return matchesCore(fields, 0x41, part, variant, revision); + } + + /// Matches a core identity; revision `-1` accepts any four-bit revision, but never a missing one. + private static boolean matchesCore(Map fields, int implementer, int part, int variant, int revision) { + if (parseCPUField(fields.get("CPU implementer")) != implementer + || parseCPUField(fields.get("CPU part")) != part + || parseCPUField(fields.get("CPU variant")) != variant) + return false; + int actualRevision = parseCPUField(fields.get("CPU revision")); + return revision < 0 ? actualRevision <= 15 : actualRevision == revision; + } + + /// Parses decimal or hexadecimal procfs identity fields, rejecting missing or negative values. + private static int parseCPUField(@Nullable String value) { + if (value == null) + throw new NumberFormatException("Missing CPU identity field"); + value = value.trim(); + int result = value.regionMatches(true, 0, "0x", 0, 2) + ? Integer.parseInt(value.substring(2), 16) : Integer.parseInt(value); + if (result < 0) + throw new NumberFormatException("Negative CPU identity field"); + return result; + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxCPUDetector.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxCPUDetector.java index 0a99a92e40..1d785c12d0 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxCPUDetector.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/linux/LinuxCPUDetector.java @@ -70,6 +70,10 @@ final class LinuxCPUDetector { /// Resolves Qualcomm names from device-tree compatibles and sysfs, returning `null` for unknown models. private static @Nullable String detectQualcommName(String model, String[] compatibles) { + @Nullable String knownName = LinuxArmSoCModel.qualcommCodeToName(model); + if (knownName != null) + return knownName; + // Adapted from Fastfetch's ffCPUQualcommSnapdragonToName: // https://github.com/fastfetch-cli/fastfetch/blob/2f68ce7f7467ddbaaf31519c1d41455781d48492/src/detection/cpu/cpu_linux.c#L711-L776 // The devkit shares soc_id 555 with retail X Elite chips; its compatible entry distinguishes it. @@ -115,7 +119,7 @@ final class LinuxCPUDetector { return null; } - /// Reads the processor identity, using AVF heuristics and a virtual CPU fallback when direct names are unavailable. + /// Reads the processor identity, falling back to Arm model rules, a shared core vendor, then a virtual CPU name. private static void detectNameAndVendor(CentralProcessor.Builder builder, TreeMap> cpuInfo) { // assert !cpuInfo.isEmpty(); @Unmodifiable List deviceTreeRoots = List.of( @@ -190,16 +194,16 @@ final class LinuxCPUDetector { } boolean avf = deviceTreeRoots.stream().anyMatch(root -> Files.isDirectory(root.resolve("avf"))); - if (avf && (StringUtils.isBlank(modelName) || modelName.startsWith("ARMv8 Processor"))) { - try { - for (AVFSoCModel model : AVFSoCModel.values()) { - if (model.matches(cpuInfo)) { - builder.setName(model.getDisplayName()).setVendor(model.getVendor()); - return; - } - } - } catch (IllegalArgumentException e) { - // Missing or malformed CPU identities leave the remaining name fallbacks available. + if (Architecture.SYSTEM_ARCH.isArm() && (StringUtils.isBlank(modelName) || modelName.startsWith("ARMv8 Processor"))) { + @Nullable LinuxArmSoCModel model = LinuxArmSoCModel.detect(cpuInfo); + if (model != null) { + builder.setName(model.getDisplayName()).setVendor(model.getVendor()); + return; + } + @Nullable HardwareVendor vendor = detectArmVendor(cpuInfo); + if (vendor != null) { + builder.setName(vendor + " Processor").setVendor(vendor); + return; } } @@ -219,6 +223,30 @@ final class LinuxCPUDetector { } } + /// Returns the shared Arm core implementer when every observed CPU identifies the same known vendor. + /// Empty, incomplete, malformed or mixed identities return `null`; this does not identify a SoC product line. + static @Nullable HardwareVendor detectArmVendor(Map> cpuInfo) { + @Nullable HardwareVendor vendor = null; + for (Map fields : cpuInfo.values()) { + @Nullable String implementer = fields.get("CPU implementer"); + if (implementer == null) + return null; + implementer = implementer.trim(); + @Nullable HardwareVendor current; + try { + int id = implementer.regionMatches(true, 0, "0x", 0, 2) + ? Integer.parseInt(implementer.substring(2), 16) : Integer.parseInt(implementer); + current = HardwareVendor.ofArmImplementerId(id); + } catch (NumberFormatException e) { + return null; + } + if (current == null || (vendor != null && !vendor.equals(current))) + return null; + vendor = current; + } + return vendor; + } + /// Reads an optional sysfs attribute without making missing attributes fatal. private static @Nullable String readSysfsAttribute(Path path) { try { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows/WindowsGPUDetector.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows/WindowsGPUDetector.java index 76dbfe8e89..4947eed2c3 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows/WindowsGPUDetector.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/windows/WindowsGPUDetector.java @@ -64,6 +64,19 @@ final class WindowsGPUDetector { "Root\\IddSampleDriver", "IddSampleDriver", + // Oray Sunlogin virtual display adapter + "Root\\OrayIddDriver", + + // spacedesk Graphics Adapter + "VID_DATRONICSOFT_PID_SPACEDESK_VIRTUAL_DISPLAY_0003", + + // Looking Glass Indirect Display Device + "Root\\LGIdd", + "LGIdd", + + // Intel indirect display component, not its System-class KMD device + "SWC\\IntelVirtDisplay", + // Amyuni USB Mobile Monitor Virtual Display "usbmmidd" ); @@ -87,6 +100,10 @@ final class WindowsGPUDetector { return GraphicsCard.Type.DISPLAY_ONLY; } } + + // VMware drivers may report Broadcom as their provider. + if (StringUtils.startsWithIgnoreCase(matchingDeviceId, "PCI\\VEN_15AD&")) + return GraphicsCard.Type.VIRTUAL; } if (HardwareVendor.VMWARE.equals(vendor) || HardwareVendor.PARALLEL.equals(vendor)) @@ -141,7 +158,22 @@ final class WindowsGPUDetector { return null; } - /// Reads CIM video controllers and applies the shared name and DAC type heuristics. + /// Builds a video-controller query with matching IDs when PnP property lookup is available. + static String buildCimQuery(String cmdlet) { + return String.join(" | ", + cmdlet + " -Class Win32_VideoController", + """ + Select-Object Name,AdapterCompatibility,DriverVersion,AdapterDACType,@{Name='MatchingDeviceId';Expression={ + if ($_.PNPDeviceID -and (Get-Command Get-PnpDeviceProperty -ErrorAction SilentlyContinue)) { + (Get-PnpDeviceProperty -InstanceId $_.PNPDeviceID -KeyName DEVPKEY_Device_MatchingDeviceId -ErrorAction SilentlyContinue).Data + } + }} + """.stripTrailing(), + "Format-List", + "Out-String -Width 4096"); + } + + /// Reads CIM video controllers and applies the shared device ID, name and DAC type heuristics. /// Returns an empty list if the query or its processing fails. private static List detectByCim() { try { @@ -153,11 +185,7 @@ final class WindowsGPUDetector { "powershell.exe", "-NoProfile", "-Command", - String.join(" | ", - getCimInstance + " -Class Win32_VideoController", - "Select-Object Name,AdapterCompatibility,DriverVersion,AdapterDACType", - "Format-List" - )), + buildCimQuery(getCimInstance)), inputStream -> KeyValuePairUtils.loadList(new BufferedReader(new InputStreamReader(inputStream, OperatingSystem.NATIVE_CHARSET)))); ArrayList cards = new ArrayList<>(videoControllers.size()); @@ -166,12 +194,13 @@ final class WindowsGPUDetector { @Nullable HardwareVendor vendor = HardwareVendor.of(videoController.get("AdapterCompatibility")); @Nullable String driverVersion = videoController.get("DriverVersion"); @Nullable String adapterDACType = videoController.get("AdapterDACType"); + @Nullable String matchingDeviceId = videoController.get("MatchingDeviceId"); if (StringUtils.isNotBlank(name)) { cards.add(GraphicsCard.builder().setName(name) .setVendor(vendor) .setDriverVersion(driverVersion) - .setType(inferType(name, vendor, adapterDACType, null)) + .setType(inferType(name, vendor, adapterDACType, matchingDeviceId)) .build() ); }