Skip to content

Commit

Permalink
Create debug message groups for ProfilerFiller push/pop calls in Game…
Browse files Browse the repository at this point in the history
…Renderer & LevelRenderer
  • Loading branch information
Drullkus committed Sep 18, 2023
1 parent c41aa64 commit 1a5609a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
24 changes: 24 additions & 0 deletions common/src/main/java/us/drullk/opengldebug/GLDebugHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@
public final class GLDebugHelper {
//public static final Logger LOGGER = LogUtils.getLogger();

// Value resets at beginning of each render-frame
// Used in enumerating ids for glPushDebugGroup calls, within each render-frame
private static int id = 0;

public static void resetCounter() {
id = 0;
}

public static int getMessageId() {
return id++;
}

public static void pushMessageGroupFromProfiler(String message) {
pushMessageGroup("Profiler group: " + message);
}

public static void pushMessageGroup(String message) {
KHRDebug.glPushDebugGroup(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, getMessageId(), message);
}

public static void popMessageGroup() {
KHRDebug.glPopDebugGroup();
}

public static void setTextureDebugName(String name, AbstractTexture texture) {
setTextureDebugName(name, texture.getId());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package us.drullk.opengldebug.mixin;

import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import us.drullk.opengldebug.GLDebugHelper;

@Mixin(GameRenderer.class)
public class GameRendererMixin {
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V"))
private void renderDebugPush(ProfilerFiller instance, String s) {
instance.push(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V"))
private void renderDebugPopPush(ProfilerFiller instance, String s) {
GLDebugHelper.popMessageGroup();
instance.popPush(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;pop()V"))
private void renderDebugPop(ProfilerFiller instance) {
GLDebugHelper.popMessageGroup();
instance.pop();
}

@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V"))
private void renderLevelDebugPush(ProfilerFiller instance, String s) {
instance.push(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V"))
private void renderLevelDebugPopPush(ProfilerFiller instance, String s) {
GLDebugHelper.popMessageGroup();
instance.popPush(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;pop()V"))
private void renderLevelDebugPop(ProfilerFiller instance) {
GLDebugHelper.popMessageGroup();
instance.pop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package us.drullk.opengldebug.mixin;

import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import us.drullk.opengldebug.GLDebugHelper;

import java.util.function.Supplier;

@Mixin(LevelRenderer.class)
public class LevelRendererMixin {
@Redirect(method = "renderLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V"))
private void debugAmongPopPush(ProfilerFiller instance, String s) {
GLDebugHelper.popMessageGroup();
instance.popPush(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "renderChunkLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;push(Ljava/lang/String;)V"))
private void renderChunkLayerPush(ProfilerFiller instance, String s) {
instance.push(s);
GLDebugHelper.pushMessageGroupFromProfiler(s);
}

@Redirect(method = "renderChunkLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/util/function/Supplier;)V"))
private void renderChunkLayerDebugPopPush(ProfilerFiller instance, Supplier<String> stringSupplier) {
GLDebugHelper.popMessageGroup();
instance.popPush(stringSupplier);
GLDebugHelper.pushMessageGroupFromProfiler(stringSupplier.get());
}

@Redirect(method = "renderChunkLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;pop()V"))
private void renderChunkLayerPop(ProfilerFiller instance) {
GLDebugHelper.popMessageGroup();
instance.pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public abstract class MinecraftMixin {
private void nameMain(GameConfig gameConfig, CallbackInfo ci) {
GLDebugHelper.setFBODebugNames(this.getMainRenderTarget(), "Minecraft main");
}

@Inject(method = "runTick", at = @At(value = "HEAD"))
private void resetCounter(boolean b, CallbackInfo ci) {
GLDebugHelper.resetCounter();
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/opengldebug.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
},
"client": [
"EffectInstanceMixin",
"GameRendererMixin",
"LevelRendererMixin",
"MinecraftMixin",
"OverlayTextureMixin",
"PostChainMixin",
Expand Down

0 comments on commit 1a5609a

Please sign in to comment.