GPU Passthrough QEMU/KVM, still use Spice to view guest

Goal: To be able to use GPU passthrough in Guest NixosVM.

Setup: I have a host NixOS install and I am using qemu/kvm via virt-manager to setup/manage my virtual machines. In the host system, I have two video cards one AMD and one NVIDIA.

I have my monitor hooked up to the AMD which is less powerful and I want to passthrough the NVIDIA to use inside of my guest VM, which will also be NixOS.

I’ve found a few tutorials, but some of them are multiple years old, focus on Windows Guest, or want to do more complex things like setup looking-glass.

I’ve tried a few different things after adding the PCI device to my vm’s config - sometimes it halts the whole system and I just get some type of log/dump - I assume that in this case it is actually outputting the video to the NVIDIA card, but if I connect the monitor on the NVIDIA I don’t see anything. Other times, it boots like it normally does using virt-manager, but then the screen goes black.

I’m also now wondering if I even need to do this, I found on the Arch Wiki about " Virgil3d virtio-gpu paravirtualized device driver". I did not fully understand this, but does this mean I actually don’t need two video cards and can just virtualize the video card from the host as long as I am using a Linux guest vm? If so, anything special for NixOS?

To clarify: My goal is to use the GPU in the VM to assist processing for video editing and converting, rendering, etc.

  • I am not overly concerned about real-time seeing it on my monitor.
  • I don’t want to use a second monitor or second set of mouse/keyboard
  • I want to easily be able to switch between VMs. Besides this main VM, I will be using virt-manager to manage other VMs with GUIs I will be using for other purposes and those will not need any type of GPU for the most part.
  • It sounds like looking-glass would somewhat be similar to using normal spice inside of virt-manager, but I want to keep it simple with a minimum number of tools for my purpose - doing everything through virt-manager seems to be simple and predictable

I did some more research after this post, looking for some clarification. In virt-manager, if I select video → “virtio” and have setup my GPU with all the kernel params, is that essentially accomplishing the same goal? e.g., if I look at hardware on the guest I will see the virtio video driver listed.

This is still a virtualized device, so I get all the processing power, but maybe lose some NVIDIA specific things?

How can I tell if I have this setup correctly, If i select “virtio” and I don’t have the GPUs bound correctly, would it still work?