Skip to content

Commit 2f98a8d

Browse files
committed
Add chunk memory stats debug entry
1 parent 29c9d77 commit 2f98a8d

4 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.vulkanmod.mixin.debug;
2+
3+
import net.minecraft.client.gui.components.debug.DebugScreenEntries;
4+
import net.minecraft.client.gui.components.debug.DebugScreenEntry;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.vulkanmod.render.profiling.DebugEntryMemoryStats;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(DebugScreenEntries.class)
14+
public abstract class DebugScreenEntriesM {
15+
16+
@Shadow
17+
public static ResourceLocation register(ResourceLocation resourceLocation, DebugScreenEntry debugScreenEntry) {
18+
return null;
19+
}
20+
21+
@Inject(method = "<clinit>", at = @At("RETURN"))
22+
private static void addEntry(CallbackInfo ci) {
23+
register(ResourceLocation.fromNamespaceAndPath("vkmod","stats"), new DebugEntryMemoryStats());
24+
}
25+
}

src/main/java/net/vulkanmod/render/chunk/WorldRenderer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ public SectionGrid getSectionGrid() {
508508
}
509509

510510
public ChunkAreaManager getChunkAreaManager() {
511+
if (this.sectionGrid == null)
512+
return null;
511513
return this.sectionGrid.chunkAreaManager;
512514
}
513515

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.vulkanmod.render.profiling;
2+
3+
import net.minecraft.client.gui.components.debug.DebugScreenDisplayer;
4+
import net.minecraft.client.gui.components.debug.DebugScreenEntry;
5+
import net.minecraft.resources.ResourceLocation;
6+
import net.minecraft.world.level.Level;
7+
import net.minecraft.world.level.chunk.LevelChunk;
8+
import net.vulkanmod.render.chunk.WorldRenderer;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.util.List;
12+
13+
public class DebugEntryMemoryStats implements DebugScreenEntry {
14+
private static final ResourceLocation GROUP = ResourceLocation.withDefaultNamespace("vk_memory");
15+
16+
@Override
17+
public void display(DebugScreenDisplayer debugScreenDisplayer, @Nullable Level level,
18+
@Nullable LevelChunk levelChunk, @Nullable LevelChunk levelChunk2) {
19+
var chunkAreaManager = WorldRenderer.getInstance().getChunkAreaManager();
20+
21+
if (chunkAreaManager != null) {
22+
debugScreenDisplayer.addToGroup(
23+
GROUP,
24+
List.of(chunkAreaManager.getStats())
25+
);
26+
}
27+
}
28+
}

src/main/resources/vulkanmod.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
"debug.crash_report.SystemReportM",
2828
"debug.DebugEntryMemoryM",
29+
"debug.DebugScreenEntriesM",
2930
"debug.KeyboardHandlerM",
3031

3132
"matrix.Matrix4fM",

0 commit comments

Comments
 (0)