common: consider every subset sum as a candidate shelf width
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 20s
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 21s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 19s
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 19s
build / host-linux (push) Failing after 20s
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 21s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s

Only trying running totals in packing order missed layouts where the
displays sharing a shelf are not the first few. A 4K above two 1440p side
by side is the common case: the 4K sorts first by height but belongs on a
shelf of its own, so the useful width is the sum of the other two.

For that arrangement the atlas drops from 3840x5040 to 5120x3600, about
5% fewer pixels per frame. With at most 8 displays this is 255 subsets,
so the extra search costs nothing.
This commit is contained in:
donny committed 2026-07-28 08:23:22 +00:00
1 parent b73ffa1b33
commit 76207dce41
8 files changed
+56 -18

No files matched your search

+32 -15
View File
@@ -126,29 +126,46 @@ bool lgDisplaysPack(
order[j] = v;
}
unsigned maxWidth = 0, totalWidth = 0;
unsigned maxWidth = 0;
for(unsigned i = 0; i < count; ++i)
{
if (in[i].width > maxWidth)
maxWidth = in[i].width;
totalWidth += in[i].width;
}
/* Candidate shelf widths: the widest single display (a pure vertical stack),
* every running total in packing order (which produces the natural "N per
* row" arrangements), and the sum of all widths (a single row). Every
* candidate is at least maxWidth so no display is ever too wide to place. */
unsigned candidates[KVMFR_MAX_DISPLAYS + 2];
/* Candidate shelf widths: the total width of every subset of displays.
*
* Any shelf is some set of displays sitting side by side, so its width is a
* subset sum; enumerating them covers every arrangement worth trying. Only
* considering running totals in packing order misses layouts where the
* displays that share a shelf are not the first few — a 4K above two 1440p
* side by side, for instance, since the 4K sorts first but belongs alone.
*
* With at most 8 displays this is 255 subsets, which costs nothing. Every
* candidate is raised to maxWidth so no display is ever too wide to place. */
unsigned candidates[1u << KVMFR_MAX_DISPLAYS];
unsigned candidateCount = 0;
candidates[candidateCount++] = maxWidth;
unsigned running = 0;
for(unsigned i = 0; i < count; ++i)
for(uint32_t mask = 1; mask < (1u << count); ++mask)
{
running += in[order[i]].width;
candidates[candidateCount++] = running < maxWidth ? maxWidth : running;
unsigned width = 0;
for(unsigned i = 0; i < count; ++i)
if (mask & (1u << i))
width += in[i].width;
if (width < maxWidth)
width = maxWidth;
// duplicates are common when displays share a width, so drop them
bool seen = false;
for(unsigned c = 0; c < candidateCount; ++c)
if (candidates[c] == width)
{
seen = true;
break;
}
if (!seen)
candidates[candidateCount++] = width;
}
candidates[candidateCount++] = totalWidth < maxWidth ? maxWidth : totalWidth;
unsigned bestX[KVMFR_MAX_DISPLAYS], bestY[KVMFR_MAX_DISPLAYS];
unsigned bestWidth = 0, bestHeight = 0;