Skip to contentSkip to conversation

Support per-head resolutions with virtio-gpu

PATCH Superseded Andrew Keesler 2 participants 8 messages Jan 9 – Feb 7

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Support per-head resolutions with virtio-gpu

In 454f4b0f, we started down the path of supporting separate configurations per display head (e.g., you have 2 heads - one with EDID name "AAA" and the other with EDID name "BBB").

In this change, we add resolution to this configuration surface (e.g., you have 2 heads - one with resolution 111x222 and the other with resolution 333x444).

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA",
                 "xres":111,
                 "yres":222
              },
              {
                 "name":"BBB",
                 "xres":333,
                 "yres":444
              }
            ]}'

Here is the behavior matrix of the current resolution configuration surface (xres/yres) with the new resolution configuration surface (outputs[i].xres/yres).

Case: !(xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with default xres/yres

Case: (xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with xres/yres

Case: !(xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Case: (xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Changelist:
* v4: changes after dropped from pull request
* rebase against master (3b5fe75e2c)
* use @NAME (@xres/@yres) in qapi/virtio.json docs
* documented behavior when only one or none of @xres/@yres is set
* v3: changes after v2 review
* fix new resolution configuration logic (&& instead of ||)
* correct use of api machinery (has_*)
* move documentation to QMP API
* v2: changes after v1 review + 10.2 rebase
* updated code, commit message, and cover letter to match new res config logic
* marked new VirtIOGPUOutput fields as optional and since 10.2
* v1: initial patch

Andrew Keesler (1):
Support per-head resolutions with virtio-gpu

 hw/display/virtio-gpu-base.c | 10 ++++++++++
 qapi/virtio.json             | 13 +++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#1 lore raw

PATCH v4 1/1 Support per-head resolutions with virtio-gpu

In 454f4b0f, we started down the path of supporting separate configurations per display head (e.g., you have 2 heads - one with EDID name "AAA" and the other with EDID name "BBB").

In this change, we add resolution to this configuration surface (e.g., you have 2 heads - one with resolution 111x222 and the other with resolution 333x444).

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA",
                 "xres":111,
                 "yres":222
              },
              {
                 "name":"BBB",
                 "xres":333,
                 "yres":444
              }
            ]}'

Here is the behavior matrix of the current resolution configuration surface (xres/yres) with the new resolution configuration surface (outputs[i].xres/yres).

Case: !(xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with default xres/yres

Case: (xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with xres/yres

Case: !(xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Case: (xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

---
 hw/display/virtio-gpu-base.c | 10 ++++++++++
 qapi/virtio.json             | 13 +++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-base.c +10 -0
index 7269477a1c..6adb5312a4 100644
@@ -233,6 +233,16 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
     g->req_state[0].width = g->conf.xres;
     g->req_state[0].height = g->conf.yres;
 
+    for (output_idx = 0, node = g->conf.outputs;
+         node && output_idx < g->conf.max_outputs;
+         output_idx++, node = node->next) {
+        if (node->value->has_xres && node->value->has_yres) {
+            g->enabled_output_bitmask |= (1 << output_idx);
+            g->req_state[output_idx].width = node->value->xres;
+            g->req_state[output_idx].height = node->value->yres;
+        }
+    }
+
     g->hw_ops = &virtio_gpu_ops;
     for (i = 0; i < g->conf.max_outputs; i++) {
         g->scanout[i].con =
qapi/virtio.json +11 -2
index cd67c4f52e..c1a1fb4997 100644
@@ -970,15 +970,24 @@
 ##
 # @VirtIOGPUOutput:
 #
-# Describes configuration of a VirtIO GPU output.
+# Describes configuration of a VirtIO GPU output.  If both @xres and
+# @yres are set, they take precedence over root virtio-gpu
+# resolution configuration and enable the corresponding output.  If
+# only one or none of @xres or @yres is set, root virtio-gpu
+# resolution configuration takes precedence and only the first output
+# is enabled.
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels (since 10.2)
+#
+# @yres: vertical resolution of the output in pixels (since 10.2)
+#
 # Since: 10.1
 ##
 
 { 'struct': 'VirtIOGPUOutput',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*xres': 'uint16', '*yres': 'uint16' } }
 
 ##
 # @DummyVirtioForceArrays:
Signature · 1 line
2.52.0.457.g6b5491de43-goog
#2 lore raw

Note - we use "xres" and "yres" (instead of, say, "width" and "height") to match analogous virtio_gpu_base_conf.xres/yres.

Quoted 104 lines · Andrew Keesler

In 454f4b0f, we started down the path of supporting separate configurations per display head (e.g., you have 2 heads - one with EDID name "AAA" and the other with EDID name "BBB").

In this change, we add resolution to this configuration surface (e.g., you have 2 heads - one with resolution 111x222 and the other with resolution 333x444).

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA",
                 "xres":111,
                 "yres":222
              },
              {
                 "name":"BBB",
                 "xres":333,
                 "yres":444
              }
            ]}'

Here is the behavior matrix of the current resolution configuration surface (xres/yres) with the new resolution configuration surface (outputs[i].xres/yres).

Case: !(xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with default xres/yres

Case: (xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with xres/yres

Case: !(xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Case: (xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

---
 hw/display/virtio-gpu-base.c | 10 ++++++++++
 qapi/virtio.json             | 13 +++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-base.c +10 -0
index 7269477a1c..6adb5312a4 100644
@@ -233,6 +233,16 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
     g->req_state[0].width = g->conf.xres;
     g->req_state[0].height = g->conf.yres;
 
+    for (output_idx = 0, node = g->conf.outputs;
+         node && output_idx < g->conf.max_outputs;
+         output_idx++, node = node->next) {
+        if (node->value->has_xres && node->value->has_yres) {
+            g->enabled_output_bitmask |= (1 << output_idx);
+            g->req_state[output_idx].width = node->value->xres;
+            g->req_state[output_idx].height = node->value->yres;
+        }
+    }
+
     g->hw_ops = &virtio_gpu_ops;
     for (i = 0; i < g->conf.max_outputs; i++) {
         g->scanout[i].con =
qapi/virtio.json +11 -3
index cd67c4f52e..c1a1fb4997 100644
@@ -970,15 +970,24 @@
 ##
 # @VirtIOGPUOutput:
 #
-# Describes configuration of a VirtIO GPU output.
+# Describes configuration of a VirtIO GPU output.  If both @xres and
+# @yres are set, they take precedence over root virtio-gpu
+# resolution configuration and enable the corresponding output.  If
+# only one or none of @xres or @yres is set, root virtio-gpu
+# resolution configuration takes precedence and only the first output
+# is enabled.
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels (since 10.2)
+#
+# @yres: vertical resolution of the output in pixels (since 10.2)
+#
 # Since: 10.1
 ##
 
 { 'struct': 'VirtIOGPUOutput',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*xres': 'uint16', '*yres': 'uint16' } }
 
 ##
 # @DummyVirtioForceArrays:
--

2.52.0.457.g6b5491de43-goog

#3 lore raw

Gentle request for review.

This change was previously queued, and then dropped from a PR:

https://mail.gnu.org/archive/html/qemu-devel/2025-10/msg04960.html

This v4 PATCH addresses those comments.

Quoted 110 lines · Andrew Keesler

Note - we use "xres" and "yres" (instead of, say, "width" and "height") to match analogous virtio_gpu_base_conf.xres/yres.

Quoted 104 lines · Andrew Keesler

In 454f4b0f, we started down the path of supporting separate configurations per display head (e.g., you have 2 heads - one with EDID name "AAA" and the other with EDID name "BBB").

In this change, we add resolution to this configuration surface (e.g., you have 2 heads - one with resolution 111x222 and the other with resolution 333x444).

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA",
                 "xres":111,
                 "yres":222
              },
              {
                 "name":"BBB",
                 "xres":333,
                 "yres":444
              }
            ]}'

Here is the behavior matrix of the current resolution configuration surface (xres/yres) with the new resolution configuration surface (outputs[i].xres/yres).

Case: !(xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with default xres/yres

Case: (xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with xres/yres

Case: !(xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Case: (xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

---
 hw/display/virtio-gpu-base.c | 10 ++++++++++
 qapi/virtio.json             | 13 +++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-base.c +10 -0
index 7269477a1c..6adb5312a4 100644
@@ -233,6 +233,16 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
     g->req_state[0].width = g->conf.xres;
     g->req_state[0].height = g->conf.yres;
 
+    for (output_idx = 0, node = g->conf.outputs;
+         node && output_idx < g->conf.max_outputs;
+         output_idx++, node = node->next) {
+        if (node->value->has_xres && node->value->has_yres) {
+            g->enabled_output_bitmask |= (1 << output_idx);
+            g->req_state[output_idx].width = node->value->xres;
+            g->req_state[output_idx].height = node->value->yres;
+        }
+    }
+
     g->hw_ops = &virtio_gpu_ops;
     for (i = 0; i < g->conf.max_outputs; i++) {
         g->scanout[i].con =
qapi/virtio.json +11 -3
index cd67c4f52e..c1a1fb4997 100644
@@ -970,15 +970,24 @@
 ##
 # @VirtIOGPUOutput:
 #
-# Describes configuration of a VirtIO GPU output.
+# Describes configuration of a VirtIO GPU output.  If both @xres and
+# @yres are set, they take precedence over root virtio-gpu
+# resolution configuration and enable the corresponding output.  If
+# only one or none of @xres or @yres is set, root virtio-gpu
+# resolution configuration takes precedence and only the first output
+# is enabled.
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels (since 10.2)
+#
+# @yres: vertical resolution of the output in pixels (since 10.2)
+#
 # Since: 10.1
 ##
 
 { 'struct': 'VirtIOGPUOutput',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*xres': 'uint16', '*yres': 'uint16' } }
 
 ##
 # @DummyVirtioForceArrays:
--

2.52.0.457.g6b5491de43-goog

#4 lore raw
In reply to Andrew Keesler
Quoted 2 lines · Andrew Keesler

Note - we use "xres" and "yres" (instead of, say, "width" and "height") to match analogous virtio_gpu_base_conf.xres/yres.

Mentioning this in the commit message wouldn't hurt.

#5 lore raw
Quoted 1 line

So when exactly one of @xres or @yes is present, it's silently ignored?

That is the currently proposed behavior, yes.

Here is the related review comment.

https://mail.gnu.org/archive/html/qemu-devel/2025-08/msg04584.html

WDYT?

Quoted 1 line

(since 11.0)

ACK, fixed in next patch.

Quoted 1 line

Mentioning this in the commit message wouldn't hurt.

ACK, fixed in next patch.

Quoted 1 line

Recovering from the coughing plague.

Hope you feel better.

Quoted 8 lines · Markus Armbruster
Quoted 2 lines · Andrew Keesler

Note - we use "xres" and "yres" (instead of, say, "width" and "height") to match analogous virtio_gpu_base_conf.xres/yres.

Mentioning this in the commit message wouldn't hurt.

#6 lore raw
Quoted 9 lines · Andrew Keesler
Quoted 1 line

So when exactly one of @xres or @yes is present, it's silently ignored?

That is the currently proposed behavior, yes.

Here is the related review comment.

https://mail.gnu.org/archive/html/qemu-devel/2025-08/msg04584.html

WDYT?

I think nonsensical configuration should be an error.

Quoted 11 lines
Quoted 1 line

(since 11.0)

ACK, fixed in next patch.

Quoted 1 line

Mentioning this in the commit message wouldn't hurt.

ACK, fixed in next patch.

Quoted 1 line

Recovering from the coughing plague.

Hope you feel better.

Much improved, thanks!

[...]

#7 lore raw
In reply to Andrew Keesler

Sorry for the delay. Recovering from the coughing plague.

Quoted 43 lines · Andrew Keesler

In 454f4b0f, we started down the path of supporting separate configurations per display head (e.g., you have 2 heads - one with EDID name "AAA" and the other with EDID name "BBB").

In this change, we add resolution to this configuration surface (e.g., you have 2 heads - one with resolution 111x222 and the other with resolution 333x444).

  -display vnc=localhost:0,id=aaa,display=vga,head=0 \
  -display vnc=localhost:1,id=bbb,display=vga,head=1 \
  -device '{"driver":"virtio-vga",
            "max_outputs":2,
            "id":"vga",
            "outputs":[
              {
                 "name":"AAA",
                 "xres":111,
                 "yres":222
              },
              {
                 "name":"BBB",
                 "xres":333,
                 "yres":444
              }
            ]}'

Here is the behavior matrix of the current resolution configuration surface (xres/yres) with the new resolution configuration surface (outputs[i].xres/yres).

Case: !(xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with default xres/yres

Case: (xres || yres) && !(outputs[i].has_xres && outputs[i].has_yres)
Behavior: current behavior - outputs[0] enabled with xres/yres

Case: !(xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

Case: (xres || yres) && (outputs[i].has_xres && outputs[i].has_yres)
Behavior: new behavior - outputs[i] enabled with outputs[i].xres/yres

[...]

Quoted 5 lines
qapi/virtio.json +0 -0
index cd67c4f52e..c1a1fb4997 100644

qapi/virtio.json line 978

Quoted 10 lines
qapi/virtio.json +6 -1
@@ -970,15 +970,24 @@
 ##
 # @VirtIOGPUOutput:
 #
-# Describes configuration of a VirtIO GPU output.
+# Describes configuration of a VirtIO GPU output.  If both @xres and
+# @yres are set, they take precedence over root virtio-gpu
+# resolution configuration and enable the corresponding output.  If
+# only one or none of @xres or @yres is set, root virtio-gpu
+# resolution configuration takes precedence and only the first output
+# is enabled.

So when exactly one of @xres or @yes is present, it's silently ignored?

qapi/virtio.json line 984

Quoted 6 lines
qapi/virtio.json +3 -0
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels (since 10.2)
+#
+# @yres: vertical resolution of the output in pixels (since 10.2)

(since 11.0)

Quoted 10 lines
qapi/virtio.json +2 -1
+#
 # Since: 10.1
 ##
 
 { 'struct': 'VirtIOGPUOutput',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*xres': 'uint16', '*yres': 'uint16' } }
 
 ##
 # @DummyVirtioForceArrays: