Skip to content

Instantly share code, notes, and snippets.

@Ethorbit
Last active April 22, 2024 20:53
Show Gist options
  • Save Ethorbit/ee85c10d0ce73b4827cba8ebaf7bbc0c to your computer and use it in GitHub Desktop.
Save Ethorbit/ee85c10d0ce73b4827cba8ebaf7bbc0c to your computer and use it in GitHub Desktop.
Hyper-V tutorial to partition GPU for virtualization + achieve full GPU acceleration with it and daily drive it.
Windows VM

Using GPU-PV, you can create a partition of your GPU and assign it to a Windows virtual machine

Make sure your GPU is visible.

  • Go to Device Manager
  • Expand Display Adapters
  • Your GPU model should be listed.

Immediately you want to enforce a 60fps cap on the virtual machine so that it doesn't use 100% of the GPU when it's not supposed to.

Great, but you're connecting via RDP which is limited.

Great, but UAC prompts will cause Moonlight to go unresponsive for about 5 seconds which can make changing Windows settings really annoying.

  • Go to Change User Account Control settings
  • Slide setting down to either one or two notches
  • Click OK

So at this point, graphical acceleration is only partially available and really buggy. You need a virtual display driver that supports 1920x1080@60hz and one that is compatible with the virtual machine. usbmmidd will work.

Let's say it's stored in C:\Users\MyUser\usbmmidd

  • Open Powershell or CMD as Administrator
  • Enter command: cd C:\Users\MyUser\usbmmidd
  • Enter command: deviceinstaller64 install usbmmidd.inf usbmmidd
  • Close the Powershell or CMD window
  • Create file (Make sure file extension visibility is on) C:\Users\MyUser\usbmmidd\start.ps1
  • Edit C:\Users\MyUser\usbmmidd\start.ps1 and save its contents as:
C:\Users\MyUser\usbmmidd\deviceinstaller64 enableidd 1
  • Open Task Scheduler
  • Create Task, click General tab
  • Set a name
  • Set to Run whether user is logged on or not
  • Check Run with highest privileges
  • Click Triggers tab
  • Click New
  • Set Begin the task: to At startup
  • Click Actions tab
  • Click New
  • Set Program / script to powershell.exe
  • Set Add arguments to -NoExit -ExecutionPolicy Bypass C:\Users\MyUser\usbmmidd\start.ps1
  • Click Conditions tab
  • Uncheck all
  • Click OK
  • Reboot virtual machine

Now to confirm everything is working

  • Connect with Moonlight (It will fail to connect a few times, just keep trying)
  • Go to Display Settings
  • Choose the monitor that lets you control resolution
  • Set the monitor's resolution to 1920x1080
  • Show only on that monitor
  • Press Ctrl + Shift + Alt + S for statistics overlay toggle
  • Watch a 1920x1080@60hz YouTube video and see if you are getting a constant 60 FPS. If you are, CONGRATS! 🎉 you're fully utilizing the graphical acceleration of a PARTITIONED GPU! 🎉

Since you won't be able to connect using Hyper-V anymore, you probably want to create snapshots of the disk to make recovery quick and easy in case you get locked out of Moonlight

  • Go into Hyper-V Manager
  • Right-click virtual machine
  • Settings
  • Checkpoints
  • Set to Production
  • Uncheck Create standard checkpoints if the guest does not support creation of production checkpoints (since you cannot create a Standard checkpoint on a virtual machine that has GPU partitions)
  • Click OK
  • Right-click virtual machine
  • Click Checkpoint

It should say Checkpoint successfully created; now you can restore from a checkpoint if you get locked out 👍

WSL2 Linux Using WSL2, you can share the host GPU with Linux and then Linux can create multiple Docker desktop containers with it.

This part is currently unfinished as experimentation continues. So far I know that it IS possible.

You can use both methods to run both Windows AND Linux (with graphics acceleration) at the same time with a SINGLE GPU to show everyone how cool you are!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment