Skip to contentSkip to conversation

Support per-head resolutions with virtio-gpu

PATCH Superseded Andrew Keesler 2 participants 7 messages Jul 22, 2025 – Aug 28, 2025

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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
              }
            ]}'

If no virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected, preserving backwards compatibility.

Otherwise, if any virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres will take precedence. In this case, virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres must be non-zero.

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

 hw/display/virtio-gpu-base.c | 12 ++++++++++++
 qapi/virtio.json             |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#1 lore raw

PATCH 1/1 hw/display: 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
              }
            ]}'

If no virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected, preserving backwards compatibility.

Otherwise, if any virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres will take precedence. In this case, virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres must be non-zero.

---
 hw/display/virtio-gpu-base.c | 12 ++++++++++++
 qapi/virtio.json             |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-base.c +12 -0
index 7269477a1c..1fc879cc93 100644
@@ -206,6 +206,10 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
                        node->value->name, EDID_NAME_MAX_LENGTH);
             return false;
         }
+        if (node->value && !(node->value->xres && node->value->yres)) {
+            error_setg(errp, "invalid resolution == 0");
+            return false;
+        }
     }
 
     if (virtio_gpu_virgl_enabled(g->conf)) {
@@ -233,6 +237,14 @@ 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) {
+        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 +5 -1
index 9d652fe4a8..36581690c7 100644
@@ -970,11 +970,15 @@
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels
+#
+# @yres: vertical resolution of the output in pixels
+#
 # Since: 10.1
 ##
 
 { 'struct': 'VirtIOGPUOutput',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', 'xres': 'uint16', 'yres': 'uint16' } }
 
 ##
 # @DummyVirtioForceArrays:
Signature · 1 line
2.50.0.727.gbf7dc18ff4-goog
#2 lore raw

Re: [PATCH 1/1] hw/display: Support per-head resolutions with virtio-gpu

Quoted 26 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
              }
            ]}'
Quoted 3 lines

If no virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected, preserving backwards compatibility.

IIUC from the current code, xres/yres are only set against the first head. The 2nd and later heads are left undefined by the virtio-gpu-base code at least - I'm unclear if something else in QEMU will fill in defaults later, or if they set to 0x0.

Quoted 5 lines

Otherwise, if any virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres will take precedence. In this case, virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres must be non-zero.

Makes sense.

Quoted 22 lines
---
 hw/display/virtio-gpu-base.c | 12 ++++++++++++
 qapi/virtio.json             |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-base.c +4 -0
index 7269477a1c..1fc879cc93 100644
@@ -206,6 +206,10 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
                        node->value->name, EDID_NAME_MAX_LENGTH);
             return false;
         }
+        if (node->value && !(node->value->xres && node->value->yres)) {
+            error_setg(errp, "invalid resolution == 0");
+            return false;
+        }
     }
 
     if (virtio_gpu_virgl_enabled(g->conf)) {

hw/display/virtio-gpu-base.c virtio_gpu_base_device_realize(DeviceState *qdev, · line 243

Quoted 7 lines
hw/display/virtio-gpu-base.c +4 -0
@@ -233,6 +237,14 @@ 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) {
+        g->enabled_output_bitmask |= (1 << output_idx);

This change means that all heads are enabled by default if the 'outputs' property array is set, which is a semantic difference from the previous behaviour before xres/yres are added as properties.

Is it relevant to set xres/yres on outputs, even when they are not (yet) enabled ? Perhaps we should have an explicit 'enabled: bool' property in the 'outputs' struct ?

hw/display/virtio-gpu-base.c virtio_gpu_base_device_realize(DeviceState *qdev, · line 246

Quoted 3 lines
hw/display/virtio-gpu-base.c +3 -0
+        g->req_state[output_idx].width = node->value->xres;
+        g->req_state[output_idx].height = node->value->yres;
+    }

For head 0, this is overwriting the defaults set a few lines earlier.

I think we should probably report an error if xres / yres are set at the global level and also set against any individual output, so the two approaches are mutually exclusive.

Quoted 8 lines
hw/display/virtio-gpu-base.c +0 -0
     g->hw_ops = &virtio_gpu_ops;
     for (i = 0; i < g->conf.max_outputs; i++) {
         g->scanout[i].con =
qapi/virtio.json +0 -0
index 9d652fe4a8..36581690c7 100644

qapi/virtio.json line 976

Quoted 7 lines
qapi/virtio.json +4 -0
@@ -970,11 +970,15 @@
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels
+#
+# @yres: vertical resolution of the output in pixels
+#

Sorry, we missed the boat for 10.1, so these two new properties will require an explicit "Since 10.2" tag against them, separate from the overall struct versrion below.

qapi/virtio.json line 981

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

This is a backcompat problem, because xres/yres are mandatory if 'outputs' is present.

$ ./qemu-system-x86_64 -device '{"driver":"virtio-vga","outputs":[{"name":"AAA"},{"name":"BBB"}],"max_outputs":2,"id":"v0"}'
qemu-system-x86_64: -device {"driver":"virtio-vga","outputs":[{"name":"AAA"},{"name":"BBB"}],"max_outputs":2,"id":"v0"}: Parameter 'outputs[0].xres' is missing

These need to be marked optional, to be compatible with existing use of 'outputs' from the 10.1.0 release.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

Re: [PATCH 1/1] hw/display: Support per-head resolutions with virtio-gpu

Sending again (replying all this time).

Quoted 4 lines

IIUC from the current code, xres/yres are only set against the first head. The 2nd and later heads are left undefined by the virtio-gpu-base code at least - I'm unclear if something else in QEMU will fill in defaults later, or if they set to 0x0.

That is correct - xres/yres are only set against the first head in the current code. The wording in my commit message (and cover letter) was misleading. I will fix that to say that "If no virtio_gpu_base_conf.outputs are provided, virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected _for the first head_ for backwards compatibility".

The only way I could get QEMU to fill in xres/yres for a 2nd and later head was to trigger virtio_gpu_ops.ui_info via a VNC client.

Quoted 3 lines

Is it relevant to set xres/yres on outputs, even when they are not (yet) enabled ? Perhaps we should have an explicit 'enabled: bool' property in the 'outputs' struct ?

Maybe you might want to set xres/yres on an output, but not enable it yet? I don't have any concrete examples of when you might want to do that, maybe you have some examples?

I feel like I could see a user setting xres/yres on an output, forgetting to set enabled on that output, and then being confused why their head is blank. Because of this, my vote would be to default to enabling an output when it has configuration. I am easily swayed by your guidance, though.

Quoted 3 lines

I think we should probably report an error if xres / yres are set at the global level and also set against any individual output, so the two approaches are mutually exclusive.

ACK - fixed for the next patch.

Quoted 3 lines

Sorry, we missed the boat for 10.1, so these two new properties will require an explicit "Since 10.2" tag against them, separate from the overall struct versrion below.

ACK - fixed for the next patch.

Quoted 2 lines

This is a backcompat problem, because xres/yres are mandatory if 'outputs' is present.

ACK - fixed for the next patch.

Quoted 143 lines · Daniel P. Berrangé
Quoted 26 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
              }
            ]}'
Quoted 3 lines

If no virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected, preserving backwards compatibility.

IIUC from the current code, xres/yres are only set against the first head. The 2nd and later heads are left undefined by the virtio-gpu-base code at least - I'm unclear if something else in QEMU will fill in defaults later, or if they set to 0x0.

Quoted 5 lines

Otherwise, if any virtio_gpu_base_conf.outputs are provided, then virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres will take precedence. In this case, virtio_gpu_base_conf.outputs.xres/virtio_gpu_base_conf.outputs.yres must be non-zero.

Makes sense.

Quoted 22 lines
---
 hw/display/virtio-gpu-base.c | 12 ++++++++++++
 qapi/virtio.json             |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-base.c +4 -0
index 7269477a1c..1fc879cc93 100644
@@ -206,6 +206,10 @@ virtio_gpu_base_device_realize(DeviceState *qdev,
                        node->value->name, EDID_NAME_MAX_LENGTH);
             return false;
         }
+        if (node->value && !(node->value->xres && node->value->yres)) {
+            error_setg(errp, "invalid resolution == 0");
+            return false;
+        }
     }
 
     if (virtio_gpu_virgl_enabled(g->conf)) {

hw/display/virtio-gpu-base.c virtio_gpu_base_device_realize(DeviceState *qdev, · line 243

Quoted 7 lines
hw/display/virtio-gpu-base.c +4 -0
@@ -233,6 +237,14 @@ 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) {
+        g->enabled_output_bitmask |= (1 << output_idx);

This change means that all heads are enabled by default if the 'outputs' property array is set, which is a semantic difference from the previous behaviour before xres/yres are added as properties.

Is it relevant to set xres/yres on outputs, even when they are not (yet) enabled ? Perhaps we should have an explicit 'enabled: bool' property in the 'outputs' struct ?

hw/display/virtio-gpu-base.c virtio_gpu_base_device_realize(DeviceState *qdev, · line 246

Quoted 3 lines
hw/display/virtio-gpu-base.c +3 -0
+        g->req_state[output_idx].width = node->value->xres;
+        g->req_state[output_idx].height = node->value->yres;
+    }

For head 0, this is overwriting the defaults set a few lines earlier.

I think we should probably report an error if xres / yres are set at the global level and also set against any individual output, so the two approaches are mutually exclusive.

Quoted 8 lines
hw/display/virtio-gpu-base.c +0 -0
     g->hw_ops = &virtio_gpu_ops;
     for (i = 0; i < g->conf.max_outputs; i++) {
         g->scanout[i].con =
qapi/virtio.json +0 -0
index 9d652fe4a8..36581690c7 100644

qapi/virtio.json line 976

Quoted 7 lines
qapi/virtio.json +4 -0
@@ -970,11 +970,15 @@
 #
 # @name: the name of the output
 #
+# @xres: horizontal resolution of the output in pixels
+#
+# @yres: vertical resolution of the output in pixels
+#

Sorry, we missed the boat for 10.1, so these two new properties will require an explicit "Since 10.2" tag against them, separate from the overall struct versrion below.

qapi/virtio.json line 981

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

This is a backcompat problem, because xres/yres are mandatory if 'outputs' is present.

$ ./qemu-system-x86_64 -device
'{"driver":"virtio-vga","outputs":[{"name":"AAA"},{"name":"BBB"}],"max_outputs":2,"id":"v0"}'
qemu-system-x86_64: -device
{"driver":"virtio-vga","outputs":[{"name":"AAA"},{"name":"BBB"}],"max_outputs":2,"id":"v0"}:
Parameter 'outputs[0].xres' is missing

These need to be marked optional, to be compatible with existing use of 'outputs' from the 10.1.0 release.

With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|

#4 lore raw

Re: [PATCH 1/1] hw/display: Support per-head resolutions with virtio-gpu

Quoted 17 lines · Andrew Keesler

Sending again (replying all this time).

Quoted 4 lines

IIUC from the current code, xres/yres are only set against the first head. The 2nd and later heads are left undefined by the virtio-gpu-base code at least - I'm unclear if something else in QEMU will fill in defaults later, or if they set to 0x0.

That is correct - xres/yres are only set against the first head in the current code. The wording in my commit message (and cover letter) was misleading. I will fix that to say that "If no virtio_gpu_base_conf.outputs are provided, virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected _for the first head_ for backwards compatibility".

The only way I could get QEMU to fill in xres/yres for a 2nd and later head was to trigger virtio_gpu_ops.ui_info via a VNC client.

Quoted 7 lines
Quoted 3 lines

Is it relevant to set xres/yres on outputs, even when they are not (yet) enabled ? Perhaps we should have an explicit 'enabled: bool' property in the 'outputs' struct ?

Maybe you might want to set xres/yres on an output, but not enable it yet? I don't have any concrete examples of when you might want to do that, maybe you have some examples?

No, I don't have an example.

Quoted 5 lines

I feel like I could see a user setting xres/yres on an output, forgetting to set enabled on that output, and then being confused why their head is blank. Because of this, my vote would be to default to enabling an output when it has configuration. I am easily swayed by your guidance, though.

Ok, lets just document that setting xres/yres will cause the output to be automatically enabled. We can always retrofit an 'enabled' property at a later date if someone arrives with a use case for setting res without enabling the output.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

Re: [PATCH 1/1] hw/display: Support per-head resolutions with virtio-gpu

Quoted 5 lines
Quoted 3 lines

I think we should probably report an error if xres / yres are set at the global level and also set against any individual output, so the two approaches are mutually exclusive.

ACK - fixed for the next patch.

Doh, I ran into an error. Seems like if I don't set xres/yres, then it gets defaulted to 1280x800.

https://gitlab.com/qemu-project/qemu/-/blob/master/include/hw/virtio/virtio-gpu.h#L175-176

So...could we just get away with documenting that if you set xres/yres and outputs[0].xres/yres, then the later is going to overwrite the former? I'm not sure how to detect if xres/yres has been set globally to 1280x800, or if we are just getting the defaults.

What do you think?

Quoted 50 lines · Daniel P. Berrangé
Quoted 17 lines · Andrew Keesler

Sending again (replying all this time).

Quoted 4 lines

IIUC from the current code, xres/yres are only set against the first head. The 2nd and later heads are left undefined by the virtio-gpu-base code at least - I'm unclear if something else in QEMU will fill in defaults later, or if they set to 0x0.

That is correct - xres/yres are only set against the first head in the current code. The wording in my commit message (and cover letter) was misleading. I will fix that to say that "If no virtio_gpu_base_conf.outputs are provided, virtio_gpu_base_conf.xres/virtio_gpu_base_conf.yres will still be respected _for the first head_ for backwards compatibility".

The only way I could get QEMU to fill in xres/yres for a 2nd and later head was to trigger virtio_gpu_ops.ui_info via a VNC client.

Quoted 7 lines
Quoted 3 lines

Is it relevant to set xres/yres on outputs, even when they are not (yet) enabled ? Perhaps we should have an explicit 'enabled: bool' property in the 'outputs' struct ?

Maybe you might want to set xres/yres on an output, but not enable it yet? I don't have any concrete examples of when you might want to do that, maybe you have some examples?

No, I don't have an example.

Quoted 5 lines

I feel like I could see a user setting xres/yres on an output, forgetting to set enabled on that output, and then being confused why their head is blank. Because of this, my vote would be to default to enabling an output when it has configuration. I am easily swayed by your guidance, though.

Ok, lets just document that setting xres/yres will cause the output to be automatically enabled. We can always retrofit an 'enabled' property at a later date if someone arrives with a use case for setting res without enabling the output.

With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|

#6 lore raw

Re: [PATCH 1/1] hw/display: Support per-head resolutions with virtio-gpu

Quoted 10 lines · Andrew Keesler
Quoted 5 lines
Quoted 3 lines

I think we should probably report an error if xres / yres are set at the global level and also set against any individual output, so the two approaches are mutually exclusive.

ACK - fixed for the next patch.

Doh, I ran into an error. Seems like if I don't set xres/yres, then it gets defaulted to 1280x800.

Quoted 8 lines

https://gitlab.com/qemu-project/qemu/-/blob/master/include/hw/virtio/virtio-gpu.h#L175-176

So...could we just get away with documenting that if you set xres/yres and outputs[0].xres/yres, then the later is going to overwrite the former? I'm not sure how to detect if xres/yres has been set globally to 1280x800, or if we are just getting the defaults.

What do you think?

Oh it probably isn't worth the hassle for a mere error report. Instead just document that per-output takes priority if both are set.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|