dxgi: track damage per output and translate it into atlas space
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 21s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / module (push) Failing after 16s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / host-linux (push) Failing after 19s
build / host-windows-cross (push) Failing after 19s
build / obs (clang) (push) Failing after 20s
build / docs (push) Failing after 3s
build / obs (gcc) (push) Failing after 20s
build / idd (push) Canceled after 0s
build / host-windows-native (push) Canceled after 0s

Damage is now gathered from every output that presented this cycle rather
than reporting the whole frame. An output that did not present contributes
nothing, so a static monitor costs no transfer at all — which matters when
the atlas is tens of megabytes and only one display is moving.

The translation clips each rectangle to the display it came from, so one
output's damage can never reach into another's part of the atlas, and
scaling is applied after placement since the downscale applies to the frame
as a whole. If the combined damage cannot be described the count is left at
zero, meaning full damage: redrawing too much only costs time, whereas
redrawing too little leaves stale pixels on screen.

lgDisplaysRectToAtlas is in common and unit tested, including a sweep of
awkward inputs asserting no translated rectangle ever escapes its display.
The DXGI plumbing around it still needs hardware.
This commit is contained in:
donny committed 2026-07-28 08:43:57 +00:00
1 parent e425b15a87
commit e582faed84
12 files changed
+253 -24

No files matched your search

+71
View File
@@ -183,6 +183,76 @@ static void testRepack(void)
free(src);
}
/* Damage rectangles arrive in a display's own coordinates. Getting the
* translation into atlas space wrong is uniquely nasty: it does not crash, it
* silently redraws the wrong region, leaving stale pixels on screen. */
static void testDamageTranslation(void)
{
printf("\n== damage translation ==\n");
/* a display parked away from the atlas origin, so an offset that is
* forgotten or applied twice is visible */
const KVMFRDisplay d =
{
.atlasX = 1000, .atlasY = 500,
.atlasWidth = 800, .atlasHeight = 600,
.desktopX = 0, .desktopY = 0,
.desktopWidth = 800, .desktopHeight = 600
};
FrameDamageRect r;
check(lgDisplaysRectToAtlas(&d, 0, 0, 800, 600, &r) &&
r.x == 1000 && r.y == 500 && r.width == 800 && r.height == 600,
"a full display rect maps to the whole atlas region");
check(lgDisplaysRectToAtlas(&d, 10, 20, 30, 40, &r) &&
r.x == 1010 && r.y == 520 && r.width == 30 && r.height == 40,
"an interior rect is offset by the display's atlas position");
// a rect running past the display must not bleed into its neighbour
check(lgDisplaysRectToAtlas(&d, 700, 500, 400, 400, &r) &&
r.x == 1700 && r.y == 1000 && r.width == 100 && r.height == 100,
"a rect overhanging the display is clipped to it");
check(lgDisplaysRectToAtlas(&d, -50, -50, 100, 100, &r) &&
r.x == 1000 && r.y == 500 && r.width == 50 && r.height == 50,
"a rect starting before the origin is clipped");
check(!lgDisplaysRectToAtlas(&d, 800, 0, 10, 10, &r),
"a rect entirely past the right edge is dropped");
check(!lgDisplaysRectToAtlas(&d, 0, 600, 10, 10, &r),
"a rect entirely past the bottom edge is dropped");
check(!lgDisplaysRectToAtlas(&d, -100, 0, 50, 10, &r),
"a rect entirely before the left edge is dropped");
check(!lgDisplaysRectToAtlas(&d, 0, 0, 0, 10, &r),
"a zero width rect is dropped");
check(!lgDisplaysRectToAtlas(&d, 0, 0, 10, -5, &r),
"a negative height rect is dropped");
/* Every translated rect must stay inside the display's atlas region.
* Sweep a range of awkward inputs and assert containment. */
bool contained = true;
for(int x = -900; x <= 900 && contained; x += 37)
for(int y = -700; y <= 700; y += 29)
for(int w = 1; w <= 1600; w += 311)
{
if (!lgDisplaysRectToAtlas(&d, x, y, w, w, &r))
continue;
if (r.x < d.atlasX || r.y < d.atlasY ||
r.x + r.width > d.atlasX + d.atlasWidth ||
r.y + r.height > d.atlasY + d.atlasHeight)
{
printf(" escaped at %d,%d %dx%d -> %u,%u %ux%u\n",
x, y, w, w, r.x, r.y, r.width, r.height);
contained = false;
break;
}
}
check(contained, "no translated rect ever escapes its display's region");
}
int main(void)
{
debug_init();
@@ -284,6 +354,7 @@ int main(void)
}
testRepack();
testDamageTranslation();
printf("\n%s (%d failure%s)\n", failures ? "FAILED" : "ALL PASSED",
failures, failures == 1 ? "" : "s");