From 32409ebe2b92a5f82507e27f04c6c0cd348bd28a Mon Sep 17 00:00:00 2001 From: chenjiangqun Date: Mon, 29 Jun 2026 10:55:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=20GPU=20=E4=BF=A1=E6=81=AF=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WinISP/FormISP_MSI.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs b/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs index 768434d..64b9f1b 100644 --- a/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs +++ b/WIN10_WinISP_SrcCode_For_MOKA_20250416_1/WinISP/FormISP_MSI.cs @@ -1663,6 +1663,8 @@ namespace WinISP SetStatusMsg("Ready"); frmISP.WriteLog("===== Start ISP =====", "info"); frmISP.WriteLog("binFilePath = " + _binFilePath + ", simI2cCtrl = " + _simI2cCtrl, "info"); + frmISP.WriteLog("[ENV] GPU = " + GetGpuInfoSnapshot(), "info"); + //int totalFailCnt1 = 0; int failCnt = 0; int checkSumFailCnt = 0; @@ -2288,5 +2290,92 @@ namespace WinISP } return buffer; } + + /// + /// 通过 WMI 采集所有显卡信息快照,用于诊断不同 GPU 厂商(N/A/I)下的 ISP 行为差异。 + /// 该方法自带异常拦截,任何失败都不影响主升级流程。 + /// + private string GetGpuInfoSnapshot() + { + var sb = new System.Text.StringBuilder(); + try + { + using (var searcher = new System.Management.ManagementObjectSearcher( + "SELECT Name, AdapterCompatibility, DriverVersion, AdapterRAM, " + + "VideoProcessor, PNPDeviceID, Status FROM Win32_VideoController")) + { + int idx = 0; + foreach (var mo in searcher.Get()) + { + idx++; + string name = SafeWmi(mo, "Name"); + string vendor = SafeWmi(mo, "AdapterCompatibility"); // 厂商: NVIDIA / Advanced Micro Devices / Intel + string driverVer = SafeWmi(mo, "DriverVersion"); + string ramStr = SafeWmi(mo, "AdapterRAM"); + string gpuProc = SafeWmi(mo, "VideoProcessor"); + string pnp = SafeWmi(mo, "PNPDeviceID"); + string status = SafeWmi(mo, "Status"); + + // 归一化厂商标识,方便日志里一眼区分 N/A/I 卡 + string vendorTag = ClassifyGpuVendor(vendor, name, pnp); + + string ramMB = "N/A"; + long ramBytes; + if (long.TryParse(ramStr, out ramBytes) && ramBytes > 0) + ramMB = (ramBytes / 1024 / 1024) + "MB"; + + sb.Append("[GPU#" + idx + "] tag=" + vendorTag + + " name=" + name + + " vendor=" + vendor + + " driver=" + driverVer + + " ram=" + ramMB + + " proc=" + gpuProc + + " status=" + status + + " pnp=" + pnp + + " | "); + } + if (idx == 0) + sb.Append("No Win32_VideoController found."); + } + } + catch (Exception ex) + { + sb.Append("GetGpuInfoSnapshot EXCEPTION: " + ex.Message); + } + return sb.ToString(); + } + + /// WMI 字段安全读取,避免某些字段为 null 抛异常。 + private string SafeWmi(System.Management.ManagementBaseObject mo, string prop) + { + try + { + var v = mo[prop]; + return v == null ? "null" : v.ToString().Trim(); + } + catch + { + return "err"; + } + } + + /// 根据厂商字符串/名称/PNPDeviceID 的 VEN_ 归类为 N/A/I/Other。 + private string ClassifyGpuVendor(string vendor, string name, string pnp) + { + string s = ((vendor ?? "") + " " + (name ?? "")).ToUpperInvariant(); + string p = (pnp ?? "").ToUpperInvariant(); + + // 优先用 PCI VendorID 判断,最准 + if (p.Contains("VEN_10DE")) return "N(NVIDIA)"; + if (p.Contains("VEN_1002")) return "A(AMD)"; + if (p.Contains("VEN_8086")) return "I(Intel)"; + + // 退化到字符串匹配 + if (s.Contains("NVIDIA")) return "N(NVIDIA)"; + if (s.Contains("AMD") || s.Contains("ADVANCED MICRO") || s.Contains("RADEON") || s.Contains("ATI")) return "A(AMD)"; + if (s.Contains("INTEL")) return "I(Intel)"; + + return "Other"; + } } }