Skip to content

Commit

Permalink
Test 1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 15, 2023
1 parent 8bc3a7e commit 71a266e
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 1 deletion.
5 changes: 5 additions & 0 deletions buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public void getModDependencies(ModDependencyCollector d) {
jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-key-binding-api-v1", "1.0.12+54e5b2ec60"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));

jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre13"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.lwjgl:lwjgl-nuklear:3.3.3"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.lwjgl:lwjgl-nuklear:3.3.3:natives-linux"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.lwjgl:lwjgl-nuklear:3.3.3:natives-windows"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.lwjgl:lwjgl-nuklear:3.3.3:natives-macos"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.lwjgl:lwjgl-nuklear:3.3.3:natives-macos-arm64"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
d.addMaven("https://api.modrinth.com/maven", new MavenId("maven.modrinth", "distanthorizons", "2.0.0-a-1.18.2"), ModDependencyFlag.COMPILE);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.coderbot.iris.compat.sodium.SodiumVersionCheck;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.gl.GLDebug;
import net.coderbot.iris.gl.debug.TimerQuerier;
import net.coderbot.iris.gl.shader.StandardMacros;
import net.coderbot.iris.gui.screen.ShaderPackScreen;
import net.coderbot.iris.pipeline.FixedFunctionWorldRenderingPipeline;
Expand Down Expand Up @@ -182,6 +183,7 @@ public static void onRenderSystemInit() {
return;
}

TimerQuerier.initRenderer();
PBRTextureManager.INSTANCE.init();

// Only load the shader pack when we can access OpenGL
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/net/coderbot/iris/gl/debug/TimerQuerier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.coderbot.iris.gl.debug;

import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import net.coderbot.iris.Iris;
import net.minecraft.client.gui.screens.Screen;
import org.lwjgl.opengl.GL32C;

import java.util.Set;

public class TimerQuerier {
private static final Object2ObjectMap<String, TimerQuery>[] queries = new Object2ObjectOpenHashMap[5];
private static int frameId = 0;

static {
for (int i = 0; i < 5; i++) {
queries[i] = new Object2ObjectOpenHashMap<>();
}
}

private static final Set<TimerQuery> unusedQueries = new ObjectArraySet<>();

public static void initRenderer() {
int[] queries = new int[100];
GL32C.glGenQueries(queries);
for (int i = 0; i < 100; i++) {
unusedQueries.add(new TimerQuery(queries[i]));
}
}

public static TimerQuery giveQuery() {
if (unusedQueries.isEmpty()) {
Iris.logger.warn("Congrats, you overran the query system. Adding a new query. (If this stops after a bit, it's not an error, you just have a lot going on)");
unusedQueries.add(new TimerQuery(GL32C.glGenQueries()));
}
TimerQuery query = unusedQueries.iterator().next();
unusedQueries.remove(query);
return query;
}


public static void advanceFrameAndReset() {
// Advance the frame ID
frameId = (frameId + 1) % 5;

int frameToGet = frameId - 4;
if (frameToGet < 0) frameToGet += 5;

queries[frameToGet].forEach((name, query) -> {
if (Screen.hasControlDown()) {
Iris.logger.warn("Query result for " + name + " was " + ((float) query.returnResult() / 1000000f) + "ms");
}
query.stopUsing();
unusedQueries.add(query);
});

queries[frameToGet].clear();
}

public static void monitorQuery(String name, TimerQuery query) {
queries[frameId].put(name, query);
}
}
57 changes: 57 additions & 0 deletions src/main/java/net/coderbot/iris/gl/debug/TimerQuery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.coderbot.iris.gl.debug;

import net.coderbot.iris.Iris;
import org.jetbrains.annotations.ApiStatus;
import org.lwjgl.opengl.GL42C;

public class TimerQuery {
private final int query;
private boolean inUse = false;

private static boolean isInQuery = false;
private static String name;

public TimerQuery(int query) {
this.query = query;
}

public boolean isInUse() {
return inUse;
}

public void startQuery(String name) {
if (inUse || isInQuery) {
throw new IllegalStateException("Query " + name + " already in use");
}
TimerQuery.name = name;

inUse = true;
isInQuery = true;

GL42C.glBeginQuery(GL42C.GL_TIME_ELAPSED, query);
}

public void startMonitoring() {
if (!inUse) {
throw new IllegalStateException("Not in use, giving up");
}

isInQuery = false;
GL42C.glEndQuery(GL42C.GL_TIME_ELAPSED);

TimerQuerier.monitorQuery(name, this);
}

@ApiStatus.Internal
public int returnResult() {
return GL42C.glGetQueryObjecti(query, GL42C.GL_QUERY_RESULT);
}

protected void stopUsing() {
if (!inUse) {
throw new IllegalStateException("Query not in use");
}

inUse = false;
}
}
14 changes: 14 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import net.coderbot.iris.Iris;
import net.coderbot.iris.fantastic.WrappingMultiBufferSource;
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.debug.TimerQuerier;
import net.coderbot.iris.gl.debug.TimerQuery;
import net.coderbot.iris.gl.program.Program;
import net.coderbot.iris.layer.IsOutlineRenderStateShard;
import net.coderbot.iris.layer.OuterWrappedRenderType;
import net.coderbot.iris.pipeline.HandRenderer;
import net.coderbot.iris.pipeline.WorldRenderingPhase;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.shadows.ShadowRenderingState;
import net.coderbot.iris.shadows.frustum.fallback.NonCullingFrustum;
import net.coderbot.iris.uniforms.CapturedRenderingState;
import net.coderbot.iris.uniforms.IrisTimeUniforms;
Expand Down Expand Up @@ -82,6 +85,7 @@ public class MixinLevelRenderer {
CapturedRenderingState.INSTANCE.setTickDelta(tickDelta);
SystemTimeUniforms.COUNTER.beginFrame();
SystemTimeUniforms.TIMER.beginFrame(startTime);
TimerQuerier.advanceFrameAndReset();

pipeline = Iris.getPipelineManager().preparePipeline(Iris.getCurrentDimension());

Expand Down Expand Up @@ -200,15 +204,25 @@ public class MixinLevelRenderer {
pipeline.setPhase(WorldRenderingPhase.NONE);
}

@Unique
TimerQuery query;

@Inject(method = "renderChunkLayer", at = @At("HEAD"))
private void iris$beginTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) {
pipeline.setPhase(WorldRenderingPhase.fromTerrainRenderType(renderType));

if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) return;
query = TimerQuerier.giveQuery();
query.startQuery(WorldRenderingPhase.fromTerrainRenderType(renderType).name());
}

@Inject(method = "renderChunkLayer", at = @At("RETURN"))
private void iris$endTerrainLayer(RenderType renderType, PoseStack poseStack, double d, double e, double f, Matrix4f projectionMatrix, CallbackInfo ci) {
pipeline.setPhase(WorldRenderingPhase.NONE);
if (ShadowRenderingState.areShadowsCurrentlyBeingRendered()) return;

query.startMonitoring();
query = null;
}

@Inject(method = "renderLevel", at = @At(value = "INVOKE", target = RENDER_WEATHER))
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/coderbot/iris/pipeline/ShadowRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.coderbot.batchedentityrendering.impl.RenderBuffersExt;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.debug.TimerQuerier;
import net.coderbot.iris.gl.debug.TimerQuery;
import net.coderbot.iris.gl.program.ComputeProgram;
import net.coderbot.iris.gl.texture.DepthCopyStrategy;
import net.coderbot.iris.gui.option.IrisVideoSettings;
Expand Down Expand Up @@ -360,6 +362,9 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame
return;
}

TimerQuery query = TimerQuerier.giveQuery();
query.startQuery("shadowPass");

Minecraft client = Minecraft.getInstance();

levelRenderer.getLevel().getProfiler().popPush("shadows");
Expand Down Expand Up @@ -555,6 +560,7 @@ public void renderShadows(LevelRendererAccessor levelRenderer, Camera playerCame
if (levelRenderer instanceof CullingDataCache) {
((CullingDataCache) levelRenderer).restoreState();
}
query.startMonitoring();

compositeRenderer.renderAll();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.blending.BlendModeOverride;
import net.coderbot.iris.gl.debug.TimerQuerier;
import net.coderbot.iris.gl.debug.TimerQuery;
import net.coderbot.iris.gl.framebuffer.GlFramebuffer;
import net.coderbot.iris.gl.image.GlImage;
import net.coderbot.iris.gl.program.ComputeProgram;
Expand Down Expand Up @@ -109,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[i] != null && computes[i][0] != null) {
ComputeOnlyPass pass = new ComputeOnlyPass();
pass.name = computes[i][0].getName();
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier);
passes.add(pass);
}
Expand All @@ -121,6 +124,7 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
ProgramDirectives directives = source.getDirectives();

pass.program = createProgram(source, flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier);
pass.name = source.getName();
pass.blendModeOverride = source.getDirectives().getBlendModeOverride().orElse(null);
pass.computes = createComputes(computes[i], flipped, flippedAtLeastOnceSnapshot, shadowTargetsSupplier);
int[] drawBuffers = directives.getDrawBuffers();
Expand Down Expand Up @@ -205,6 +209,7 @@ private static class Pass {
int viewWidth;
int viewHeight;
Program program;
String name;
BlendModeOverride blendModeOverride;
ComputeProgram[] computes;
GlFramebuffer framebuffer;
Expand Down Expand Up @@ -241,6 +246,8 @@ public void renderAll() {
com.mojang.blaze3d.pipeline.RenderTarget main = Minecraft.getInstance().getMainRenderTarget();

for (Pass renderPass : passes) {
TimerQuery query = TimerQuerier.giveQuery();
query.startQuery(renderPass.name);
boolean ranCompute = false;
for (ComputeProgram computeProgram : renderPass.computes) {
if (computeProgram != null) {
Expand All @@ -258,6 +265,7 @@ public void renderAll() {
Program.unbind();

if (renderPass instanceof ComputeOnlyPass) {
query.startMonitoring();
continue;
}

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

BlendModeOverride.restore();
query.startMonitoring();
}

FullScreenQuadRenderer.INSTANCE.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.debug.TimerQuerier;
import net.coderbot.iris.gl.debug.TimerQuery;
import net.coderbot.iris.gl.image.GlImage;
import net.coderbot.iris.features.FeatureFlags;
import net.coderbot.iris.gl.IrisRenderSystem;
Expand Down

0 comments on commit 71a266e

Please sign in to comment.