virtio-gpu: add VIRTIO_GPU_F_CURSOR_SIZE
PATCH 1/1 virtio-gpu: add VIRTIO_GPU_F_CURSOR_SIZE
The cursor resource is 64x64. A guest on a high-DPI display scales its pointer beyond that: Windows asks for a 96x96 pointer at 300% scaling and a 160x160 one at 500%. When the driver cannot hand the device a cursor of that size, the guest draws the pointer into the framebuffer itself, so every pointer move becomes a guest redraw and a scanout update instead of a cursorq command. Hosts can show larger cursors:
Intel display engines, for example, have 256x256 cursor planes.
Let the device advertise the largest cursor it takes, in a new configuration field made valid by a new feature bit, following VIRTIO_GPU_F_BLOB_ALIGNMENT. When the feature has been negotiated, the width and the height of a cursor resource can each be any value up to that size. Without the feature nothing changes: the cursor stays 64x64.
---
Notes:
Bit number: bits 6 and 7 are proposed in Val Packett's pending series "virtio_gpu: add F_CREATE_GUEST_HANDLE and F_BLOB_CTX_ID_FIX" [1], so this takes 8. Neither of those adds a configuration field, so max_cursor_size goes right after blob_alignment either way.
Implementations: a QEMU device change (the feature, the field and a max_cursor_size property, up to 256) and a change to the Windows viogpudo driver have been run together on an Intel host. With a 4K display at 300% scaling, Windows hands the driver 96x96 pointer shapes, and the host shows them at full size on its hardware cursor plane. Both still use bit 6 and will follow the number agreed here. Neither is posted yet. There is no Linux driver change yet.
This patch was written with the help of an AI coding assistant, Anthropic's Claude, directed and reviewed by me, and I take responsibility for it as for any patch I sign off.
[1] https://lore.kernel.org/virtio-comment/[email protected]/
device-types/gpu/description.tex | 23 ++++++++++++++++++++++- device-types/gpu/device-conformance.tex | 1 + device-types/gpu/driver-conformance.tex | 1 + 3 files changed, 24 insertions(+), 1 deletion(-)
device-types/gpu/description.tex +22 -1
@@ -39,6 +39,9 @@ \subsection{Feature bits}\label{sec:Device Types / GPU Device / Feature bits} synchronization timelines supported. Requires VIRTIO_GPU_F_VIRGL. \item[VIRTIO_GPU_F_BLOB_ALIGNMENT (5)] configuration field \field{blob_alignment} is valid. Requires VIRTIO_GPU_F_RESOURCE_BLOB. +\item[VIRTIO_GPU_F_CURSOR_SIZE (8)] configuration field + \field{max_cursor_size} is valid, and a cursor resource can be + larger than 64x64. \end{description} \subsection{Device configuration layout}\label{sec:Device Types / GPU Device / Device configuration layout}
@@ -55,6 +58,7 @@ \subsection{Device configuration layout}\label{sec:Device Types / GPU Device / D le32 num_scanouts; le32 num_capsets; le32 blob_alignment; + le32 max_cursor_size; }; \end{lstlisting}
@@ -73,6 +77,8 @@ \subsubsection{Device configuration fields} \item[\field{blob_alignment}] specifies the minimal alignment, in bytes, required by the device for resource blobs. The value is a power of two. Minimum value is 1, maximum value is 4294967296. +\item[\field{max_cursor_size}] specifies the maximum width and the + maximum height, in pixels, of a cursor resource. Minimum value is 64. \end{description} \subsubsection{Events}
@@ -184,7 +190,9 @@ \subsubsection{Device Operation: Multihead setup} \subsubsection{Device Operation: Configure mouse cursor} The mouse cursor image is a normal resource, except that it must be -64x64 in size. The driver MUST create and populate the resource +64x64 in size. If VIRTIO_GPU_F_CURSOR_SIZE has been negotiated, its +width and its height can instead be any value up to +\field{max_cursor_size}. The driver MUST create and populate the resource (using the usual VIRTIO_GPU_CMD_RESOURCE_CREATE_2D, VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING and VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D controlq commands) and make sure they
@@ -866,6 +874,19 @@ \subsubsection{Device Operation: cursorq}\label{sec:Device Types / GPU Device / \end{description} +\drivernormative{\paragraph}{Device Operation: cursorq}{Device Types / GPU Device / Device Operation / Device Operation: cursorq} + +If VIRTIO_GPU_F_CURSOR_SIZE has been negotiated, the driver MUST NOT +send VIRTIO_GPU_CMD_UPDATE_CURSOR for a resource whose width or height +is larger than \field{max_cursor_size}. + +\devicenormative{\paragraph}{Device Operation: cursorq}{Device Types / GPU Device / Device Operation / Device Operation: cursorq} + +If VIRTIO_GPU_F_CURSOR_SIZE has been negotiated, the device MUST load +the cursor from the whole resource in VIRTIO_GPU_CMD_UPDATE_CURSOR +whenever its width and its height are both at most +\field{max_cursor_size}. + \subsection{VGA Compatibility}\label{sec:Device Types / GPU Device / VGA Compatibility} Applies to Virtio Over PCI only. The GPU device can come with and
device-types/gpu/device-conformance.tex +1 -0
@@ -5,4 +5,5 @@ \begin{itemize} \item \ref{devicenormative:Device Types / GPU Device / Device Initialization} \item \ref{devicenormative:Device Types / GPU Device / Device Operation / Device Operation: Command lifecycle and fencing} +\item \ref{devicenormative:Device Types / GPU Device / Device Operation / Device Operation: cursorq} \end{itemize}
device-types/gpu/driver-conformance.tex +1 -0
@@ -5,4 +5,5 @@ \begin{itemize} \item \ref{drivernormative:Device Types / GPU Device / Device Operation / Device Operation: controlq} \item \ref{drivernormative:Device Types / GPU Device / Device Operation / Device Operation: controlq (3d)} +\item \ref{drivernormative:Device Types / GPU Device / Device Operation / Device Operation: cursorq} \end{itemize}