VR
Monado
Monado 是一個開源的 OpenXR 運行時。它使用內置驅動程序支持各種硬體,使其可以運行任何 OpenXR 程序,並且在 OpenComposite 的幫助下,還可以運行大多數 OpenVR 應用程式。
可以使用其 NixOS 選項 services.monado.enable
配置 Monado:
services.monado = {
enable = true;
defaultRuntime = true; # Register as default OpenXR runtime
};
為了配置 Monado,您可能需要添加其他環境變量:
systemd.user.services.monado.environment = {
STEAMVR_LH_ENABLE = "1";
XRT_COMPOSITOR_COMPUTE = "1";
};
配置完成後,Monado 可以在 systemd 用戶會話中啟動和停止。
例如,以下命令將啟動 Monado,然後列印其日誌輸出:
$ systemctl --user start monado.service
$ journalctl --user --follow --unit monado.service
手部追蹤
您可能會注意到,由於缺少手部追蹤數據,運行 monado-services
會失敗。有兩種方法可以解決這個問題:完全禁用手部追蹤,或下載手部追蹤數據。
要禁用手部追蹤,請修改環境變量以包含 WMR_HANDTRACKING = "0";
,使其如下所示。
systemd.user.services.monado.environment = {
STEAMVR_LH_ENABLE = "1";
XRT_COMPOSITOR_COMPUTE = "1";
WMR_HANDTRACKING = "0";
};
要使手部追蹤功能正常工作,您需要啟用 git-lfs
。啟用 git-lfs
的標準方法是通過以下配置
programs.git = {
enable = true;
lfs.enable = true;
};
確保 git-lfs
功能啟用後,運行以下命令並重新啟動 monado-service
$ mkdir -p ~/.local/share/monado
$ cd ~/.local/share/monado
$ git clone https://gitlab.freedesktop.org/monado/utilities/hand-tracking-models
For further information about available environment variables and tweaks, read the Linux VR Adventures wiki and the Monado documentation about environment variables
OpenComposite
OpenComposite is a compatibility layer for running OpenVR applications on an OpenXR runtime like Monado. It is comparable to tools like DXVK or vkd3d, but for translating OpenVR calls to OpenXR.
為了在 SteamVR 以外的任何平台上運行 OpenVR 遊戲,您需要配置 ~/.config/openvr/openvrpaths.vrpath
中定義的 OpenVR 運行時路徑。一個可靠的方法是使用 Home Manager 創建此文件。
如果此文件未設置為只讀,SteamVR 將添加其運行時路徑,因此可以使用 Home Manager。
啟用 OpenComposite 的示例配置可能如下所示:
# For Monado:
xdg.configFile."openxr/1/active_runtime.json".source = "${pkgs.monado}/share/openxr/1/openxr_monado.json";
# For WiVRn v0.22 and below:
xdg.configFile."openxr/1/active_runtime.json".source = "${pkgs.wivrn}/share/openxr/1/openxr_wivrn.json";
xdg.configFile."openvr/openvrpaths.vrpath".text = ''
{
"config" :
[
"${config.xdg.dataHome}/Steam/config"
],
"external_drivers" : null,
"jsonid" : "vrpathreg",
"log" :
[
"${config.xdg.dataHome}/Steam/logs"
],
"runtime" :
[
"${pkgs.opencomposite}/lib/opencomposite"
],
"version" : 1
}
'';
如果您計劃在 Steam 上玩任何 OpenVR 遊戲或通過 Proton 遊玩 OpenXR 遊戲,則必須以這種方式使用 OpenComposite。在大多數情況下,您還必須允許 Steam 運行時訪問您的 OpenXR 運行時的 Socket 路徑,方法是使用以下 Steam 上 XR 應用程式的啟動選項:env PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/monado_comp_ipc %command%
。此示例適用於 Monado,其他 XR 運行時可能有所不同。
WiVRn
WiVRn 是一款基於 Monado 構建的 OpenXR 流媒體應用程式。它能夠將獨立的 VR 頭戴設備無線連接到 Linux 計算機。如果您的頭戴設備不是無線的,請查閱 Monado。 WiVRn 模塊的示例用法:
services.wivrn = {
enable = true;
openFirewall = true;
# Write information to /etc/xdg/openxr/1/active_runtime.json, VR applications
# will automatically read this and work with WiVRn (Note: This does not currently
# apply for games run in Valve's Proton)
defaultRuntime = true;
# Run WiVRn as a systemd service on startup
autoStart = true;
# Config for WiVRn (https://github.com/WiVRn/WiVRn/blob/master/docs/configuration.md)
config = {
enable = true;
json = {
# 1.0x foveation scaling
scale = 1.0;
# 100 Mb/s
bitrate = 100000000;
encoders = [
{
encoder = "vaapi";
codec = "h265";
# 1.0 x 1.0 scaling
width = 1.0;
height = 1.0;
offset_x = 0.0;
offset_y = 0.0;
}
];
};
};
};
與 Monado 一樣,您還須添加 WiVRn 的啟動參數以允許訪問 Socket:PRESSURE_VESSEL_FILESYSTEMS_RW=$XDG_RUNTIME_DIR/wivrn/comp_ipc %command%
Envision
Envision is an orchestrator for the FOSS VR stack. It handles the building and configuration of Monado, WiVRn, OpenComposite, and other utilities of the FOSS VR stack such as the Lighthouse driver, OpenHMD, Survive, and WMR. You can enable it with the Envision module:
programs.envision = {
enable = true;
openFirewall = true; # This is set true by default
};
SteamVR
SteamVR is a proprietary OpenVR runtime with compatibility for OpenXR. It is part of Steam and doesn't need any additional setup on NixOS apart from enabling Steam.
After installing SteamVR through Steam and plugging in a SteamVR-compatible headset, SteamVR should work for the most part.
On initial setup, SteamVR will ask for elevated permissions, to set up a file capability for one of its binaries. This is needed to allow asynchronous reprojection to work. Clients need the CAP_SYS_NICE
capability to acquire a high-priority context, which is a requirement for asynchronous reprojection.
修補 AMDGPU 以允許高優先級隊列
By applying this patch, the AMDGPU kernel driver will ignore process privileges and allow any application to create high priority contexts.
作為 NixOS 內核補丁進行應用
To workaround the CAP_SYS_NICE
requirement, we can apply a kernel patch using the following NixOS configuration snippet:
boot.kernelPatches = [
{
name = "amdgpu-ignore-ctx-privileges";
patch = pkgs.fetchpatch {
name = "cap_sys_nice_begone.patch";
url = "https://github.com/Frogging-Family/community-patches/raw/master/linux61-tkg/cap_sys_nice_begone.mypatch";
hash = "sha256-Y3a0+x2xvHsfLax/uwycdJf3xLxvVfkfDVqjkxNaYEo=";
};
}
];
It is also possible to just patch amdgpu and build it as an out-of-tree module, as described in Linux_kernel#Patching_a_single_In-tree_kernel_module
wlx-overlay-s
wlx-overlay-s is a lightweight OpenXR/OpenVR overlay for Wayland and X11 desktops. It works with SteamVR as well as Monado/WiVRn natively.
SteamVR 自動啟動
# Run wlx-overlay-s and replace any running instance
$ wlx-overlay-s --replace