From e62742f65dfd271a8503447caa3ec168fec87720 Mon Sep 17 00:00:00 2001 From: ChenRuoT Date: Tue, 1 Dec 2026 13:01:37 +0800 Subject: [PATCH] fix(host): surface Vulkan probe failures in setup and doctor --- frontend/src/components/Setup.tsx | 7 +++-- frontend/src/i18n/domains/wizard.gen.ts | 2 ++ frontend/src/i18n/keys.gen.ts | 1 + frontend/wailsjs/go/models.ts | 2 ++ internal/cli/cli.go | 7 +++-- internal/host/host.go | 1 + internal/host/host_windows.go | 26 +++++++++------- internal/host/vulkan_windows.go | 40 +++++++++++++++++-------- internal/i18n/catalog_gen.go | 3 ++ locales/en-US/native.json | 1 + locales/en-US/wizard.json | 1 + locales/zh-CN/native.json | 1 + locales/zh-CN/wizard.json | 1 + 13 files changed, 66 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/Setup.tsx b/frontend/src/components/Setup.tsx index 0c24142..19eb844 100644 --- a/frontend/src/components/Setup.tsx +++ b/frontend/src/components/Setup.tsx @@ -203,7 +203,7 @@ const RuntimeStep: React.FC = ({ locale, tr, state, runtimeTask, onCh const whpxOK = host.whpx === 'ready' const gpu = host.recommended_gpu ?? (host.gpus ?? []).find((g) => g.kind !== 'virtual') const gpuHint = gpuCompatHint(locale, gpu) - const gpuOK = !!gpu && gpu.compat !== 'warn' && gpu.compat !== 'unsupported' + const gpuOK = !host.vulkan_probe_error && !!gpu && gpu.compat !== 'warn' && gpu.compat !== 'unsupported' const recMem = recommendedMemoryGB(host) return ( <> @@ -236,7 +236,10 @@ const RuntimeStep: React.FC = ({ locale, tr, state, runtimeTask, onCh
{tr('setupGPU')}
-
{gpu ? shortGPUName(gpu.name) : tr('setupNoGPU')}
+ {gpu &&
{shortGPUName(gpu.name)}
} + {host.vulkan_probe_error ? ( +
{tr('vulkanProbeFailed', { detail: host.vulkan_probe_error })}
+ ) : !gpu &&
{tr('setupNoGPU')}
} {gpuHint &&
{gpuHint}
}
diff --git a/frontend/src/i18n/domains/wizard.gen.ts b/frontend/src/i18n/domains/wizard.gen.ts index 2dfc62a..93b1c61 100644 --- a/frontend/src/i18n/domains/wizard.gen.ts +++ b/frontend/src/i18n/domains/wizard.gen.ts @@ -79,6 +79,7 @@ export const wizardZh: Record = { "summarySource": "来源", "validationChecking": "正在检查…", "validationPassed": "可以创建", + "vulkanProbeFailed": "Vulkan 探测失败({detail})。请运行 vulkaninfo --summary 检查驱动。", "wizChooseFile": "选择…", "wizNoFile": "还没有选择文件", "wizOptions": "选项", @@ -166,6 +167,7 @@ export const wizardEn: Record = { "summarySource": "Source", "validationChecking": "Checking…", "validationPassed": "Ready to create", + "vulkanProbeFailed": "Vulkan probe failed ({detail}). Run vulkaninfo --summary to check the driver.", "wizChooseFile": "Choose…", "wizNoFile": "No file chosen", "wizOptions": "Options", diff --git a/frontend/src/i18n/keys.gen.ts b/frontend/src/i18n/keys.gen.ts index 9ee8854..97a6a15 100644 --- a/frontend/src/i18n/keys.gen.ts +++ b/frontend/src/i18n/keys.gen.ts @@ -890,6 +890,7 @@ export type I18nKey = | "viewLogs" | "vmDir" | "vmName" + | "vulkanProbeFailed" | "welcomeCheckHost" | "welcomeSub" | "welcomeTitle" diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 7d181bf..1c69716 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -762,6 +762,7 @@ export namespace host { whpx_caps: WHPXCapabilities; needs_cold_reboot_workaround: boolean; gpus: GPUInfo[]; + vulkan_probe_error?: string; recommended_gpu?: GPUInfo; displays?: DisplayInfo[]; primary_display?: DisplayInfo; @@ -807,6 +808,7 @@ export namespace host { this.whpx_caps = this.convertValues(source["whpx_caps"], WHPXCapabilities); this.needs_cold_reboot_workaround = source["needs_cold_reboot_workaround"]; this.gpus = this.convertValues(source["gpus"], GPUInfo); + this.vulkan_probe_error = source["vulkan_probe_error"]; this.recommended_gpu = this.convertValues(source["recommended_gpu"], GPUInfo); this.displays = this.convertValues(source["displays"], DisplayInfo); this.primary_display = this.convertValues(source["primary_display"], DisplayInfo); diff --git a/internal/cli/cli.go b/internal/cli/cli.go index aa74164..1d40ef8 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -194,9 +194,12 @@ func cmdDoctor(cfg *config.Config, loc i18n.Locale, args []string) error { } fmt.Printf("%-36s: %s\n", i18n.T(loc, "doctor.whpx"), i18n.T(loc, whpxKey)) - if len(rep.GPUs) == 0 { + if rep.VulkanProbeError != "" { + fmt.Printf("%-36s: %s\n", i18n.T(loc, "doctor.gpu"), i18n.M(loc, "doctor.gpu.probe_failed", i18n.Vars{"detail": rep.VulkanProbeError})) + } + if len(rep.GPUs) == 0 && rep.VulkanProbeError == "" { fmt.Printf("%-36s: %s\n", i18n.T(loc, "doctor.gpu"), i18n.T(loc, "doctor.gpu.none")) - } else { + } else if len(rep.GPUs) > 0 { fmt.Printf("%s:\n", i18n.T(loc, "doctor.gpu")) for _, g := range rep.GPUs { tags := []string{} diff --git a/internal/host/host.go b/internal/host/host.go index 84e1203..e6cfe37 100644 --- a/internal/host/host.go +++ b/internal/host/host.go @@ -91,6 +91,7 @@ type Report struct { WHPXCaps WHPXCapabilities `json:"whpx_caps"` NeedsColdRebootWorkaround bool `json:"needs_cold_reboot_workaround"` GPUs []GPUInfo `json:"gpus"` + VulkanProbeError string `json:"vulkan_probe_error,omitempty"` RecommendedGPU *GPUInfo `json:"recommended_gpu,omitempty"` Displays []DisplayInfo `json:"displays,omitempty"` PrimaryDisplay *DisplayInfo `json:"primary_display,omitempty"` diff --git a/internal/host/host_windows.go b/internal/host/host_windows.go index 11da2fe..4e00778 100644 --- a/internal/host/host_windows.go +++ b/internal/host/host_windows.go @@ -64,11 +64,12 @@ type memoryStatusEx struct { } type staticHostSnapshot struct { - needsColdReboot bool - gpus []GPUInfo - recGPU *GPUInfo - topo hybridTopology - topoOK bool + needsColdReboot bool + gpus []GPUInfo + vulkanProbeError string + recGPU *GPUInfo + topo hybridTopology + topoOK bool } var ( @@ -82,7 +83,7 @@ var ( func getStaticHostSnapshot() staticHostSnapshot { staticHostOnce.Do(func() { - gpus := probeVulkanGPUs() + gpus, err := probeVulkanGPUs() topo, ok := probeHybridTopology() staticHostData = staticHostSnapshot{ needsColdReboot: probeNeedsColdRebootWorkaround(), @@ -91,6 +92,9 @@ func getStaticHostSnapshot() staticHostSnapshot { topo: topo, topoOK: ok, } + if err != nil { + staticHostData.vulkanProbeError = err.Error() + } }) return staticHostData } @@ -122,6 +126,7 @@ func Inspect(dataRoot string) Report { WHPX: probeWHPX(), NeedsColdRebootWorkaround: st.needsColdReboot, GPUs: gpusCopy, + VulkanProbeError: st.vulkanProbeError, RecommendedGPU: recGPUCopy, } if rep.WHPX == WHPXReady { @@ -545,10 +550,11 @@ func isUSBBusVolume(vol string) bool { // ProbeVulkanGPUs returns the current Vulkan adapters without using Inspect's cache. func ProbeVulkanGPUs() []GPUInfo { - return probeVulkanGPUs() + gpus, _ := probeVulkanGPUs() + return gpus } -func probeVulkanGPUs() []GPUInfo { +func probeVulkanGPUs() ([]GPUInfo, error) { const baseKey = `SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}` var regGPUs []GPUInfo for i := 0; i < 32; i++ { @@ -578,8 +584,8 @@ func probeVulkanGPUs() []GPUInfo { DriverVersion: drvVer, }) } - vkProbes := probeVulkanDevices() - return MergeRegistryAndVulkanGPUs(regGPUs, vkProbes) + vkProbes, err := probeVulkanDevices() + return MergeRegistryAndVulkanGPUs(regGPUs, vkProbes), err } func regReadString(root uintptr, subKey, valueName string) (string, bool) { diff --git a/internal/host/vulkan_windows.go b/internal/host/vulkan_windows.go index f9c1cab..01815fb 100644 --- a/internal/host/vulkan_windows.go +++ b/internal/host/vulkan_windows.go @@ -5,6 +5,7 @@ package host import ( "bytes" "encoding/binary" + "fmt" "syscall" "unsafe" ) @@ -50,21 +51,21 @@ type vkExtensionProperties struct { // probeVulkanDevices loads vulkan-1.dll and enumerates all visible Vulkan // physical devices along with their API version, PCI IDs, device type, and -// advertised device extensions. Returns nil cleanly if the Vulkan loader is -// absent or refuses instance creation. -func probeVulkanDevices() []VulkanDeviceProbe { +// advertised device extensions. An empty list with no error means enumeration succeeded. +func probeVulkanDevices() ([]VulkanDeviceProbe, error) { dll := syscall.NewLazyDLL("vulkan-1.dll") if err := dll.Load(); err != nil { - return nil + return nil, err } pCreateInst := dll.NewProc("vkCreateInstance") pDestroyInst := dll.NewProc("vkDestroyInstance") pEnumPhys := dll.NewProc("vkEnumeratePhysicalDevices") pGetProps := dll.NewProc("vkGetPhysicalDeviceProperties") pEnumExts := dll.NewProc("vkEnumerateDeviceExtensionProperties") - if pCreateInst.Find() != nil || pDestroyInst.Find() != nil || - pEnumPhys.Find() != nil || pGetProps.Find() != nil || pEnumExts.Find() != nil { - return nil + for _, proc := range []*syscall.LazyProc{pCreateInst, pDestroyInst, pEnumPhys, pGetProps, pEnumExts} { + if err := proc.Find(); err != nil { + return nil, err + } } appName := append([]byte("reims-go"), 0) @@ -92,15 +93,21 @@ func probeVulkanDevices() []VulkanDeviceProbe { uintptr(unsafe.Pointer(&instance)), ) } - if int32(res) != vkSuccess || instance == 0 { - return nil + if int32(res) != vkSuccess { + return nil, vulkanResultError("vkCreateInstance", int32(res)) + } + if instance == 0 { + return nil, fmt.Errorf("vkCreateInstance: VK_NULL_HANDLE") } defer pDestroyInst.Call(instance, 0) var count uint32 res, _, _ = pEnumPhys.Call(instance, uintptr(unsafe.Pointer(&count)), 0) - if (int32(res) != vkSuccess && int32(res) != vkIncomplete) || count == 0 { - return nil + if int32(res) != vkSuccess && int32(res) != vkIncomplete { + return nil, vulkanResultError("vkEnumeratePhysicalDevices", int32(res)) + } + if count == 0 { + return nil, nil } if count > 32 { count = 32 @@ -112,7 +119,7 @@ func probeVulkanDevices() []VulkanDeviceProbe { uintptr(unsafe.Pointer(&devices[0])), ) if int32(res) != vkSuccess && int32(res) != vkIncomplete { - return nil + return nil, vulkanResultError("vkEnumeratePhysicalDevices", int32(res)) } out := make([]VulkanDeviceProbe, 0, count) @@ -136,7 +143,14 @@ func probeVulkanDevices() []VulkanDeviceProbe { } out = append(out, probe) } - return out + return out, nil +} + +func vulkanResultError(call string, result int32) error { + if result == vkErrorIncompatibleDriver { + return fmt.Errorf("%s: VK_ERROR_INCOMPATIBLE_DRIVER (%d)", call, result) + } + return fmt.Errorf("%s: VkResult %d", call, result) } func probeVulkanDeviceExtensions(pEnumExts *syscall.LazyProc, pd uintptr) map[string]bool { diff --git a/internal/i18n/catalog_gen.go b/internal/i18n/catalog_gen.go index 61dcba3..9c9ce59 100644 --- a/internal/i18n/catalog_gen.go +++ b/internal/i18n/catalog_gen.go @@ -90,6 +90,7 @@ var catalog = map[Locale]map[string]string{ "doctor.gpu.err.vulkan_cpu": "软件渲染 Vulkan 实现不满足 vGPU 硬件加速要求,请改用 VMware SVGA", "doctor.gpu.err.vulkan_too_old": "Vulkan 版本 {ver} 低于 1.3 最低要求,请更新显卡驱动或改用 VMware SVGA", "doctor.gpu.none": "未检测到已注册的 Vulkan ICD 显卡驱动", + "doctor.gpu.probe_failed": "Vulkan 探测失败({detail})。请运行 vulkaninfo --summary 检查驱动。", "doctor.gpu.recommended": "推荐", "doctor.gpu.warn.amd_legacy": "AMD Vega/Polaris 在 Windows 闭源驱动下存在上游已知黑屏/设备丢失问题({ref}),建议使用其他独显或在虚拟机设置改用 VMware SVGA", "doctor.gpu.warn.amd_rdna2": "该 AMD 显卡在 Windows 下存在上游已知设备丢失风险({ref}),若黑屏/卡死请升级驱动或临时改用 VMware SVGA", @@ -624,6 +625,7 @@ var catalog = map[Locale]map[string]string{ "doctor.gpu.err.vulkan_cpu": "Software Vulkan implementation does not meet the vGPU floor; use VMware SVGA instead", "doctor.gpu.err.vulkan_too_old": "Vulkan {ver} is below the required 1.3 floor; update your GPU driver or use VMware SVGA", "doctor.gpu.none": "No registered Vulkan ICD driver found", + "doctor.gpu.probe_failed": "Vulkan probe failed ({detail}). Run vulkaninfo --summary to check the driver.", "doctor.gpu.recommended": "Recommended", "doctor.gpu.warn.amd_legacy": "AMD Vega/Polaris on Windows hits known upstream black-screen/device-loss issues ({ref}); prefer another discrete GPU or switch the VM to VMware SVGA", "doctor.gpu.warn.amd_rdna2": "This AMD GPU hits known Windows device-loss issues upstream ({ref}); update drivers or switch temporarily to VMware SVGA if it freezes", @@ -1099,6 +1101,7 @@ var paramOrder = map[string][]string{ "doctor.ecores.detail": {"count", "cpus"}, "doctor.gpu.err.missing_ext": {"ext"}, "doctor.gpu.err.vulkan_too_old": {"ver"}, + "doctor.gpu.probe_failed": {"detail"}, "doctor.gpu.warn.amd_legacy": {"ref"}, "doctor.gpu.warn.amd_rdna2": {"ref"}, "doctor.pcores.detail": {"count", "mask", "cpus"}, diff --git a/locales/en-US/native.json b/locales/en-US/native.json index 0fdcee5..bffddc7 100644 --- a/locales/en-US/native.json +++ b/locales/en-US/native.json @@ -1,4 +1,5 @@ { + "doctor.gpu.probe_failed": "Vulkan probe failed ({detail}). Run vulkaninfo --summary to check the driver.", "doctor.title": "Reims-Go Host Environment Check", "doctor.os": "Operating System", "doctor.cpu": "CPU & Core Topology", diff --git a/locales/en-US/wizard.json b/locales/en-US/wizard.json index 6f0f83c..4491ef1 100644 --- a/locales/en-US/wizard.json +++ b/locales/en-US/wizard.json @@ -1,4 +1,5 @@ { + "vulkanProbeFailed": "Vulkan probe failed ({detail}). Run vulkaninfo --summary to check the driver.", "setupTitle": "Choose a data folder", "setupDesc": "VMs, installers and runtimes all live here", "setupOther": "Other location…", diff --git a/locales/zh-CN/native.json b/locales/zh-CN/native.json index 91ce361..06c638b 100644 --- a/locales/zh-CN/native.json +++ b/locales/zh-CN/native.json @@ -1,4 +1,5 @@ { + "doctor.gpu.probe_failed": "Vulkan 探测失败({detail})。请运行 vulkaninfo --summary 检查驱动。", "doctor.title": "Reims-Go 宿主机环境体检", "doctor.os": "操作系统", "doctor.cpu": "处理器与核心拓扑", diff --git a/locales/zh-CN/wizard.json b/locales/zh-CN/wizard.json index 93fca8c..56708ca 100644 --- a/locales/zh-CN/wizard.json +++ b/locales/zh-CN/wizard.json @@ -1,4 +1,5 @@ { + "vulkanProbeFailed": "Vulkan 探测失败({detail})。请运行 vulkaninfo --summary 检查驱动。", "setupTitle": "选择数据目录", "setupDesc": "虚拟机、安装包和运行时都放在这里", "setupOther": "其他位置…",