前言
之前在玩《碧藍幻想 Relink》的時候,一直想找個方法能一邊掛機刷素材、一邊正常用電腦進行日常辦公、開發工作,後來想到了可以用虛擬機來避免前台搶佔。
然而,在嘗試過程中遇到了幾個問題:
- 不想為了掛機去開其他台電腦
- 一般的虛擬機(如 VMware, VirtualBox)的虛擬顯卡效能極其有限,無法應付大部分現代 3D 遊戲的圖形運算需求,容易導致掉幀或崩潰。
- 雖然 Linux 系統下的 KVM 擁有成熟的 GPU Passthrough 技術,但因各種需求的關係,暫時沒有更換為 Linux 系統的打算。
後來想到了 Windows 內建的 Hyper-V,發現透過 GPU Passthrough 可以讓虛擬機直接調用實體顯卡,所以就有了這篇筆記。
好處在哪
- Windows 內建,無需額外安裝第三方軟體。
- 與傳統虛擬化不同,GPU-P 允許虛擬機直接調用實體顯卡的硬體資源。
- 主機與虛擬機能同時共享同一張顯卡,不像 DDA 那樣必須將整張顯卡獨佔給虛擬機。
這樣也能多開遊戲了,我相信4090一定扛的住(?
Hyper-V
Windows Pro 版才有…沒人在管。
[Run as AD] Installation.cmd
1 2 3 4 5pushd "%~dp0" dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i" del hyper-v.txt Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL[Run as AD] Uninstall.cmd
1Dism /online /disable-feature /featurename:Microsoft-Hyper-V-All /Remove
OS選擇
基本上裝較輕量的 Windows 10 LTSC 就行了
當然你要用來裝其他系統也行
GPU Passthrough
先在 Hyper-V 管理員中關閉 VM 的 啟用檢查點 設定

用系統管理員權限開啟 PowerShell
跑Get-VMHostPartitionableGpu會看到ValidPartitionCountsPartitionCountTotalVRAMAvailableVRAMMinPartitionVRAMMaxPartitionVRAMOptimalPartitionVRAMTotalEncodeAvailableEncodeMinPartitionEncodeMaxPartitionEncodeOptimalPartitionEncodeTotalDecodeAvailableDecodeMinPartitionDecodeMaxPartitionDecodeOptimalPartitionDecodeTotalComputeAvailableComputeMinPartitionComputeMaxPartitionComputeOptimalPartitionCompute
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22ValidPartitionCounts : {32} PartitionCount : 32 TotalVRAM : 1000000000 AvailableVRAM : 1000000000 MinPartitionVRAM : 0 MaxPartitionVRAM : 1000000000 OptimalPartitionVRAM : 1000000000 TotalEncode : 18446744073709551615 AvailableEncode : 18446744073709551615 MinPartitionEncode : 0 MaxPartitionEncode : 18446744073709551615 OptimalPartitionEncode : 18446744073709551615 TotalDecode : 1000000000 AvailableDecode : 1000000000 MinPartitionDecode : 0 MaxPartitionDecode : 1000000000 OptimalPartitionDecode : 1000000000 TotalCompute : 1000000000 AvailableCompute : 1000000000 MinPartitionCompute : 0 MaxPartitionCompute : 1000000000 OptimalPartitionCompute : 1000000000改腳本並執行 (PowerShell)
- 把腳本中
$vm改成你虛擬機的名稱 - 把腳本中
Max*改成上一步結果中的Max*
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19$vm = "Win10LTSC" Add-VMGpuPartitionAdapter -VMName $vm Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionVRAM 1 Set-VMGpuPartitionAdapter -VMName $vm -MaxPartitionVRAM 1000000000 Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionVRAM 1000000000 Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionEncode 1 Set-VMGpuPartitionAdapter -VMName $vm -MaxPartitionEncode 18446744073709551615 Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionEncode 18446744073709551615 Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionDecode 1 Set-VMGpuPartitionAdapter -VMName $vm -MaxPartitionDecode 1000000000 Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionDecode 1000000000 Set-VMGpuPartitionAdapter -VMName $vm -MinPartitionCompute 1 Set-VMGpuPartitionAdapter -VMName $vm -MaxPartitionCompute 1000000000 Set-VMGpuPartitionAdapter -VMName $vm -OptimalPartitionCompute 1000000000 Set-VM -GuestControlledCacheTypes $true -VMName $vm Set-VM -LowMemoryMappedIoSpace 1Gb -VMName $vm Set-VM -HighMemoryMappedIoSpace 32GB –VMName $vm- 把腳本中
然後「安裝」顯卡驅動 (以 Nvidia 舉例)
把
C:\Windows\System32\DriverStore\FileRepository\底下的 NV 顯卡驅動拉到 VM 的C:\Windows\System32\HostDriverStore\FileRepository\(沒有自己建)把
C:\Windows\System32\nvapi64.dll拉到 VM 的相同位置關於顯卡驅動:
- 在裝置管理員裡面找你 GPU 的驅動流水號,複製那個資料夾就好
- ex.
C:\Windows\System32\DriverStore\FileRepository\nvami.inf_amd64_<流水號之類的英數組合>
重開機,打開 dxdiag 檢查是否無誤
高幀數串流
這邊你有兩種選擇:
- Parsec 能搞定一切,懶人首選
- 裝 Virtual Display Driver + VB Cable,再用 Sunshine + Moonlight 串流
Virtual Display Driver
ge9/IddSampleDriver : Github
步驟:系統管理員跑 .bat > 裝置管理員 > [本機] 掃描軟體變更 > 動作 > 新增傳統硬體 > [手動選擇 .inf 檔安裝]
VB Cable
VB Cable : vb-audio.com
Sunshine / Moonlight
連線端裝 Moonlight,被連線端裝 Sunshine
moonlight-stream/moonlight-qt : Github
LizardByte/Sunshine : Github
我絕對不會說什麼有些遊戲可以在 Hyper-V 的 VM 裡面開 Hyper-V 來繞過反作弊什麼的
