Skip to content

Commit

Permalink
The great debug groups
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Oct 28, 2024
1 parent 9c9fb8a commit d846ff8
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 41 deletions.
25 changes: 18 additions & 7 deletions common/src/main/java/net/irisshaders/iris/gl/GLDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.irisshaders.iris.gl;

import net.irisshaders.iris.Iris;
import net.irisshaders.iris.platform.IrisPlatformHelpers;
import org.lwjgl.opengl.AMDDebugOutput;
import org.lwjgl.opengl.ARBDebugOutput;
import org.lwjgl.opengl.GL;
Expand All @@ -19,6 +20,7 @@
import org.lwjgl.system.APIUtil;

import java.io.PrintStream;
import java.util.Stack;
import java.util.function.Consumer;

public final class GLDebug {
Expand Down Expand Up @@ -313,11 +315,11 @@ public static void nameObject(int id, int object, String name) {
}

public static void pushGroup(int id, String name) {
//debugState.pushGroup(id, name);
debugState.pushGroup(id, name);
}

public static void popGroup() {
//debugState.popGroup();
debugState.popGroup();
}

private interface DebugState {
Expand All @@ -329,7 +331,10 @@ private interface DebugState {
}

private static class KHRDebugState implements DebugState {
// Let's see how bad this goes
private static final boolean ENABLE_DEBUG_GROUPS = true;
private int stackSize;
private final Stack<String> stack = new Stack<>();

@Override
public void nameObject(int id, int object, String name) {
Expand All @@ -338,15 +343,21 @@ public void nameObject(int id, int object, String name) {

@Override
public void pushGroup(int id, String name) {
KHRDebug.glPushDebugGroup(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, id, name);
stackSize += 1;
if (ENABLE_DEBUG_GROUPS) {
KHRDebug.glPushDebugGroup(KHRDebug.GL_DEBUG_SOURCE_APPLICATION, id, name);
stack.push(name);
stackSize += 1;
}
}

@Override
public void popGroup() {
if (stackSize != 0) {
KHRDebug.glPopDebugGroup();
stackSize -= 1;
if (ENABLE_DEBUG_GROUPS) {
if (stackSize != 0) {
KHRDebug.glPopDebugGroup();
stack.pop();
stackSize -= 1;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.irisshaders.iris.mixin;

import com.mojang.blaze3d.pipeline.RenderTarget;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.targets.Blaze3dRenderTargetExt;
import org.lwjgl.opengl.GL43C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -18,6 +20,10 @@ public class MixinRenderTarget implements Blaze3dRenderTargetExt {
@Shadow
protected int depthBufferId;

@Shadow
protected int colorTextureId;
@Shadow
public int frameBufferId;
@Unique
private int iris$depthBufferVersion;
@Unique
Expand All @@ -29,6 +35,13 @@ public class MixinRenderTarget implements Blaze3dRenderTargetExt {
iris$colorBufferVersion++;
}

@Inject(method = "createBuffers", at = @At(value = "RETURN"))
private void nameDepthBuffer(int i, int j, boolean bl, CallbackInfo ci) {
GLDebug.nameObject(GL43C.GL_TEXTURE, this.depthBufferId, "Main depth texture");
GLDebug.nameObject(GL43C.GL_TEXTURE, this.colorTextureId, "Main color texture");
GLDebug.nameObject(GL43C.GL_FRAMEBUFFER, this.frameBufferId, "Main framebuffer");
}

@Override
public int iris$getDepthBufferVersion() {
return iris$depthBufferVersion;
Expand Down
15 changes: 12 additions & 3 deletions common/src/main/java/net/irisshaders/iris/mixin/gui/MixinGui.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.irisshaders.iris.mixin.gui;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.mojang.blaze3d.systems.RenderSystem;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gui.screen.HudHideable;
import net.irisshaders.iris.pipeline.WorldRenderingPipeline;
import net.minecraft.client.DeltaTracker;
Expand All @@ -28,13 +31,19 @@ public class MixinGui {
@Final
private DebugScreenOverlay debugOverlay;

@Inject(method = "render", at = @At("HEAD"), cancellable = true)
public void iris$handleHudHidingScreens(GuiGraphics guiGraphics, DeltaTracker deltaTracker, CallbackInfo ci) {
@WrapMethod(method = "render")
public void iris$handleHudHidingScreens(GuiGraphics guiGraphics, DeltaTracker deltaTracker, Operation<Void> original) {
Screen screen = this.minecraft.screen;

if (screen instanceof HudHideable) {
ci.cancel();
return;
}

GLDebug.pushGroup(1000, "GUI");

original.call(guiGraphics, deltaTracker);

GLDebug.popGroup();
}

@Inject(method = "renderVignette", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.irisshaders.iris.pipeline;

public enum CompositePass {
BEGIN,
PREPARE,
DEFERRED,
COMPOSITE
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.irisshaders.iris.features.FeatureFlags;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
import net.irisshaders.iris.gl.buffer.ShaderStorageBufferHolder;
Expand Down Expand Up @@ -51,6 +52,7 @@
import org.lwjgl.opengl.GL43C;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand All @@ -69,14 +71,16 @@ public class CompositeRenderer {
private final Set<GlImage> customImages;
private final TextureStage textureStage;
private final WorldRenderingPipeline pipeline;
private final CompositePass compositePass;

public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDirectives, ProgramSource[] sources, ComputeSource[][] computes, RenderTargets renderTargets, ShaderStorageBufferHolder holder,
public CompositeRenderer(WorldRenderingPipeline pipeline, CompositePass compositePass, PackDirectives packDirectives, ProgramSource[] sources, ComputeSource[][] computes, RenderTargets renderTargets, ShaderStorageBufferHolder holder,
TextureAccess noiseTexture, FrameUpdateNotifier updateNotifier,
CenterDepthSampler centerDepthSampler, BufferFlipper bufferFlipper,
Supplier<ShadowRenderTargets> shadowTargetsSupplier, TextureStage textureStage,
Object2ObjectMap<String, TextureAccess> customTextureIds, Object2ObjectMap<String, TextureAccess> irisCustomTextures, Set<GlImage> customImages, ImmutableMap<Integer, Boolean> explicitPreFlips,
CustomUniforms customUniforms) {
this.pipeline = pipeline;
this.compositePass = compositePass;
this.noiseTexture = noiseTexture;
this.centerDepthSampler = centerDepthSampler;
this.renderTargets = renderTargets;
Expand Down Expand Up @@ -107,8 +111,9 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
ImmutableSet<Integer> flippedAtLeastOnceSnapshot = flippedAtLeastOnce.build();

if (source == null || !source.isValid()) {
if (computes[i] != null) {
if (computes.length != 0 && computes[i] != null && computes[i].length > 0) {
ComputeOnlyPass pass = new ComputeOnlyPass();
pass.name = computes[i].length > 0 ? computes[i][0].getName() : "unknown";
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier, holder);
passes.add(pass);
}
Expand All @@ -118,9 +123,14 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
Pass pass = new Pass();
ProgramDirectives directives = source.getDirectives();

pass.name = source.getName();
pass.program = createProgram(source, flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier);
pass.blendModeOverride = source.getDirectives().getBlendModeOverride().orElse(null);
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier, holder);
if (computes.length != 0) {
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier, holder);
} else {
pass.computes = new ComputeProgram[0];
}
int[] drawBuffers = directives.getDrawBuffers();


Expand Down Expand Up @@ -172,6 +182,23 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
GlStateManager._glBindFramebuffer(GL30C.GL_READ_FRAMEBUFFER, 0);
}

private boolean hasComputes(ComputeSource[][] computes) {
boolean hasCompute = false;

for (int i = 0; i < computes.length; i++) {
if (computes[i].length > 0) {
for (int j = 0; j < computes[i].length; j++) {
if (computes[i][j] != null) {
hasCompute = true;
break;
}
}
}
}

return hasCompute;
}

private static void setupMipmapping(net.irisshaders.iris.targets.RenderTarget target, boolean readFromAlt) {
if (target == null) return;

Expand Down Expand Up @@ -224,12 +251,15 @@ public void recalculateSizes() {
}

public void renderAll() {
GLDebug.pushGroup(20 + compositePass.ordinal(), compositePass.name().toLowerCase(Locale.ROOT));
RenderSystem.disableBlend();

FullScreenQuadRenderer.INSTANCE.begin();
com.mojang.blaze3d.pipeline.RenderTarget main = Minecraft.getInstance().getMainRenderTarget();

for (Pass renderPass : passes) {
for (int i = 0, passesSize = passes.size(); i < passesSize; i++) {
Pass renderPass = passes.get(i);
GLDebug.pushGroup(20 * compositePass.ordinal() + i, renderPass.name);
boolean ranCompute = false;
for (ComputeProgram computeProgram : renderPass.computes) {
if (computeProgram != null) {
Expand All @@ -247,6 +277,7 @@ public void renderAll() {
Program.unbind();

if (renderPass instanceof ComputeOnlyPass) {
GLDebug.popGroup();
continue;
}

Expand Down Expand Up @@ -278,6 +309,7 @@ public void renderAll() {
FullScreenQuadRenderer.INSTANCE.renderQuad();

BlendModeOverride.restore();
GLDebug.popGroup();
}

FullScreenQuadRenderer.INSTANCE.end();
Expand All @@ -300,6 +332,8 @@ public void renderAll() {
}

RenderSystem.activeTexture(GL15C.GL_TEXTURE0);

GLDebug.popGroup();
}

// TODO: Don't just copy this from DeferredWorldRenderingPipeline
Expand Down Expand Up @@ -432,6 +466,7 @@ private static class Pass {
int[] drawBuffers;
int viewWidth;
int viewHeight;
String name;
Program program;
BlendModeOverride blendModeOverride;
ComputeProgram[] computes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.irisshaders.iris.features.FeatureFlags;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.buffer.ShaderStorageBufferHolder;
import net.irisshaders.iris.gl.framebuffer.GlFramebuffer;
Expand Down Expand Up @@ -218,6 +219,7 @@ public void renderFinalPass() {
}

if (this.finalPass != null) {
GLDebug.pushGroup(990, "final");
// If there is a final pass, we use the shader-based full screen quad rendering pathway instead
// of just copying the color buffer.

Expand Down Expand Up @@ -251,6 +253,7 @@ public void renderFinalPass() {
FullScreenQuadRenderer.INSTANCE.renderQuad();

FullScreenQuadRenderer.INSTANCE.end();
GLDebug.popGroup();
} else {
// If there are no passes, we somehow need to transfer the content of the Iris color render targets into
// the main Minecraft framebuffer.
Expand Down
Loading

0 comments on commit d846ff8

Please sign in to comment.