Skip to content

Commit

Permalink
Abusing debug groups
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Mar 7, 2024
1 parent 9e03089 commit cbfcdef
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void createDepthTex(int width, int height) {

translucentDepthDirty = true;

depthTexNoTranslucent = new DepthTexture(width, height, DepthBufferFormat.DEPTH32F);
depthTexNoTranslucent = new DepthTexture("DH depth tex", width, height, DepthBufferFormat.DEPTH32F);
}

public void renderShadowSolid() {
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/net/irisshaders/iris/gl/GLDebug.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ public static void nameObject(int id, int object, String name) {
debugState.nameObject(id, object, name);
}

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

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

private interface DebugState {
void nameObject(int id, int object, String name);

Expand All @@ -317,7 +325,7 @@ private interface DebugState {
}

private static class KHRDebugState implements DebugState {
private boolean hasGroup;
private int stackSize;

@Override
public void nameObject(int id, int object, String name) {
Expand All @@ -327,14 +335,14 @@ 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);
hasGroup = true;
stackSize += 1;
}

@Override
public void popGroup() {
if (hasGroup) {
if (stackSize != 0) {
KHRDebug.glPopDebugGroup();
hasGroup = false;
stackSize -= 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.gl.buffer;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.IrisRenderSystem;
import org.lwjgl.opengl.GL43C;

Expand All @@ -12,6 +13,7 @@ public class ShaderStorageBuffer {

public ShaderStorageBuffer(int index, ShaderStorageInfo info) {
this.id = GlStateManager._glGenBuffers();
GLDebug.nameObject(GL43C.GL_BUFFER, id, "SSBO " + index);
this.index = index;
this.info = info;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/irisshaders/iris/gl/image/GlImage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.irisshaders.iris.gl.image;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.InternalTextureFormat;
Expand All @@ -12,6 +13,7 @@
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
import org.lwjgl.opengl.GL43C;

public class GlImage extends GlResource {
protected final String name;
Expand All @@ -33,6 +35,8 @@ public GlImage(String name, String samplerName, TextureType target, PixelFormat
this.pixelType = pixelType;
this.clear = clear;

GLDebug.nameObject(GL43C.GL_TEXTURE, getGlId(), name);

IrisRenderSystem.bindTextureForSetup(target.getGlType(), getGlId());
target.apply(getGlId(), width, height, depth, internalFormat.getGlFormat(), format.getGlFormat(), pixelType.getGlFormat(), null);

Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/irisshaders/iris/gl/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void use() {
IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT | GL43C.GL_SHADER_STORAGE_BARRIER_BIT);
ProgramManager.glUseProgram(getGlId());


uniforms.update();
samplers.update();
images.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mojang.blaze3d.vertex.VertexFormat;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.pipeline.programs.ShaderKey;
import net.irisshaders.iris.pipeline.programs.ShaderMap;
import net.irisshaders.iris.shaderpack.materialmap.BlockMaterialMapping;
Expand Down Expand Up @@ -797,6 +798,16 @@ public WorldRenderingPhase getPhase() {

@Override
public void setPhase(WorldRenderingPhase phase) {
if (phase == WorldRenderingPhase.NONE) {
if (this.phase != WorldRenderingPhase.NONE) {
GLDebug.popGroup();
}
} else {
if (this.phase != WorldRenderingPhase.NONE) {
GLDebug.popGroup();
}
GLDebug.pushGroup(phase.ordinal(), phase.name());
}
this.phase = phase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public ShadowRenderTargets(WorldRenderingPipeline pipeline, int resolution, Pack
linearFiltered = new boolean[size];
buffersToBeCleared = new IntArrayList();

this.mainDepth = new DepthTexture(resolution, resolution, DepthBufferFormat.DEPTH);
this.noTranslucents = new DepthTexture(resolution, resolution, DepthBufferFormat.DEPTH);
this.mainDepth = new DepthTexture("shadowtex0", resolution, resolution, DepthBufferFormat.DEPTH);
this.noTranslucents = new DepthTexture("shadowtex1", resolution, resolution, DepthBufferFormat.DEPTH);

this.ownedFramebuffers = new ArrayList<>();
this.resolution = resolution;
Expand Down Expand Up @@ -133,6 +133,7 @@ private void create(int index) {
PackShadowDirectives.SamplingSettings settings = shadowDirectives.getColorSamplingSettings().computeIfAbsent(index, i -> new PackShadowDirectives.SamplingSettings());
targets[index] = RenderTarget.builder().setDimensions(resolution, resolution)
.setInternalFormat(settings.getFormat())
.setName("shadowcolor" + index)
.setPixelFormat(settings.getFormat().getPixelFormat()).build();
formats[index] = settings.getFormat();
if (settings.getClear()) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/irisshaders/iris/targets/DepthTexture.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package net.irisshaders.iris.targets;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.DepthBufferFormat;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL43C;

public class DepthTexture extends GlResource {
public DepthTexture(int width, int height, DepthBufferFormat format) {
public DepthTexture(String name, int width, int height, DepthBufferFormat format) {
super(IrisRenderSystem.createTexture(GL11C.GL_TEXTURE_2D));
int texture = getGlId();

resize(width, height, format);
GLDebug.nameObject(GL43C.GL_TEXTURE, texture, name);

IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_NEAREST);
IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_NEAREST);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/irisshaders/iris/targets/RenderTarget.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package net.irisshaders.iris.targets;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.InternalTextureFormat;
import net.irisshaders.iris.gl.texture.PixelFormat;
import net.irisshaders.iris.gl.texture.PixelType;
import org.joml.Vector2i;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL43C;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -42,6 +44,11 @@ public RenderTarget(Builder builder) {
setupTexture(mainTexture, builder.width, builder.height, !isPixelFormatInteger);
setupTexture(altTexture, builder.width, builder.height, !isPixelFormatInteger);

if (builder.name != null) {
GLDebug.nameObject(GL43C.GL_TEXTURE, mainTexture, builder.name + " main");
GLDebug.nameObject(GL43C.GL_TEXTURE, mainTexture, builder.name + " alt");
}

// Clean up after ourselves
// This is strictly defensive to ensure that other buggy code doesn't tamper with our textures
GlStateManager._bindTexture(0);
Expand Down Expand Up @@ -123,11 +130,18 @@ public static class Builder {
private int height = 0;
private PixelFormat format = PixelFormat.RGBA;
private PixelType type = PixelType.UNSIGNED_BYTE;
private String name = null;

private Builder() {
// No-op
}

public Builder setName(String name) {
this.name = name;

return this;
}

public Builder setInternalFormat(InternalTextureFormat format) {
this.internalFormat = format;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/irisshaders/iris/targets/RenderTargets.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public RenderTargets(int width, int height, int depthTexture, int depthBufferVer

this.depthSourceFb = createFramebufferWritingToMain(new int[]{0});

this.noTranslucents = new DepthTexture(width, height, currentDepthFormat);
this.noHand = new DepthTexture(width, height, currentDepthFormat);
this.noTranslucents = new DepthTexture("depthtex1", width, height, currentDepthFormat);
this.noHand = new DepthTexture("dephtex2", width, height, currentDepthFormat);

this.noTranslucentsDestFb = createFramebufferWritingToMain(new int[]{0});
this.noTranslucentsDestFb.addDepthAttachment(this.noTranslucents.getTextureId());
Expand Down Expand Up @@ -123,6 +123,7 @@ private void create(int index) {
PackRenderTargetDirectives.RenderTargetSettings settings = targetSettingsMap.get(index);
Vector2i dimensions = packDirectives.getTextureScaleOverride(index, cachedWidth, cachedHeight);
targets[index] = RenderTarget.builder().setDimensions(dimensions.x, dimensions.y)
.setName("colortex" + index)
.setInternalFormat(settings.getInternalFormat())
.setPixelFormat(settings.getInternalFormat().getPixelFormat()).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.irisshaders.iris.targets.backed;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.TextureUploadHelper;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL43C;

import java.nio.ByteBuffer;
import java.util.Random;
Expand Down Expand Up @@ -34,6 +36,8 @@ public NoiseTexture(int width, int height) {
IrisRenderSystem.texParameterf(texture, GL11C.GL_TEXTURE_2D, GL20C.GL_TEXTURE_LOD_BIAS, 0.0F);
resize(texture, width, height);

GLDebug.nameObject(GL43C.GL_TEXTURE, texture, "noise texture");

GlStateManager._bindTexture(0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.irisshaders.iris.targets.backed;

import com.mojang.blaze3d.platform.GlStateManager;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.GlResource;
import net.irisshaders.iris.gl.IrisRenderSystem;
import net.irisshaders.iris.gl.texture.TextureUploadHelper;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11C;
import org.lwjgl.opengl.GL13C;
import org.lwjgl.opengl.GL43C;

import java.nio.ByteBuffer;

Expand All @@ -22,6 +24,8 @@ public SingleColorTexture(int red, int green, int blue, int alpha) {

int texture = getGlId();

GLDebug.nameObject(GL43C.GL_TEXTURE, texture, "single color (" + red + ", " + green + "," + blue + "," + alpha + ")");

IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MIN_FILTER, GL11C.GL_LINEAR);
IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_MAG_FILTER, GL11C.GL_LINEAR);
IrisRenderSystem.texParameteri(texture, GL11C.GL_TEXTURE_2D, GL11C.GL_TEXTURE_WRAP_S, GL13C.GL_REPEAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType;
import net.irisshaders.iris.Iris;
import net.irisshaders.iris.compat.sodium.impl.IrisChunkShaderBindingPoints;
import net.irisshaders.iris.gl.GLDebug;
import net.irisshaders.iris.gl.blending.AlphaTest;
import net.irisshaders.iris.gl.blending.AlphaTests;
import net.irisshaders.iris.gl.blending.BlendModeOverride;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL43C;

import java.util.EnumMap;
import java.util.List;
Expand Down Expand Up @@ -252,7 +254,7 @@ private GlProgram<IrisChunkShaderInterface> createShader(IrisTerrainPass pass, S
.link((shader) -> {
int handle = ((GlObject) shader).handle();
ShaderBindingContextExt contextExt = (ShaderBindingContextExt) shader;

GLDebug.nameObject(GL43C.GL_PROGRAM, handle, "sodium-terrain-" + pass.toString().toLowerCase(Locale.ROOT));
return new IrisChunkShaderInterface(handle, contextExt, pipeline, new ChunkShaderOptions(ChunkFogMode.SMOOTH, pass.toTerrainPass(), vertexType),
tessCShader != null || tessEShader != null, pass == IrisTerrainPass.SHADOW || pass == IrisTerrainPass.SHADOW_CUTOUT, blendOverride, bufferOverrides, alpha, pipeline.getCustomUniforms());
});
Expand Down

0 comments on commit cbfcdef

Please sign in to comment.