Skip to contentSkip to conversation

ati-vga: fix ati_set_dirty address calculation

PATCH Applied BALATON Zoltan 3 participants 3 messages May 6 – May 10

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ati-vga: fix ati_set_dirty address calculation

From: Chad Jablonski <[email protected]>

This fixes three bugs with the ati_set_dirty address calculation.

First, vbe_start_addr is a word offset. All other values in the calculation are byte offsets. It must be converted to bytes.

Second, when setting the dirty region with memory_region_set_dirty the vbe_start_addr is used to calculate the start of the dirty region. This is a problem because the vbe_start_addr is the offset at which scan out begins. This puts it in the visible screen coordinate system. The dirty region however is in the virtual screen coordinate system. This can cause both overmarking and missed updates. This is removed from the calculation.

Third, when the start address of a blit is outside of the bounds check the entire blit is missed and not set to dirty. This happens even if the blit does partially overlap with the visible screen. The fix here is to find the intersection of the visible screen and the blit and mark only that region as dirty.

This does not attempt to apply clipping to the blit. So there will be overmarking in some cases.

[balaton: drop excess parenthesis, use offsets instead of pointers]

---
To help moving this forward I've picked it up and made the changes I suggested in review.

 hw/display/ati_2d.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
hw/display/ati_2d.c +17 -7
index 504d1c5708..48498677c7 100644
@@ -69,18 +69,28 @@ typedef struct {
 static void ati_set_dirty(VGACommonState *vga, const ATI2DCtx *ctx)
 {
     DisplaySurface *ds = qemu_console_surface(vga->con);
+    unsigned int bypp = ctx->bpp / 8;
+    hwaddr dirty_start = ctx->dst_offset + ctx->dst.x * bypp +
+                         ctx->dst.y * ctx->dst_stride;
+    hwaddr dirty_end = dirty_start + ctx->dst.width * bypp +
+                       (ctx->dst.height - 1) * ctx->dst_stride;
+    /*
+     * The blit may be outside of the visible screen (e.g. virtual desktops.)
+     * Dirty only the intersection of the visible screen and the blit.
+     */
+    hwaddr vis_start = vga->vbe_start_addr * 4;
+    hwaddr vis_end = vis_start + vga->vbe_regs[VBE_DISPI_INDEX_YRES] *
+                       vga->vbe_line_offset;
+    hwaddr start = MAX(vis_start, dirty_start);
+    hwaddr end = MIN(vis_end, dirty_end);
 
     (void)ds;
     DPRINTF("%p %u ds: %p %d %d rop: %x\n", vga->vram_ptr, vga->vbe_start_addr,
             surface_data(ds), surface_stride(ds), surface_bits_per_pixel(ds),
             ctx->rop3 >> 16);
-    if (ctx->dst_bits >= vga->vram_ptr + vga->vbe_start_addr &&
-        ctx->dst_bits < vga->vram_ptr + vga->vbe_start_addr +
-        vga->vbe_regs[VBE_DISPI_INDEX_YRES] * vga->vbe_line_offset) {
-        memory_region_set_dirty(&vga->vram,
-                                vga->vbe_start_addr + ctx->dst_offset +
-                                ctx->dst.y * ctx->dst_stride,
-                                ctx->dst.height * ctx->dst_stride);
+
+    if (start < end) {
+        memory_region_set_dirty(&vga->vram, start, end - start);
     }
 }
 
Signature · 1 line
2.41.3
#1 lore raw
Quoted 23 lines · BALATON Zoltan

From: Chad Jablonski <[email protected]>

This fixes three bugs with the ati_set_dirty address calculation.

First, vbe_start_addr is a word offset. All other values in the calculation are byte offsets. It must be converted to bytes.

Second, when setting the dirty region with memory_region_set_dirty the vbe_start_addr is used to calculate the start of the dirty region. This is a problem because the vbe_start_addr is the offset at which scan out begins. This puts it in the visible screen coordinate system. The dirty region however is in the virtual screen coordinate system. This can cause both overmarking and missed updates. This is removed from the calculation.

Third, when the start address of a blit is outside of the bounds check the entire blit is missed and not set to dirty. This happens even if the blit does partially overlap with the visible screen. The fix here is to find the intersection of the visible screen and the blit and mark only that region as dirty.

This does not attempt to apply clipping to the blit. So there will be overmarking in some cases.

Quoted 6 lines
[balaton: drop excess parenthesis, use offsets instead of pointers]

---

Queued, thanks.

#2 lore raw

Thanks Zoltan for the v3. I was away for a bit there. Glad to see it queued. Thank you Philippe.