mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 15:18:40 +01:00
On a host whose GPU can encode H.264 (a Windows driver through d3d12 on WSL 2 does), KRDP in
the demo guest encoded on the guest's CPUs. The host side was fine (vainfo on the host lists
H.264 and HEVC EncSlice), and virgl can pass a guest's VA-API video to it, but a chain of seven
problems stood between the two. Each is a patch, and the guest takes them all:
QEMU (nix/dev/qemu-virgl-video.patch)
QEMU never asks virglrenderer for video: virglrenderer turns it on only for an embedder that
passes VIRGL_RENDERER_USE_VIDEO and a get_drm_fd callback to open the host's video device on.
The flag is defined only with VIRGL_RENDERER_UNSTABLE_APIS, which the build sets.
virglrenderer 1.3.0, four patches in this order
virglrenderer-chroma-format.patch
the guest's Mesa and virglrenderer number the chroma format of a codec differently: 4:2:0
was read as 4:2:2, and the host's encoder refused every codec it was asked for
virglrenderer-video-memory-upload.patch
the d3d12 driver has no dma-bufs: vaExportSurfaceHandle fails, nothing was uploaded and
the encoder returned an empty bitstream. The planes of the guest's picture are read back
(glReadPixels) and written to the surface through a derived image (vaDeriveImage, with
vaCreateImage and vaPutImage as a fallback)
virglrenderer-h264-packed-sps.patch
Mesa's VA-API takes the level of the stream from a packed SPS, which virglrenderer never
sent: level 0 reached UNREACHABLE in the d3d12 encoder and crashed QEMU
virglrenderer-ubo0-constants.patch
a constant buffer 0 bound as a buffer was never read by the shader, so the colour matrix
of an RGB to YUV conversion was zero and the picture was a solid green
Mesa 26.2.5 in the guest, two patches (hardware.graphics.package)
mesa-virgl-rgb-yuv-csc.patch
the graphics compositor never loaded an RGB to YUV matrix, and multiplied by the YUV to
RGB one of its initial state
mesa-virgl-fence-leak.patch
a surface kept the out-fence (a sync_file) of its last flush and the next flush stored a
new one over it: one file descriptor leaked per converted frame, 44 a second under motion,
and KRDP froze when it reached the limit of 1024, about 28 seconds in
KRDP (krdp.nix) asks for H264Baseline and the guest's driver lists Main and High, so ffmpeg's
h264_vaapi found no profile it could use: it is built with H264Main.
What was checked: a luma ramp and a colour-bar pattern encoded through the guest to the 4090
decode to the right values; the real desktop shows over RDP in Windows' own client with the
right colours; under es2gears motion the descriptors of krdpserver stay flat (3 sync_file, 78
of 1024) where they were 949 of 1024 after 28 seconds.
run-kde sets what the host needs for Mesa and for virglrenderer's libva to find the Windows
driver, on WSL 2 with the GPU on and unless it is set already: GALLIUM_DRIVER=d3d12,
LD_LIBRARY_PATH with /usr/lib/wsl/lib first, LIBVA_DRIVER_NAME=d3d12 and LIBVA_DRIVERS_PATH
(/run/opengl-driver/lib/dri, for the d3d12 video driver, which it looks for). --doctor checks
for the libraries and for that driver, and the tests have a scenario for each.
Known: the software decoder warns "illegal short term buffer state detected" on the stream; the
d3d12 encoder writes Constrained Baseline whatever profile is asked for. There is no binary
cache: the first run builds QEMU and Mesa, which takes about 20 minutes. QEMU, virglrenderer and
Mesa are the runner's and the guest's only, and the VM suites build the Mesa as well.
Not measured yet: whether it is smoother than the CPU encoder under the same load.
114 lines
5.8 KiB
Nix
114 lines
5.8 KiB
Nix
# What `run-kde` says and starts, for machines that a test makes up from the variables the script
|
|
# reads (RUN_KDE_*, WAYLAND_DISPLAY, DISPLAY): a WSL 2 with WSLg and a GPU, one with WSLg and a
|
|
# software OpenGL or none, a Linux machine with no window, and machines that cannot run the guest.
|
|
# `--dry-run` prints what the script would start, which is the environment and the arguments the
|
|
# runner is given; `--doctor` prints what the machine lacks and how to fix it, and starts the
|
|
# virtiofsd of nixpkgs for real, as the sandbox's user, to see that it serves a directory. The
|
|
# sandbox has no KVM, no GPU and no WSL, which is the point: the script's answer does not depend on
|
|
# the machine it is run on. The expected texts are in `run-kde/`.
|
|
{ pkgs, runKde }:
|
|
let
|
|
exe = pkgs.lib.getExe runKde;
|
|
|
|
# The files that stand for a machine, and a command that runs the script in an environment of its
|
|
# own, with the variables that follow it. @T@ is where the files are, which the expected texts do
|
|
# not keep.
|
|
setup = ''
|
|
t=$PWD/machine
|
|
mkdir -p $t/bin $t/repo $t/dri $t/wsl-lib $t/va
|
|
touch $t/repo/flake.nix $t/kvm $t/kvm-denied $t/fuse $t/dxg $t/va/d3d12_drv_video.so
|
|
chmod 000 $t/kvm-denied
|
|
printf '#!/bin/sh\n' > $t/bin/nix
|
|
printf '#!/bin/sh\necho "[ERROR virtiofsd] Error creating the vhost-user socket: Address in use (os error 98)" >&2\nexit 1\n' > $t/bin/virtiofsd-broken
|
|
chmod +x $t/bin/nix $t/bin/virtiofsd-broken
|
|
printf 'MemTotal: 16777216 kB\n' > $t/meminfo
|
|
printf 'MemTotal: 6291456 kB\n' > $t/meminfo-small
|
|
printf '5.15.167.4-microsoft-standard-WSL2\n' > $t/osrelease-wsl
|
|
printf '6.18.0\n' > $t/osrelease-linux
|
|
printf 'flags : fpu vme svm sse\n' > $t/cpuinfo-svm
|
|
printf 'flags : fpu vme sse\n' > $t/cpuinfo-none
|
|
|
|
machine() {
|
|
env -i PATH=$t/bin:$PATH HOME=/home/user XDG_STATE_HOME=/state \
|
|
KOMOREBI_REPO=$t/repo RUN_KDE_GUEST=run-kde-x86_64 \
|
|
RUN_KDE_RUNNER_BIN=/nix/store/fake-nixos-vm/bin/run-komorebi-demo-vm \
|
|
RUN_KDE_CPUINFO=$t/cpuinfo-svm RUN_KDE_STORE_DIR=$t RUN_KDE_FREE_GB=100 \
|
|
RUN_KDE_DRI_DIR=$t/dri RUN_KDE_CPUS=12 RUN_KDE_FUSE_DEVICE=$t/fuse \
|
|
RUN_KDE_WSL_LIB_DIR=$t/wsl-lib RUN_KDE_VA_DRIVERS_DIR=$t/va \
|
|
"$@"
|
|
}
|
|
plain() { sed "s|$t|@T@|g"; }
|
|
'';
|
|
|
|
# a WSL 2 with WSLg, 16 GB of memory and KVM; and a Linux machine with none of WSL
|
|
wslg = "WAYLAND_DISPLAY=wayland-0 DISPLAY=:0 RUN_KDE_OSRELEASE=$t/osrelease-wsl RUN_KDE_KVM_DEVICE=$t/kvm RUN_KDE_MEMINFO=$t/meminfo";
|
|
linux = "RUN_KDE_OSRELEASE=$t/osrelease-linux RUN_KDE_KVM_DEVICE=$t/kvm RUN_KDE_MEMINFO=$t/meminfo RUN_KDE_HOST_RENDERER=";
|
|
|
|
# runs `command`, which has to exit with `status` and print what `run-kde/NAME.expected` has
|
|
scenario = name: status: command: ''
|
|
echo "== ${name}"
|
|
set +e
|
|
${command} > ${name}.raw 2>&1
|
|
got=$?
|
|
set -e
|
|
plain < ${name}.raw > ${name}.out
|
|
if [ "$got" != ${toString status} ]; then
|
|
echo "${name}: the exit status is $got, not ${toString status}"
|
|
cat ${name}.out
|
|
exit 1
|
|
fi
|
|
diff -u ${./run-kde + "/${name}.expected"} ${name}.out
|
|
'';
|
|
|
|
check =
|
|
name: scenarios:
|
|
pkgs.runCommand name { nativeBuildInputs = [ pkgs.diffutils ]; } ''
|
|
${setup}
|
|
${builtins.concatStringsSep "\n" scenarios}
|
|
touch $out
|
|
'';
|
|
in
|
|
{
|
|
run-kde-dry-run = check "run-kde-dry-run" [
|
|
(scenario "dry-run-wslg-gpu" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=D3D12 (AMD Radeon RX 7800 XT)" ${exe} --dry-run''
|
|
)
|
|
# without the d3d12 video driver the host's GPU still renders, and nothing says libva which driver
|
|
(scenario "dry-run-wslg-gpu-no-video-driver" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=D3D12 (AMD Radeon RX 7800 XT)" RUN_KDE_VA_DRIVERS_DIR=$t/absent ${exe} --dry-run''
|
|
)
|
|
# what a person has set is kept, and the directory of Windows' libraries comes first
|
|
(scenario "dry-run-wslg-gpu-own-env" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=D3D12 (AMD Radeon RX 7800 XT)" GALLIUM_DRIVER=zink LD_LIBRARY_PATH=/opt/lib LIBVA_DRIVER_NAME=radeonsi ${exe} --dry-run''
|
|
)
|
|
(scenario "dry-run-wslg-no-gpu" 0
|
|
"machine ${wslg} RUN_KDE_DXG_DEVICE=$t/absent RUN_KDE_HOST_RENDERER= ${exe} --dry-run"
|
|
)
|
|
(scenario "dry-run-wslg-software-gl" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=llvmpipe (LLVM 21.1.8, 256 bits)" ${exe} --dry-run''
|
|
)
|
|
(scenario "dry-run-headless" 0 "machine ${linux} RUN_KDE_MEMINFO=$t/meminfo-small ${exe} --dry-run")
|
|
(scenario "dry-run-tcg" 0 "machine ${linux} RUN_KDE_KVM_DEVICE=$t/absent ${exe} --dry-run --tcg")
|
|
];
|
|
|
|
run-kde-doctor = check "run-kde-doctor" [
|
|
(scenario "doctor-wslg-gpu" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=D3D12 (AMD Radeon RX 7800 XT)" RUN_KDE_WSLCONFIG=$t/none ${exe} --doctor''
|
|
)
|
|
(scenario "doctor-wslg-gpu-no-driver" 0
|
|
''machine ${wslg} RUN_KDE_DXG_DEVICE=$t/dxg "RUN_KDE_HOST_RENDERER=D3D12 (AMD Radeon RX 7800 XT)" RUN_KDE_WSL_LIB_DIR=$t/absent RUN_KDE_VA_DRIVERS_DIR=$t/absent RUN_KDE_WSLCONFIG=$t/none ${exe} --doctor''
|
|
)
|
|
(scenario "doctor-wsl-no-kvm" 1
|
|
"machine WAYLAND_DISPLAY=w RUN_KDE_OSRELEASE=$t/osrelease-wsl RUN_KDE_KVM_DEVICE=$t/absent RUN_KDE_CPUINFO=$t/cpuinfo-none RUN_KDE_MEMINFO=$t/meminfo-small RUN_KDE_DXG_DEVICE=$t/absent RUN_KDE_HOST_RENDERER= RUN_KDE_WSLCONFIG=$t/none ${exe} --doctor"
|
|
)
|
|
(scenario "doctor-kvm-denied" 1 "machine ${linux} RUN_KDE_KVM_DEVICE=$t/kvm-denied ${exe} --doctor")
|
|
(scenario "doctor-fuse-missing" 0 "machine ${linux} RUN_KDE_FUSE_DEVICE=$t/absent ${exe} --doctor")
|
|
(scenario "doctor-fuse-denied" 0
|
|
"machine ${linux} RUN_KDE_FUSE_DEVICE=$t/kvm-denied ${exe} --doctor"
|
|
)
|
|
(scenario "doctor-virtiofsd-broken" 1
|
|
"machine ${linux} RUN_KDE_VIRTIOFSD=$t/bin/virtiofsd-broken ${exe} --doctor"
|
|
)
|
|
];
|
|
}
|