Skip to content

Commit f0e2582

Browse files
committed
Improve presentation of the buffer debug widget
1 parent 71f20fe commit f0e2582

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

common/src/main/java/net/caffeinemc/mods/sodium/client/gl/arena/ArenaAggregator.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void renderBufferDebug(GuiGraphicsExtractor graphics) {
506506
int topPadding = 20;
507507
int bottomPadding = 50;
508508
int verticalPadding = 10;
509-
int arenaPadding = 4;
509+
int arenaPadding = 5;
510510
int targetWidth = graphics.guiWidth() / 2;
511511
int targetHeight = graphics.guiHeight();
512512
var totalMapHeight = (targetHeight - verticalPadding - topPadding - bottomPadding * this.dataTypes.size());
@@ -520,57 +520,64 @@ public void renderBufferDebug(GuiGraphicsExtractor graphics) {
520520

521521
int y = topPadding;
522522
for (var dataType : this.dataTypes) {
523-
// dataType.name + " Shared Arenas: " + dataType.arenas.size()
524523
var str = String.format("%s Shared Arenas: %d (Used: %d MiB / Allocated: %d MiB) %s",
525524
dataType.name,
526525
dataType.arenas.size(),
527526
MathUtil.toMib(dataType.getDeviceUsedMemory()),
528527
MathUtil.toMib(dataType.getDeviceAllocatedMemory()),
529528
dataType.pauseDeallocation ? "deallocation paused" : "");
530-
graphics.text(Minecraft.getInstance().font, str, leftPadding, y, Colors.FOREGROUND);
529+
graphics.text(Minecraft.getInstance().font, str, leftPadding, y, Colors.THEME_LIGHTER);
531530
y += verticalPadding;
532531
var x = leftPadding;
533532
var arenaCount = dataType.arenas.size();
534533
if (arenaCount == 0) {
535534
continue;
536535
}
537536

538-
int mapWidth = (targetWidth - leftPadding * 2 - arenaPadding * (arenaCount - 1)) / arenaCount;
539-
int mapHeight = (totalMapHeight * (arenaCount + countOffset)) / mapCount;
537+
// calculate rows and column counts
538+
int rows = Math.max(1, (int) Math.floor(Math.sqrt((double) arenaCount / 2)));
539+
int cols = (int) Math.ceil(arenaCount / (float) rows);
540+
541+
int mapWidth = (targetWidth - leftPadding * 2 - arenaPadding * (cols - 1)) / cols;
542+
int typeHeight = (totalMapHeight * (arenaCount + countOffset)) / mapCount;
543+
int mapHeight = (typeHeight - arenaPadding * (rows - 1)) / rows;
544+
540545
for (var arenaEntry : dataType.arenas) {
541546
arenaEntry.renderDebugMap(graphics, x, y, mapWidth, mapHeight);
542547
x += mapWidth + arenaPadding;
548+
if (x + mapWidth > leftPadding + targetWidth) {
549+
x = leftPadding;
550+
y += mapHeight + arenaPadding;
551+
}
543552
}
544-
545-
y += mapHeight + verticalPadding;
546553
}
547554

548555
// show total copies and bytes
549556
graphics.text(Minecraft.getInstance().font,
550557
String.format("Defragmentation copies: %d (%d MiB)",
551558
this.totalCopyCount, MathUtil.toMib(this.totalCopyBytes)),
552-
leftPadding, 30, Colors.FOREGROUND);
559+
leftPadding, 30, Colors.THEME_LIGHTER);
553560

554561
// budget per frame
555562
if (this.lastDefragBudget != null) {
556563
graphics.text(Minecraft.getInstance().font,
557564
String.format("Defragmentation budget per frame: %d copies / %d MiB",
558565
this.lastDefragBudget.getStartCopyCount(),
559566
MathUtil.toMib(this.lastDefragBudget.getStartCopyBytes())),
560-
leftPadding, 40, Colors.FOREGROUND);
567+
leftPadding, 40, Colors.THEME_LIGHTER);
561568

562569
// used budget
563570
graphics.text(Minecraft.getInstance().font,
564571
String.format("Defragmentation used this frame: %d copies / %d MiB",
565572
this.lastDefragBudget.getUsedCopyCount(),
566573
MathUtil.toMib(this.lastDefragBudget.getUsedCopyBytes())),
567-
leftPadding, 50, Colors.FOREGROUND);
574+
leftPadding, 50, Colors.THEME_LIGHTER);
568575
}
569576

570577
// allocation stats
571578
graphics.text(Minecraft.getInstance().font,
572579
String.format("Buffer allocations: %d (%d MiB)",
573580
this.allocationCount, MathUtil.toMib(this.allocationBytes)),
574-
leftPadding, 50, Colors.FOREGROUND);
581+
leftPadding, 60, Colors.THEME_LIGHTER);
575582
}
576583
}

0 commit comments

Comments
 (0)