From de1b9b85eff3dca42fe2cabe6e026cd2a2d5c769 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 8 Jun 2016 14:40:48 +0200 Subject: [PATCH 1/9] qxl: use uint64_t for vram size This allows for the 64bit vram bar to become larger than 2G (try -device qxl-vga,vram64_size_mb=8192). https://bugzilla.redhat.com/show_bug.cgi?id=1340439 Signed-off-by: Gerd Hoffmann Message-id: 1465389648-5179-1-git-send-email-kraxel@redhat.com --- hw/display/qxl.c | 8 ++++---- hw/display/qxl.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 919dc5cd36..ab96f24a02 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1914,7 +1914,7 @@ static void qxl_init_ramsize(PCIQXLDevice *qxl) /* vram (surfaces, 64bit, bar 4+5) */ if (qxl->vram_size_mb != -1) { - qxl->vram_size = qxl->vram_size_mb * 1024 * 1024; + qxl->vram_size = (uint64_t)qxl->vram_size_mb * 1024 * 1024; } if (qxl->vram_size < qxl->vram32_size) { qxl->vram_size = qxl->vram32_size; @@ -2020,9 +2020,9 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp) dprint(qxl, 1, "ram/%s: %d MB [region 0]\n", qxl->id == 0 ? "pri" : "sec", qxl->vga.vram_size / (1024*1024)); - dprint(qxl, 1, "vram/32: %d MB [region 1]\n", + dprint(qxl, 1, "vram/32: %" PRIx64 "d MB [region 1]\n", qxl->vram32_size / (1024*1024)); - dprint(qxl, 1, "vram/64: %d MB %s\n", + dprint(qxl, 1, "vram/64: %" PRIx64 "d MB %s\n", qxl->vram_size / (1024*1024), qxl->vram32_size < qxl->vram_size ? "[region 4]" : "[unmapped]"); @@ -2276,7 +2276,7 @@ static VMStateDescription qxl_vmstate = { static Property qxl_properties[] = { DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size, 64 * 1024 * 1024), - DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram32_size, + DEFINE_PROP_UINT64("vram_size", PCIQXLDevice, vram32_size, 64 * 1024 * 1024), DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision, QXL_DEFAULT_REVISION), diff --git a/hw/display/qxl.h b/hw/display/qxl.h index 2ddf065e1f..39ff00407d 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -104,9 +104,9 @@ typedef struct PCIQXLDevice { #endif /* vram pci bar */ - uint32_t vram_size; + uint64_t vram_size; MemoryRegion vram_bar; - uint32_t vram32_size; + uint64_t vram32_size; MemoryRegion vram32_bar; /* io bar */ From 2f5ae772c62499873a0da8fffa03594753eb8fa8 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 8 Jun 2016 16:11:41 +0200 Subject: [PATCH 2/9] qxl: handle no updates in interface_update_area_complete Simply return early in case there are no updated rects. Signed-off-by: Gerd Hoffmann Message-id: 1465395101-13580-1-git-send-email-kraxel@redhat.com --- hw/display/qxl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index ab96f24a02..47cc6f478a 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -893,7 +893,8 @@ static void interface_update_area_complete(QXLInstance *sin, int qxl_i; qemu_mutex_lock(&qxl->ssd.lock); - if (surface_id != 0 || !qxl->render_update_cookie_num) { + if (surface_id != 0 || !num_updated_rects || + !qxl->render_update_cookie_num) { qemu_mutex_unlock(&qxl->ssd.lock); return; } From 726bdf653aca9b87e28c9a56dd94c4667ddfacbc Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 22 Jun 2016 14:07:22 +0200 Subject: [PATCH 3/9] qxl: factor out qxl_get_check_slot_offset New helper function which translates a qxl physical address into memory slot and offset. Also applies sanity checks. Factored out from qxl_phys2virt. No functional change. Signed-off-by: Gerd Hoffmann Message-id: 1466597244-5938-1-git-send-email-kraxel@redhat.com --- hw/display/qxl.c | 59 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 47cc6f478a..2ea4e3bc7a 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1338,36 +1338,53 @@ static void qxl_reset_surfaces(PCIQXLDevice *d) } /* can be also called from spice server thread context */ -void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id) +static bool qxl_get_check_slot_offset(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, + uint32_t *s, uint64_t *o) { uint64_t phys = le64_to_cpu(pqxl); uint32_t slot = (phys >> (64 - 8)) & 0xff; uint64_t offset = phys & 0xffffffffffff; - switch (group_id) { - case MEMSLOT_GROUP_HOST: - return (void *)(intptr_t)offset; - case MEMSLOT_GROUP_GUEST: - if (slot >= NUM_MEMSLOTS) { - qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot, - NUM_MEMSLOTS); - return NULL; - } - if (!qxl->guest_slots[slot].active) { - qxl_set_guest_bug(qxl, "inactive slot %d\n", slot); - return NULL; - } - if (offset < qxl->guest_slots[slot].delta) { - qxl_set_guest_bug(qxl, + if (slot >= NUM_MEMSLOTS) { + qxl_set_guest_bug(qxl, "slot too large %d >= %d", slot, + NUM_MEMSLOTS); + return false; + } + if (!qxl->guest_slots[slot].active) { + qxl_set_guest_bug(qxl, "inactive slot %d\n", slot); + return false; + } + if (offset < qxl->guest_slots[slot].delta) { + qxl_set_guest_bug(qxl, "slot %d offset %"PRIu64" < delta %"PRIu64"\n", slot, offset, qxl->guest_slots[slot].delta); - return NULL; - } - offset -= qxl->guest_slots[slot].delta; - if (offset > qxl->guest_slots[slot].size) { - qxl_set_guest_bug(qxl, + return false; + } + offset -= qxl->guest_slots[slot].delta; + if (offset > qxl->guest_slots[slot].size) { + qxl_set_guest_bug(qxl, "slot %d offset %"PRIu64" > size %"PRIu64"\n", slot, offset, qxl->guest_slots[slot].size); + return false; + } + + *s = slot; + *o = offset; + return true; +} + +/* can be also called from spice server thread context */ +void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id) +{ + uint64_t offset; + uint32_t slot; + + switch (group_id) { + case MEMSLOT_GROUP_HOST: + offset = le64_to_cpu(pqxl) & 0xffffffffffff; + return (void *)(intptr_t)offset; + case MEMSLOT_GROUP_GUEST: + if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) { return NULL; } return qxl->guest_slots[slot].ptr + offset; From 3cb5158f15604a9f50287f2f06777d5835ff4c15 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 22 Jun 2016 14:07:23 +0200 Subject: [PATCH 4/9] qxl: store memory region and offset instead of pointer for guest slots Store MemoryRegion and offset instead of a pointer for each qxl memory slot, so we can easily figure in which memory region an qxl object stored. Signed-off-by: Gerd Hoffmann Message-id: 1466597244-5938-2-git-send-email-kraxel@redhat.com --- hw/display/qxl.c | 15 +++++++++++---- hw/display/qxl.h | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 2ea4e3bc7a..8101f698a1 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1244,6 +1244,7 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta, int pci_region; pcibus_t pci_start; pcibus_t pci_end; + MemoryRegion *mr; intptr_t virt_start; QXLDevMemSlot memslot; int i; @@ -1290,11 +1291,11 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta, switch (pci_region) { case QXL_RAM_RANGE_INDEX: - virt_start = (intptr_t)memory_region_get_ram_ptr(&d->vga.vram); + mr = &d->vga.vram; break; case QXL_VRAM_RANGE_INDEX: case 4 /* vram 64bit */: - virt_start = (intptr_t)memory_region_get_ram_ptr(&d->vram_bar); + mr = &d->vram_bar; break; default: /* should not happen */ @@ -1302,6 +1303,7 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta, return 1; } + virt_start = (intptr_t)memory_region_get_ram_ptr(mr); memslot.slot_id = slot_id; memslot.slot_group_id = MEMSLOT_GROUP_GUEST; /* guest group */ memslot.virt_start = virt_start + (guest_start - pci_start); @@ -1311,7 +1313,8 @@ static int qxl_add_memslot(PCIQXLDevice *d, uint32_t slot_id, uint64_t delta, qxl_rom_set_dirty(d); qemu_spice_add_memslot(&d->ssd, &memslot, async); - d->guest_slots[slot_id].ptr = (void*)memslot.virt_start; + d->guest_slots[slot_id].mr = mr; + d->guest_slots[slot_id].offset = memslot.virt_start - virt_start; d->guest_slots[slot_id].size = memslot.virt_end - memslot.virt_start; d->guest_slots[slot_id].delta = delta; d->guest_slots[slot_id].active = 1; @@ -1378,6 +1381,7 @@ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id) { uint64_t offset; uint32_t slot; + void *ptr; switch (group_id) { case MEMSLOT_GROUP_HOST: @@ -1387,7 +1391,10 @@ void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, int group_id) if (!qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset)) { return NULL; } - return qxl->guest_slots[slot].ptr + offset; + ptr = memory_region_get_ram_ptr(qxl->guest_slots[slot].mr); + ptr += qxl->guest_slots[slot].offset; + ptr += offset; + return ptr; } return NULL; } diff --git a/hw/display/qxl.h b/hw/display/qxl.h index 39ff00407d..fdb619d4a7 100644 --- a/hw/display/qxl.h +++ b/hw/display/qxl.h @@ -53,7 +53,8 @@ typedef struct PCIQXLDevice { struct guest_slots { QXLMemSlot slot; - void *ptr; + MemoryRegion *mr; + uint64_t offset; uint64_t size; uint64_t delta; uint32_t active; From 1331eab216c9dc4e50a48a34d14926b31a7fd611 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 22 Jun 2016 14:07:24 +0200 Subject: [PATCH 5/9] qxl: fix surface migration Create a helper function qxl_dirty_one_surface() to mark a single qxl surface as dirty. Use the new qxl_get_check_slot_offset function and lookup the memory region from the slot instead of assuming the surface is stored in vram. Use the new helper function in qxl_dirty_surfaces, for both primary and off-screen surfaces. For off-screen surfaces this is no functional change. For primary surfaces this will dirty only the memory actually used instead of the whole surface0 region. It will also work correctly in case the guest places the primary surface in vram instead of the surface0 region (linux kms driver does that). https://bugzilla.redhat.com/show_bug.cgi?id=1235732 Signed-off-by: Gerd Hoffmann Message-id: 1466597244-5938-3-git-send-email-kraxel@redhat.com --- hw/display/qxl.c | 37 +++++++++++++++++++++---------------- hw/display/trace-events | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 8101f698a1..65a3653898 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -1809,9 +1809,23 @@ static void qxl_hw_update(void *opaque) qxl_render_update(qxl); } +static void qxl_dirty_one_surface(PCIQXLDevice *qxl, QXLPHYSICAL pqxl, + uint32_t height, int32_t stride) +{ + uint64_t offset; + uint32_t slot, size; + bool rc; + + rc = qxl_get_check_slot_offset(qxl, pqxl, &slot, &offset); + assert(rc == true); + size = height * abs(stride); + trace_qxl_surfaces_dirty(qxl->id, (int)offset, size); + qxl_set_dirty(qxl->guest_slots[slot].mr, + qxl->guest_slots[slot].offset + offset, size); +} + static void qxl_dirty_surfaces(PCIQXLDevice *qxl) { - uintptr_t vram_start; int i; if (qxl->mode != QXL_MODE_NATIVE && qxl->mode != QXL_MODE_COMPAT) { @@ -1819,16 +1833,13 @@ static void qxl_dirty_surfaces(PCIQXLDevice *qxl) } /* dirty the primary surface */ - qxl_set_dirty(&qxl->vga.vram, qxl->shadow_rom.draw_area_offset, - qxl->shadow_rom.surface0_area_size); - - vram_start = (uintptr_t)memory_region_get_ram_ptr(&qxl->vram_bar); + qxl_dirty_one_surface(qxl, qxl->guest_primary.surface.mem, + qxl->guest_primary.surface.height, + qxl->guest_primary.surface.stride); /* dirty the off-screen surfaces */ for (i = 0; i < qxl->ssd.num_surfaces; i++) { QXLSurfaceCmd *cmd; - intptr_t surface_offset; - int surface_size; if (qxl->guest_surfaces.cmds[i] == 0) { continue; @@ -1838,15 +1849,9 @@ static void qxl_dirty_surfaces(PCIQXLDevice *qxl) MEMSLOT_GROUP_GUEST); assert(cmd); assert(cmd->type == QXL_SURFACE_CMD_CREATE); - surface_offset = (intptr_t)qxl_phys2virt(qxl, - cmd->u.surface_create.data, - MEMSLOT_GROUP_GUEST); - assert(surface_offset); - surface_offset -= vram_start; - surface_size = cmd->u.surface_create.height * - abs(cmd->u.surface_create.stride); - trace_qxl_surfaces_dirty(qxl->id, i, (int)surface_offset, surface_size); - qxl_set_dirty(&qxl->vram_bar, surface_offset, surface_size); + qxl_dirty_one_surface(qxl, cmd->u.surface_create.data, + cmd->u.surface_create.height, + cmd->u.surface_create.stride); } } diff --git a/hw/display/trace-events b/hw/display/trace-events index 30bebffd8b..9dd82cecde 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -105,7 +105,7 @@ qxl_spice_reset_image_cache(int qid) "%d" qxl_spice_reset_memslots(int qid) "%d" qxl_spice_update_area(int qid, uint32_t surface_id, uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) "%d sid=%d [%d,%d,%d,%d]" qxl_spice_update_area_rest(int qid, uint32_t num_dirty_rects, uint32_t clear_dirty_region) "%d #d=%d clear=%d" -qxl_surfaces_dirty(int qid, int surface, int offset, int size) "%d surface=%d offset=%d size=%d" +qxl_surfaces_dirty(int qid, int offset, int size) "%d offset=%d size=%d" qxl_send_events(int qid, uint32_t events) "%d %d" qxl_send_events_vm_stopped(int qid, uint32_t events) "%d %d" qxl_set_guest_bug(int qid) "%d" From 015e02f88071cfedd6bc6f910af5a388462aec6b Mon Sep 17 00:00:00 2001 From: John Snow Date: Wed, 29 Jun 2016 18:41:35 -0400 Subject: [PATCH 6/9] spice: avoid .set_mm_time on >= 0.12.6 Spice deprecated this callback in 0.12.6. It's not a problem yet, but it will cause Clang to fail in a -Werror build due to the deprecated tag. Signed-off-by: John Snow Message-id: 1467240095-12507-2-git-send-email-jsnow@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/qxl.c | 4 ++++ include/ui/qemu-spice.h | 3 +++ ui/spice-display.c | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 65a3653898..46cc86690c 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -504,6 +504,7 @@ static void interface_set_compression_level(QXLInstance *sin, int level) qxl_rom_set_dirty(qxl); } +#if SPICE_NEEDS_SET_MM_TIME static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) { PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl); @@ -517,6 +518,7 @@ static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) qxl->rom->mm_clock = cpu_to_le32(mm_time); qxl_rom_set_dirty(qxl); } +#endif static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info) { @@ -1069,7 +1071,9 @@ static const QXLInterface qxl_interface = { .attache_worker = interface_attach_worker, .set_compression_level = interface_set_compression_level, +#if SPICE_NEEDS_SET_MM_TIME .set_mm_time = interface_set_mm_time, +#endif .get_init_info = interface_get_init_info, /* the callbacks below are called from spice server thread context */ diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h index 57ac91b921..edad5e7bbf 100644 --- a/include/ui/qemu-spice.h +++ b/include/ui/qemu-spice.h @@ -42,6 +42,9 @@ int qemu_spice_set_pw_expire(time_t expires); int qemu_spice_migrate_info(const char *hostname, int port, int tls_port, const char *subject); +#define SPICE_NEEDS_SET_MM_TIME \ + (!defined(SPICE_SERVER_VERSION) || (SPICE_SERVER_VERSION < 0xc06)) + #if SPICE_SERVER_VERSION >= 0x000c02 void qemu_spice_register_ports(void); #else diff --git a/ui/spice-display.c b/ui/spice-display.c index 34095fbc8c..8644a73d5d 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -527,11 +527,13 @@ static void interface_set_compression_level(QXLInstance *sin, int level) /* nothing to do */ } +#if SPICE_NEEDS_SET_MM_TIME static void interface_set_mm_time(QXLInstance *sin, uint32_t mm_time) { dprint(3, "%s/%d:\n", __func__, sin->id); /* nothing to do */ } +#endif static void interface_get_init_info(QXLInstance *sin, QXLDevInitInfo *info) { @@ -718,7 +720,9 @@ static const QXLInterface dpy_interface = { .attache_worker = interface_attach_worker, .set_compression_level = interface_set_compression_level, +#if SPICE_NEEDS_SET_MM_TIME .set_mm_time = interface_set_mm_time, +#endif .get_init_info = interface_get_init_info, /* the callbacks below are called from spice server thread context */ From c540128f93e17141c63d41a8eb77bde80a2fc752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 14 Jun 2016 15:44:07 +0200 Subject: [PATCH 7/9] virgl: count the calls to gl_block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In virgl_cmd_resource_flush(), when several consoles are updated, it needs to keep blocking until all spice gl draws are done. This fixes an assert() in spice when using multiple monitors with virgl. Signed-off-by: Marc-André Lureau Message-id: 1465911849-30423-2-git-send-email-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu.c | 10 ++++++++-- include/hw/virtio/virtio-gpu.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 136c095b7d..f8b0274752 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -934,8 +934,14 @@ static void virtio_gpu_gl_block(void *opaque, bool block) { VirtIOGPU *g = opaque; - g->renderer_blocked = block; - if (!block) { + if (block) { + g->renderer_blocked++; + } else { + g->renderer_blocked--; + } + assert(g->renderer_blocked >= 0); + + if (g->renderer_blocked == 0) { virtio_gpu_process_cmdq(g); } } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 89f4879f55..3dff0c9a76 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -107,7 +107,7 @@ typedef struct VirtIOGPU { bool use_virgl_renderer; bool renderer_inited; - bool renderer_blocked; + int renderer_blocked; QEMUTimer *fence_poll; QEMUTimer *print_stats; From c61d8126fcdc1c70581be55d0082f4510e9cfb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 14 Jun 2016 15:44:08 +0200 Subject: [PATCH 8/9] spice: use the right head for multi-monitor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Look up the associated head monitor config. Signed-off-by: Marc-André Lureau Message-id: 1465911849-30423-3-git-send-email-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- ui/spice-display.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 8644a73d5d..67e50e9a84 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -688,6 +688,7 @@ static int interface_client_monitors_config(QXLInstance *sin, { SimpleSpiceDisplay *ssd = container_of(sin, SimpleSpiceDisplay, qxl); QemuUIInfo info; + int head; if (!dpy_ui_info_supported(ssd->dcl.con)) { return 0; /* == not supported by guest */ @@ -697,14 +698,12 @@ static int interface_client_monitors_config(QXLInstance *sin, return 1; } - /* - * FIXME: multihead is tricky due to the way - * spice has multihead implemented. - */ memset(&info, 0, sizeof(info)); - if (mc->num_of_monitors > 0) { - info.width = mc->monitors[0].width; - info.height = mc->monitors[0].height; + + head = qemu_console_get_head(ssd->dcl.con); + if (mc->num_of_monitors > head) { + info.width = mc->monitors[head].width; + info.height = mc->monitors[head].height; } dpy_set_ui_info(ssd->dcl.con, &info); dprint(1, "%s/%d: size %dx%d\n", __func__, ssd->qxl.id, From 9d8256ebc0ef88fb1f35d0405893962d20cc10ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 14 Jun 2016 15:44:09 +0200 Subject: [PATCH 9/9] virgl: pass whole GL scanout dimensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Spice client needs the whole GL texture dimension to be able to show a scanout with a monitor offset (different than +0+0). Furthermore, this fixes a crash when calling surface_{width,height}() after dpy_gfx_replace_surface(con, NULL) was called in virgl_cmd_set_scanout() Signed-off-by: Marc-André Lureau Message-id: 1465911849-30423-4-git-send-email-marcandre.lureau@redhat.com Signed-off-by: Gerd Hoffmann --- hw/display/virtio-gpu-3d.c | 5 +++-- include/ui/console.h | 2 ++ include/ui/gtk.h | 1 + include/ui/sdl2.h | 1 + ui/console.c | 2 ++ ui/gtk-egl.c | 1 + ui/sdl2-gl.c | 1 + ui/spice-display.c | 6 +++--- 8 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/display/virtio-gpu-3d.c b/hw/display/virtio-gpu-3d.c index 29918a090b..d6c8c6e2dc 100644 --- a/hw/display/virtio-gpu-3d.c +++ b/hw/display/virtio-gpu-3d.c @@ -171,13 +171,14 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, virgl_renderer_force_ctx_0(); dpy_gl_scanout(g->scanout[ss.scanout_id].con, info.tex_id, info.flags & 1 /* FIXME: Y_0_TOP */, + info.width, info.height, ss.r.x, ss.r.y, ss.r.width, ss.r.height); } else { if (ss.scanout_id != 0) { dpy_gfx_replace_surface(g->scanout[ss.scanout_id].con, NULL); } dpy_gl_scanout(g->scanout[ss.scanout_id].con, 0, false, - 0, 0, 0, 0); + 0, 0, 0, 0, 0, 0); } g->scanout[ss.scanout_id].resource_id = ss.resource_id; } @@ -580,7 +581,7 @@ void virtio_gpu_virgl_reset(VirtIOGPU *g) if (i != 0) { dpy_gfx_replace_surface(g->scanout[i].con, NULL); } - dpy_gl_scanout(g->scanout[i].con, 0, false, 0, 0, 0, 0); + dpy_gl_scanout(g->scanout[i].con, 0, false, 0, 0, 0, 0, 0, 0); } } diff --git a/include/ui/console.h b/include/ui/console.h index 7c1fdbad6f..2703a3aa5a 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -217,6 +217,7 @@ typedef struct DisplayChangeListenerOps { void (*dpy_gl_scanout)(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void (*dpy_gl_update)(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); @@ -285,6 +286,7 @@ bool dpy_gfx_check_format(QemuConsole *con, void dpy_gl_scanout(QemuConsole *con, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void dpy_gl_update(QemuConsole *con, uint32_t x, uint32_t y, uint32_t w, uint32_t h); diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 2bf60f3ec5..a7644046e4 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -101,6 +101,7 @@ QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl, QEMUGLParams *params); void gd_egl_scanout(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void gd_egl_scanout_flush(DisplayChangeListener *dcl, diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h index 3f0b57bb16..683bb6af2e 100644 --- a/include/ui/sdl2.h +++ b/include/ui/sdl2.h @@ -64,6 +64,7 @@ QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl); void sdl2_gl_scanout(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, diff --git a/ui/console.c b/ui/console.c index ce1e10570f..c24bfe422d 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1709,11 +1709,13 @@ QEMUGLContext dpy_gl_ctx_get_current(QemuConsole *con) void dpy_gl_scanout(QemuConsole *con, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { assert(con->gl); con->gl->ops->dpy_gl_scanout(con->gl, backing_id, backing_y_0_top, + backing_width, backing_height, x, y, width, height); } diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 431457c746..3f5d328c7b 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -172,6 +172,7 @@ QEMUGLContext gd_egl_create_context(DisplayChangeListener *dcl, void gd_egl_scanout(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index a324ecacac..039645df3e 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -186,6 +186,7 @@ QEMUGLContext sdl2_gl_get_current_context(DisplayChangeListener *dcl) void sdl2_gl_scanout(DisplayChangeListener *dcl, uint32_t backing_id, bool backing_y_0_top, + uint32_t backing_width, uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { diff --git a/ui/spice-display.c b/ui/spice-display.c index 67e50e9a84..99132b69b6 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -861,6 +861,8 @@ static QEMUGLContext qemu_spice_gl_create_context(DisplayChangeListener *dcl, static void qemu_spice_gl_scanout(DisplayChangeListener *dcl, uint32_t tex_id, bool y_0_top, + uint32_t backing_width, + uint32_t backing_height, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { @@ -883,9 +885,7 @@ static void qemu_spice_gl_scanout(DisplayChangeListener *dcl, assert(!tex_id || fd >= 0); /* note: spice server will close the fd */ - spice_qxl_gl_scanout(&ssd->qxl, fd, - surface_width(ssd->ds), - surface_height(ssd->ds), + spice_qxl_gl_scanout(&ssd->qxl, fd, backing_width, backing_height, stride, fourcc, y_0_top); qemu_spice_gl_monitor_config(ssd, x, y, w, h);