Skip to content

Commit

Permalink
Merge branch 'trunk' of https://github.com/IrisShaders/Iris into more…
Browse files Browse the repository at this point in the history
…-more-uniforms
  • Loading branch information
OverlordsIII committed Feb 10, 2021
2 parents d888a6b + 8f2e700 commit a38035e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/coderbot/iris/layer/GbufferPrograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static void push(GbufferProgram program) {
Iris.getPipeline().pushProgram(program);
}

public static void pop() {
Iris.getPipeline().popProgram();
public static void pop(GbufferProgram program) {
Iris.getPipeline().popProgram(program);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public class UseProgramRenderPhase extends RenderPhase {
public UseProgramRenderPhase(GbufferProgram program) {
super("iris:use_program", () -> GbufferPrograms.push(program), GbufferPrograms::pop);
super("iris:use_program", () -> GbufferPrograms.push(program), () -> GbufferPrograms.pop(program));
}
}
16 changes: 14 additions & 2 deletions src/main/java/net/coderbot/iris/mixin/MixinParticleManager.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.coderbot.iris.mixin;

import java.util.Iterator;
import java.util.Objects;

import net.coderbot.iris.layer.GbufferProgram;
import net.coderbot.iris.layer.GbufferPrograms;
import net.coderbot.iris.pipeline.ShaderPipeline;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -29,6 +31,9 @@ public class MixinParticleManager {
private static final String RENDER_PARTICLES = "renderParticles(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/client/render/Camera;F)V";
private static final String DRAW = "Lnet/minecraft/client/particle/ParticleTextureSheet;draw(Lnet/minecraft/client/render/Tessellator;)V";

@Unique
private ParticleTextureSheet lastSheet;

@Inject(method = RENDER_PARTICLES, at = @At("HEAD"))
private void iris$beginDrawingParticles(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate,
LightmapTextureManager lightmapTextureManager, Camera camera, float f,
Expand All @@ -42,19 +47,26 @@ public class MixinParticleManager {
CallbackInfo ci, Iterator<ParticleTextureSheet> sheets, ParticleTextureSheet sheet,
Iterable<Particle> particles, Tessellator tessellator) {
GbufferPrograms.push(ShaderPipeline.getProgramForSheet(sheet));

if (lastSheet != null) {
throw new IllegalStateException("Particle rendering in weird state: lastSheet != null, lastSheet = " + lastSheet);
}

lastSheet = sheet;
}

@Inject(method = RENDER_PARTICLES, at = @At(value = "INVOKE", target = DRAW, shift = At.Shift.AFTER))
private void iris$postDrawParticleSheet(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate,
LightmapTextureManager lightmapTextureManager, Camera camera, float f,
CallbackInfo ci) {
GbufferPrograms.pop();
GbufferPrograms.pop(ShaderPipeline.getProgramForSheet(Objects.requireNonNull(lastSheet)));
lastSheet = null;
}

@Inject(method = RENDER_PARTICLES, at = @At("RETURN"))
private void iris$finishDrawingParticles(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate,
LightmapTextureManager lightmapTextureManager, Camera camera, float f,
CallbackInfo ci) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.TEXTURED_LIT);
}
}
14 changes: 7 additions & 7 deletions src/main/java/net/coderbot/iris/mixin/MixinWorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public class MixinWorldRenderer {
private void iris$renderSky$enableTexture(MatrixStack matrices, float tickDelta, CallbackInfo callback) {
if (!skyTextureEnabled) {
skyTextureEnabled = true;
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.SKY_BASIC);
}
}

@Inject(method = RENDER_SKY, at = @At("RETURN"))
private void iris$renderSky$end(MatrixStack matrices, float tickDelta, CallbackInfo callback) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.SKY_TEXTURED);
}

@Inject(method = RENDER_CLOUDS, at = @At("HEAD"))
Expand All @@ -91,7 +91,7 @@ public class MixinWorldRenderer {

@Inject(method = RENDER_CLOUDS, at = @At("RETURN"))
private void iris$endClouds(MatrixStack matrices, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo callback) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.CLOUDS);
}

@Inject(method = RENDER_LAYER, at = @At("HEAD"))
Expand All @@ -108,9 +108,9 @@ public class MixinWorldRenderer {
@Inject(method = RENDER_LAYER, at = @At("RETURN"))
private void iris$endTerrainLayer(RenderLayer renderLayer, MatrixStack matrixStack, double cameraX, double cameraY, double cameraZ, CallbackInfo callback) {
if (renderLayer == RenderLayer.getSolid() || renderLayer == RenderLayer.getCutout() || renderLayer == RenderLayer.getCutoutMipped()) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.TERRAIN);
} else if (renderLayer == RenderLayer.getTranslucent() || renderLayer == RenderLayer.getTripwire()) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.TRANSLUCENT_TERRAIN);
} else {
throw new IllegalStateException("[Iris] Unexpected terrain layer: " + renderLayer);
}
Expand All @@ -123,7 +123,7 @@ public class MixinWorldRenderer {

@Inject(method = "renderWeather(Lnet/minecraft/client/render/LightmapTextureManager;FDDD)V", at = @At("RETURN"))
private void iris$endWeather(LightmapTextureManager manager, float f, double d, double e, double g, CallbackInfo callback) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.WEATHER);
}

@Inject(method = "renderWorldBorder(Lnet/minecraft/client/render/Camera;)V", at = @At("HEAD"))
Expand All @@ -133,7 +133,7 @@ public class MixinWorldRenderer {

@Inject(method = "renderWorldBorder(Lnet/minecraft/client/render/Camera;)V", at = @At("RETURN"))
private void iris$endWorldBorder(Camera camera, CallbackInfo callback) {
GbufferPrograms.pop();
GbufferPrograms.pop(GbufferProgram.TEXTURED_LIT);
}

// TODO: Need to figure out how to properly track these values (https://github.com/IrisShaders/Iris/issues/19)
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/net/coderbot/iris/pipeline/ShaderPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void pushProgram(GbufferProgram program) {
programStackLog.add("push:" + program);
}

public void popProgram() {
public void popProgram(GbufferProgram expected) {
if (!isRenderingWorld) {
// don't mess with non-world rendering
return;
Expand All @@ -132,6 +132,13 @@ public void popProgram() {
// This shouldn't have the same performance issues that remove() normally has since we're removing from the end
// every time.
GbufferProgram popped = programStack.remove(programStack.size() - 1);

if (popped != expected) {
Iris.logger.fatal("Program stack in invalid state, popped " + popped + " but expected to pop " + expected);
Iris.logger.fatal("Program stack content after pop: " + programStack);
throw new IllegalStateException("Program stack in invalid state, popped " + popped + " but expected to pop " + expected);
}

Pass poppedPass = getPass(popped);

if (poppedPass != null) {
Expand Down Expand Up @@ -407,11 +414,12 @@ public void beginWorldRender() {
}

public void endWorldRender() {
popProgram();
popProgram(GbufferProgram.BASIC);

if (!programStack.isEmpty()) {
Iris.logger.fatal("Program stack not empty at end of rendering, something has gone very wrong!");
Iris.logger.fatal("Program stack log: " + programStackLog);
Iris.logger.fatal("Program stack content: " + programStack);
throw new IllegalStateException("Program stack not empty at end of rendering, something has gone very wrong!");
}

Expand Down

0 comments on commit a38035e

Please sign in to comment.