Skip to content

Latest commit

 

History

History
475 lines (380 loc) · 18.8 KB

README.md

File metadata and controls

475 lines (380 loc) · 18.8 KB
LizardByte icon

libvirtualdisplay

C++ library to create virtual displays.

Codecov SonarCloud

libvirtualdisplay provides drivers, C++ control APIs, and tools for creating and managing virtual displays. It includes a Windows UMDF/IddCx driver and a Linux DRM backend that applications can use independently.

Scope

  • create and remove temporary displays through the control API
  • set and query a small permanent-display pool
  • preserve stable display identity through DisplayId
  • keep lease lifetime separate from display identity through LeaseId
  • advertise HDR-capable EDID and IddCx target capabilities
  • provide runtime probes that verify the control path and HDR target behavior
  • provision a dormant Linux DRM connector pool and lease connectors through a root-owned Unix-domain control broker

The Windows implementation is clean-room: compatibility work happens at the API/behavior level rather than by copying other virtual-display drivers. The Linux kernel subtree is deliberately derived from upstream VKMS and retains its GPL SPDX licensing and provenance.

Build

Initialize the shared dependencies before building the test suite or the optional KWin bridge:

git submodule update --init --recursive
cmake -S . -B cmake-build-tests -G Ninja -DBUILD_TESTS=ON
cmake --build cmake-build-tests --parallel
ctest --test-dir cmake-build-tests --output-on-failure

The test suite uses lizardbyte-common's pinned GoogleTest and shared test helpers. On Windows, use the MSYS2 UCRT64 shell for Ninja builds. With MSVC, configure with -G "Visual Studio 17 2022" -A x64, build with --config Release, and pass -C Release to CTest. Standalone GNU test builds enable coverage automatically.

On Linux, the same build also tests the connector broker, module installer, kernel-source contract, deterministic HDR EDID, and the public LinuxControlClient. The linux/virtualdisplay-drm tree contains the GPL-licensed out-of-tree DRM module derived from upstream VKMS; its source files retain the upstream SPDX identifiers. Service and installer assets live under linux/packaging.

The optional KWin bridge (-DBUILD_VIRTUALDISPLAY_KWIN_GPU_BRIDGE=ON) requires libdrm 2.4.127 or newer and the GBM development package.

To build the Windows driver and tools:

cmake -S . -B cmake-build-driver -G Ninja -DBUILD_TESTS=OFF -DBUILD_VIRTUALDISPLAY_WINDOWS_DRIVER=ON -DBUILD_VIRTUALDISPLAY_TOOLS=ON -DBUILD_VIRTUALDISPLAY_PROBE=ON
cmake --build cmake-build-driver --parallel

The Windows driver build requires MSVC and the Windows Driver Kit. Packaging also requires Inf2Cat.exe from the WDK. Local package builds generate the INF and catalog files, but do not sign them; sign the driver package according to your Windows driver distribution policy before installing it outside a test or developer environment.

To build the release ZIP locally:

cmake -S . -B cmake-build-driver -G Ninja -DBUILD_TESTS=OFF -DBUILD_VIRTUALDISPLAY_WINDOWS_DRIVER=ON -DBUILD_VIRTUALDISPLAY_TOOLS=ON -DBUILD_VIRTUALDISPLAY_PROBE=ON -DLIBVIRTUALDISPLAY_PACKAGE_VERSION=0.1.0
cmake --build cmake-build-driver --target package --parallel

The ZIP contains:

  • driver/LizardByteVirtualDisplay.inf
  • driver/LizardByteVirtualDisplay.cat
  • driver/LizardByteVirtualDisplay.dll
  • tools/virtualdisplay.exe
  • tools/virtualdisplay_broker.exe
  • tools/virtualdisplay_probe.exe
  • vulkan-layer/VkLayer_lizardbyte_hdr.dll and vulkan-layer/VkLayer_lizardbyte_hdr.json
  • README.md and LICENSE

Support traces and Event Log capture should follow docs/support-diagnostics.md.

For C++ integration, consume the source tree and CMake target. The release ZIP is intended for the driver, CLI, and probe tools.

CLI usage

virtualdisplay.exe manages the LizardByte Virtual Display driver through its control interface.

After extracting the release ZIP, run commands from the extracted top-level directory. Install the driver with:

.\tools\virtualdisplay.exe driver install

For a local developer build, the same command can be run from the build output:

.\cmake-build-driver\src\driver\virtualdisplay.exe driver install

driver install self-elevates through the Windows UAC prompt when it is not already running as administrator. By default it installs driver\LizardByteVirtualDisplay.inf from the same extracted release directory. To install a different INF:

.\tools\virtualdisplay.exe driver install --inf <path-to-inf>

All display management commands assume the driver package has already been installed, Windows has started the virtual display device, and the broker service is running. Use virtualdisplay_probe.exe for diagnostics that need to exercise the installed driver control path directly.

Manage the broker service from the CLI:

.\tools\virtualdisplay.exe broker install
.\tools\virtualdisplay.exe broker start
.\tools\virtualdisplay.exe broker status
.\tools\virtualdisplay.exe broker stop
.\tools\virtualdisplay.exe broker uninstall

Query the current permanent-display state:

.\tools\virtualdisplay.exe status
.\tools\virtualdisplay.exe permanent query

Query active display identity and profile details:

.\tools\virtualdisplay.exe display query

Create one permanent display with the default settings:

.\tools\virtualdisplay.exe spawn

Create or update a permanent display with explicit settings:

.\tools\virtualdisplay.exe spawn --width 2560 --height 1440 --refresh 120
.\tools\virtualdisplay.exe permanent set --count 1 --width 3840 --height 2160 --physical-width-mm 700 --physical-height-mm 390 --refresh 144 --name "Desk Display"

Create several permanent displays with the same EDID mode/name settings:

.\tools\virtualdisplay.exe permanent set --count 2 --width 1920 --height 1080 --refresh 60 --name "Virtual Display"

Remove all permanent displays:

.\tools\virtualdisplay.exe permanent off

Supported settings:

  • --count: permanent display count, from 0 through the driver's maximum.
  • --width: preferred display width in pixels.
  • --height: preferred display height in pixels.
  • --physical-width-mm: physical panel width advertised in EDID, in millimeters.
  • --physical-height-mm: physical panel height advertised in EDID, in millimeters.
  • --refresh: preferred refresh rate. Values up to 1000 are treated as Hz, so 120 means 120 Hz; larger values are treated as millihertz.
  • --name sets the monitor name advertised in EDID. The default is LizardByte VD. The EDID name field holds up to 13 ASCII characters.

The driver validates modes against the protocol range:

  • width: 320 through 7680
  • height: 200 through 4320
  • physical width and height: 10 mm through 2550 mm
  • refresh: any positive millihertz value accepted by the protocol; the driver no longer applies a policy refresh-rate ceiling

Optional Vulkan HDR layer

Vendor Vulkan ICDs (NVIDIA, Intel) only advertise HDR surface formats for displays driven by their own display pipeline. Indirect (IddCx) displays are owned by the virtual display adapter, so windowed Vulkan applications never see VK_COLOR_SPACE_HDR10_ST2084_EXT or VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT on a virtual display even when Windows runs it in HDR mode — while the same ICDs present those colorspaces correctly when asked (verified by reading back DWM's FP16 scRGB composition through Desktop Duplication). DirectX HDR is unaffected; this gap is specific to Vulkan surface-format enumeration.

VK_LAYER_LIZARDBYTE_virtual_hdr is an implicit Vulkan layer that closes the gap: it appends the two missing HDR format pairs to vkGetPhysicalDeviceSurfaceFormats(2)KHR results when the surface's monitor reports HDR support in Windows and the ICD did not already advertise them. Register it system-wide with:

.\tools\virtualdisplay.exe vulkan-layer install
.\tools\virtualdisplay.exe vulkan-layer status
.\tools\virtualdisplay.exe vulkan-layer uninstall

vulkan-layer install self-elevates and registers the manifest from the vulkan-layer directory of the extracted release or next to the CLI in a build tree. Pass --json PATH to register a different manifest.

The layer injects HDR formats while a host signals an active HDR session using the Windows event Global\LizardByteVirtualHdrActive or its local equivalent Local\LizardByteVirtualHdrActive. Other queries pass through unchanged. Set DISABLE_LIBVIRTUALDISPLAY_HDR_LAYER=1 to disable the layer for a process. Set LIBVIRTUALDISPLAY_HDR_FORCE=1 to bypass the monitor HDR capability check while the event is signaled.

Use virtualdisplay_probe.exe for diagnostics and runtime validation rather than normal display management. Common commands are:

.\tools\virtualdisplay_probe.exe --check
.\tools\virtualdisplay_probe.exe --diagnose
.\tools\virtualdisplay_probe.exe --query-permanent
.\tools\virtualdisplay_probe.exe --self-test-permanent
.\tools\virtualdisplay_probe.exe --self-test-temp 1920 1080 60
.\tools\virtualdisplay_probe.exe --self-test-hdr 1920 1080 60

Run .\tools\virtualdisplay_probe.exe --help to list advanced validation and debug commands.

Programmatic usage

The C++ API is primarily for source consumers. Link the libvirtualdisplay::driver CMake target and include headers from src/driver/include. Windows control device discovery is available through windows_control_client.h; the lower level protocol types and ControlClient are platform-neutral.

The public C++ control surface is in:

  • virtual_display/driver/control_protocol.h
  • virtual_display/driver/control_client.h
  • virtual_display/driver/windows_control_client.h
  • virtual_display/driver/linux_control_client.h

On Windows, open the first installed control device, check protocol compatibility, and construct a ControlClient:

#include "virtual_display/driver/control_client.h"
#include "virtual_display/driver/windows_control_client.h"

namespace vdd = virtual_display::driver;

auto opened = vdd::open_first_control_device();
if (!opened.ok()) {
  // opened.status and opened.native_error explain the failure.
  return 1;
}

vdd::ControlClient client {*opened.transport};
auto protocol = client.check_protocol_compatible();
if (!protocol.ok()) {
  return 1;
}

open_first_control_device() enumerates installed virtual display control devices and opens the first usable one. It fails when the driver is not installed, the device is not started, or Windows denies access. Keep the opened transport alive for as long as ControlClient uses it.

API calls return either ControlOperationResult or ControlResult<T>. Check ok() before using output values. status reports library/protocol failures; native_error carries the operating-system error code when transport or device access fails.

Requests in the examples are value-initialized before copying fixed-size display names. This keeps protocol strings null-terminated when using std::strncpy.

Permanent displays

Permanent displays stay present until the count is changed or the driver/device is restarted. Use them for simple desktop setups where a user wants an always-on virtual monitor.

vdd::PermanentDisplayCountRequest request {};
request.display_count = 1;
request.width = 2560;
request.height = 1440;
request.physical_width_mm = 590;
request.physical_height_mm = 330;
request.refresh_rate_millihz = 120'000;
std::strncpy(request.display_name, "Desk Display", sizeof(request.display_name) - 1);

auto result = client.set_permanent_display_count(request);
if (!result.ok()) {
  return 1;
}

// result.value reports current_display_count, max_display_count,
// temporary_display_count, width, height, physical size, refresh_rate_millihz,
// and display_name.

Query the current permanent-display state:

auto state = client.query_permanent_display_count();
if (!state.ok()) {
  return 1;
}

Remove all permanent displays:

vdd::PermanentDisplayCountRequest request {};
request.display_count = 0;
auto result = client.set_permanent_display_count(request);

Temporary displays

Temporary displays are lease-backed. They are useful when an application needs a display only while a session is active. Keep feeding the lease for as long as the display should remain present, then remove the display or release the lease.

vdd::CreateTemporaryDisplayRequest request {};
request.lease_id = 0x1001;
request.display_id = 0x2001;
request.width = 1920;
request.height = 1080;
request.physical_width_mm = 530;
request.physical_height_mm = 300;
request.refresh_rate_millihz = 60'000;
request.requested_timeout_ms = 30'000;
std::strncpy(request.display_name, "Session Display", sizeof(request.display_name) - 1);

auto created = client.create_temporary_display(request);
if (!created.ok()) {
  return 1;
}

vdd::LeaseRequest lease {
  vdd::kApiNamespaceGuid,
  request.lease_id,
  request.requested_timeout_ms,
  0
};

// Call periodically before remaining_ms reaches zero.
auto fed = client.feed_lease(lease);
if (!fed.ok()) {
  return 1;
}

vdd::LeaseDisplayRequest remove {
  vdd::kApiNamespaceGuid,
  request.lease_id,
  request.display_id
};
auto removed = client.remove_temporary_display(remove);
if (!removed.ok()) {
  return 1;
}

created.value.effective_timeout_ms reports the timeout accepted by the driver. Call feed_lease() before that timeout expires; applications commonly refresh at a fraction of the effective timeout. If the lease expires, the driver removes temporary displays owned by that lease.

Temporary displays retain driver-side identity by default so a caller can reuse the same DisplayId for a logical display that should keep Windows settings. Set request.flags |= vdd::kCreateTemporaryDisplayFlagEphemeralIdentity when a display should not write persistent driver identity state; pair that with a fresh caller-owned DisplayId when Windows settings retention is not desired.

Release every temporary display owned by a lease:

vdd::LeaseRequest lease {
  vdd::kApiNamespaceGuid,
  request.lease_id,
  0,
  0
};
auto released = client.release_lease(lease);
if (!released.ok()) {
  return 1;
}

Protocol notes

  • The current protocol version is 3.8.0. Protocol 3.8 adds requested-resolution mode catalogs and an explicit frame transport capability query. The IddCx producer and owner-authenticated frame ring are available only in an explicit experimental build option that defaults off; Windows/WDK/GPU qualification is still required. See the frame transport notes.
  • Protocol 3.7 adds owned temporary display creation and capability-based lease reclaim without exposing lease IDs through global display-state queries.
  • Reclaim rotates only lease ownership and expiry. Connector assignment and the EDID-producing display descriptor remain unchanged, so Windows keeps the same monitor identity and settings contract.
  • The Windows driver measures lease expiry with unbiased interrupt time; time spent in system sleep does not consume a temporary display lease.
  • ControlClient::check_protocol_compatible() should be called before issuing state-changing requests.
  • IDs are caller-owned. Reuse DisplayId for the same logical display when you want Windows to retain display identity across sessions; use a unique LeaseId for each active temporary-display owner.
  • Names are fixed-size protocol strings with a 32 byte limit.
  • Width must be 320 through 7680 and height 200 through 4320, with the total resolution not exceeding 7680×4320 pixels. Physical width and height must be 10 through 2550 millimeters. The refresh rate is given in millihertz and must be non-zero (for example 60000 for 60 Hz).
  • Lease timeouts are clamped to the protocol range and reported back as effective_timeout_ms.
  • Permanent-display settings are shared by the active permanent pool; setting the same count with new mode/name settings refreshes existing permanent monitors.

Requested-resolution Windows catalogs (protocol 3.8)

kCreateTemporaryDisplayFlagRequestedResolutionOnly opts one temporary monitor into advertising only its requested width and height. The default flag value is zero and preserves the complete catalog. The restricted catalog retains existing same-resolution nominal rates and the descriptor's exact base, 2x and 4x rates; it does not impose a single refresh rate. A missing or invalid unbound description retains a nonempty default catalog. Accepted explicit creates first validate their requested dimensions and refresh, then carry that exact timing and policy through the temporary record and backend descriptor. They do not retry as a full-catalog create. The malformed-description helper fallback is not evidence that Windows will retain the restriction after unexpected native descriptor loss; that path remains a qualification gate.

Check the actual opened Windows producer with supports_requested_resolution_catalog(query_protocol_version().value) after checking that the query succeeded. Protocol 3.7 does not support the new bit; never silently retry an explicit restricted request with the bit removed and report it as success. Existing request/result sizes and IOCTL values are unchanged. QueryDisplayState reports the effective policy with kDisplayStateFlagRequestedResolutionOnly.

The policy belongs to the temporary display record and is immutable until removal. Secure reclaim changes its lease, not its mode catalog. Changing policy or requested dimensions requires a new monitor lifetime, using the existing proven-owner removal path at a session boundary. Never mutate a peer, shared or permanent display's catalog to satisfy a per-client setting. Producer source support alone does not expose a host setting: consumers must carry a per-client opt-in, verify capability and queried state, and ship a reviewed, trust-qualified Windows producer first.

Both monitor-description callback versions, target-mode callback versions, and the per-monitor default-description callback use the same policy. Portable mode and controller tests do not establish Windows/DXGI enumeration, installed driver trust, or a game's resolution-selection behavior; those need native qualification.