VirGL hardware accelerated h264/h265

search the forums.

I did these but it did not help.
 
Please, anyone following these steps, don't do this on a production machine and as mentioned, to maintain this, you have to reinstall your custom qemu every time proxmox updates.


I did post this in bugzilla as you requested.

I'm not very good at formatting things, but I have typed up the notes in textedit.

add the following to /etc/apt/sources.list

I use nano:

nano -w /etc/apt/sources.list

paste in

#deb http://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware
deb-src http://ftp.us.debian.org/debian bookworm main contrib non-free non-free-firmware

keep the bookworm-backports commented out while you setup the build evironment for qemu because you don't want to get in a dependency loop with held back packages, etc.
after building, you can enable the bookworm-backports repo.
This will also update several installed packages.


When you're done with the build - you will want to update the mesa-va-drivers



apt update

apt build-dep qemu virglrenderer

apt install git build-essential

#### install the remaining packages needed for qemu build

apt install libacl1-dev libattr1-dev libglusterfs-dev libpci-dev libproxmox-backup-qemu0-dev libsdl1.2-dev libsystemd-dev python3-venv quilt xfslibs-dev lintian

cd /usr/src

git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git

cd virglrenderer

meson build -Dvenus=true -Dvideo=True -Dprefix=/usr

If you have an amd gpu, you can add -Ddrm-renderers=amdgpu-experimental to the end of the meson build line

cd build

ninja install


Now you need to get the proxmox qemu source

cd /usr/src

git clone https://github.com/proxmox/pve-qemu

cd pve-qemu

git submodule update --init --recursive

cd qemu

meson subprojects download
###########################################


Patch the source from inside the pve-qemu/qemu directory

Patch file can be found here:

https://raw.githubusercontent.com/m...471b5bcab41842a5fe6ea9b05a09cb78f/virgl.patch

or copy/paste the code from @two56bytes post

Just wget it to the qemu directory.

root@enyo:/usr/src/pve-qemu/qemu# patch < virgl.patch
can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
|index 145a0b3879..2fee481219 100644
|--- a/hw/display/virtio-gpu-virgl.c
|+++ b/hw/display/virtio-gpu-virgl.c
--------------------------
File to patch: hw/display/virtio-gpu-virgl.c #type this in the prompt
patching file hw/display/virtio-gpu-virgl.c
patching file meson.build
root@enyo:/usr/src/pve-qemu/qemu#

Now you will cd .. and run make deb

cd ..
make deb

dpkg -i pve-qemu-kvm_9.2.0-3_amd64.deb
note: your file name may be newer than the one above.

update the mesa, libdrm2, etc installs
apt upgrade -t bookworm-backports
Are these done on the guest or host? Is this still the best way to do this? I don't understand why they can't just offer these codecs for a few dollars. I would gladly pay it.
 
codecs are already licensed since they're in your GPU. This discussion is about using the hardware capabilities of the gpus in vms.
 
hey folks its me again,

here i am using the most recent version of virglrenderer so the sources can be build from pve-qemu master branch,
enjoy!

1. update to proxmox 6.11 (not necessary)

apt update
apt install proxmox-kernel-6.11
reboot

2. install amdgpu for ubuntu noble (not necessary)

wget https://repo.radeon.com/amdgpu-install/6.3.4/ubuntu/noble/amdgpu-install_6.3.60304-1_all.deb
sudo apt install ./amdgpu-install_6.3.60304-1_all.deb
amdgpu-install -y --usecase=workstation,rocm
reboot

check if it is loaded

dkms status

3. Install mesa 24 (might be necessary)

Add bookworm-backports to /etc/apt/sources.list:
echo -n "deb http://deb.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware" >> /etc/apt/sources.list

then

apt update
apt install -t bookworm-backports mesa-va-drivers


4. build virglrenderer

Code:
git clone https://gitlab.freedesktop.org/virgl/virglrenderer.git
cd virglrenderer
meson build -Dvenus=true -Dvideo=True -Dprefix=/usr
cd build
ninja install

check if it is loaded

ldd /bin/qemu-system-x86_64 | grep virgl
ls -lahrt /usr/lib/x86_64-linux-gnu/libvirglrenderer.so.1

5. build pve-qemu
git clone https://github.com/proxmox/pve-qemu
cd pve-qemu
git submodule update --init --recursive
cd qemu
meson subprojects download

6. patch

place virgl.patch into the qemu dir and patch file with

patch < virgl.patch

virgl.patch:
Code:
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 145a0b3879..2fee481219 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "qemu/iov.h"
+#include "qemu/drm.h"
 #include "trace.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-gpu.h"
@@ -1030,12 +1031,23 @@ static int virgl_make_context_current(void *opaque, int scanout_idx,
                                    qctx);
 }
 
+static int virgl_get_drm_fd(void *opaque)
+{
+    int fd = -1;
+
+    fd = qemu_drm_rendernode_open(NULL);
+
+    return fd;
+}
+
+
 static struct virgl_renderer_callbacks virtio_gpu_3d_cbs = {
     .version             = 1,
     .write_fence         = virgl_write_fence,
     .create_gl_context   = virgl_create_context,
     .destroy_gl_context  = virgl_destroy_context,
     .make_current        = virgl_make_context_current,
+    .get_drm_fd          = virgl_get_drm_fd,
 };
 
 static void virtio_gpu_print_stats(void *opaque)
@@ -1094,7 +1106,7 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g)
 int virtio_gpu_virgl_init(VirtIOGPU *g)
 {
     int ret;
-    uint32_t flags = 0;
+    uint32_t flags = VIRGL_RENDERER_USE_VIDEO;
     VirtIOGPUGL *gl = VIRTIO_GPU_GL(g);
 
 #if VIRGL_RENDERER_CALLBACKS_VERSION >= 4
diff --git a/meson.build b/meson.build
index 147097c652..707efc3861 100644
--- a/meson.build
+++ b/meson.build
@@ -1350,6 +1350,13 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
                      method: 'pkg-config',
                      required: get_option('virglrenderer'))
 endif
+
+if virgl.version().version_compare('>= 1.0.0')
+  message('Enabling virglrenderer unstable APIs')
+  virgl = declare_dependency(compile_args: '-DVIRGL_RENDERER_UNSTABLE_APIS -DVIRGL_RENDERER_VENUS',
+                            dependencies: virgl)
+endif
+
 rutabaga = not_found
 if not get_option('rutabaga_gfx').auto() or have_system or have_vhost_user_gpu
   rutabaga = dependency('rutabaga_gfx_ffi',

4. build & install & restart​



Code:
cd ..
make deb
dpkg -i pve-qemu-kvm_9.2.0-2_amd64.deb

reboot guest
Using these steps I was able to build qemu 10. Even though I have accelerated graphics in wayland on my VM i don't have access to the hardware codecs
PS. I'm using debian13 as the guest on a pve9 host and an amd ryzen apu.
PPS. I was able to get it working. Previously i intentionally left one step out - updating virglrenderer. Now I've updated that too and i succeeded!.
The reason I didn't want to build it manually was so that I can go back to the "upstream packages" at some point. Here's what I did:
I got the debian virglrenderer package source code from https://salsa.debian.org/debian/virglrenderer, compared with https://gitlab.freedesktop.org/virgl/virglrenderer.
It looked to me that only the debian dir was addoed so i copied that over.

Then i rebuilt the package - using the latest main.
Code:
mk-build-deps --install --tool "apt-get --yes --no-install-recommends"; dpkg-buildpackage -uc -us -tc -b
These scripts look at the changelog in the debian dir to populate the version.
I installed the packages and then recompiled the pve-qemu package as per previous instructions.

PPPS. seems that the VAProfiles also work on buster, not only trixie.

Code:
vainfo
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.17.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/virtio_gpu_drv_video.so
libva info: Found init function __vaDriverInit_1_17
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.17 (libva 2.12.0)
vainfo: Driver version: Mesa Gallium driver 22.3.6 for virgl (AMD Radeon Graphics (radeonsi, renoir, ACO, DRM 3.57...)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
 
Last edited:
Using these steps I was able to build qemu 10. Even though I have accelerated graphics in wayland on my VM i don't have access to the hardware codecs
PS. I'm using debian13 as the guest on a pve9 host and an amd ryzen apu.
PPS. I was able to get it working. Previously i intentionally left one step out - updating virglrenderer. Now I've updated that too and i succeeded!.
The reason I didn't want to build it manually was so that I can go back to the "upstream packages" at some point. Here's what I did:
I got the debian virglrenderer package source code from https://salsa.debian.org/debian/virglrenderer, compared with https://gitlab.freedesktop.org/virgl/virglrenderer.
It looked to me that only the debian dir was addoed so i copied that over.

Then i rebuilt the package - using the latest main.
Code:
mk-build-deps --install --tool "apt-get --yes --no-install-recommends"; dpkg-buildpackage -uc -us -tc -b
These scripts look at the changelog in the debian dir to populate the version.
I installed the packages and then recompiled the pve-qemu package as per previous instructions.

PPPS. seems that the VAProfiles also work on buster, not only trixie.

Code:
vainfo
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: can't connect to X server!
libva info: VA-API version 1.17.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/virtio_gpu_drv_video.so
libva info: Found init function __vaDriverInit_1_17
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.17 (libva 2.12.0)
vainfo: Driver version: Mesa Gallium driver 22.3.6 for virgl (AMD Radeon Graphics (radeonsi, renoir, ACO, DRM 3.57...)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
But if i install virglrenderer though apt, i won't get those codecs, even if i am on PVE9 and Debian 13, am i right? I only have a AMD S7150x2, I don't have AMD Ryzen CPU and I don't want to spend extra money in short term.
If I am right, i am going to issue a bug to Debian community, do you know where should I raise the bug? Debian forum or Gitlab?
 
But if i install virglrenderer though apt, i won't get those codecs, even if i am on PVE9 and Debian 13, am i right? I only have a AMD S7150x2, I don't have AMD Ryzen CPU and I don't want to spend extra money in short term.
If I am right, i am going to issue a bug to Debian community, do you know where should I raise the bug? Debian forum or Gitlab?
I think that the Debian package maintainer needs to pull in the latest release. This being said there isn't a new release of virglrenderer either. It seems that a new release of virgilrenderer was cut yesterday - https://gitlab.freedesktop.org/virgl/virglrenderer/-/releases

I would wait and see if this versions make it into unstable, then forky and then perhaps trixie-backports.

What's the line you're drawing in the sand tho? There's still a patch needed for QEMU, so you still need to compile thingies.

LE. I think all intel and amd gpus can do this right now, not sure about nvidia.
For certain intel integrated gpus you can even enable sr-iov so there's that.

here is the debian packagepage https://tracker.debian.org/pkg/virglrenderer
 
Last edited:
I think that the Debian package maintainer needs to pull in the latest release. This being said there isn't a new release of virglrenderer either. It seems that a new release of virgilrenderer was cut yesterday - https://gitlab.freedesktop.org/virgl/virglrenderer/-/releases

I would wait and see if this versions make it into unstable, then forky and then perhaps trixie-backports.

What's the line you're drawing in the sand tho? There's still a patch needed for QEMU, so you still need to compile thingies.

LE. I think all intel and amd gpus can do this right now, not sure about nvidia.
For certain intel integrated gpus you can even enable sr-iov so there's that.
From i understand, you are using latest virglrender from Freedesktop (instead of Debian) + Debian directory. Right? Did you make any other change?

Also, since which version of virglrender start to include those codecs?

By the way, what patch do I need for QEMU? Was that a patch included in QEMU but not compiled by Proxmox or?
 
I think that the Debian package maintainer needs to pull in the latest release. This being said there isn't a new release of virglrenderer either. It seems that a new release of virgilrenderer was cut yesterday - https://gitlab.freedesktop.org/virgl/virglrenderer/-/releases

I would wait and see if this versions make it into unstable, then forky and then perhaps trixie-backports.

What's the line you're drawing in the sand tho? There's still a patch needed for QEMU, so you still need to compile thingies.

LE. I think all intel and amd gpus can do this right now, not sure about nvidia.
For certain intel integrated gpus you can even enable sr-iov so there's that.
What is your VM config?
 
if you look at what wo56bytes wrote you'll see that after installing the latest version of virglrenderer you need to patch - step 6 of compiling qemu.
Here's my trixie vm - i think it's pretty standard. I am passing through the nic - as i'm using sr-iov for it.
Code:
/etc/pve/qemu-server# cat 120.conf
agent: 1
audio0: device=ich9-intel-hda,driver=spice
bios: ovmf
boot: order=scsi0;ide2
cores: 4
cpu: host
efidisk0: local-lvm:vm-120-disk-0,efitype=4m,pre-enrolled-keys=1,size=4M
hostpci0: 0000:07:11.0
ide2: local:iso/systemrescue-12.01-amd64.iso,media=cdrom,size=1066560K
machine: q35
memory: 8192
meta: creation-qemu=10.0.2,ctime=
name: debian13-desktop
numa: 0
ostype: l26
scsi0: local-lvm:vm-120-disk-1,discard=on,iothread=1,size=64G,ssd=1
scsihw: virtio-scsi-single
smbios1: uuid=
sockets: 1
tpmstate0: local-lvm:vm-120-disk-2,size=4M,version=v2.0
vga: virtio-gl,memory=512
vmgenid:
 
Last edited: