Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Dec 26, 2023
2 parents 61f0dc7 + e9d7799 commit 92c7ba3
Show file tree
Hide file tree
Showing 47 changed files with 615 additions and 121 deletions.
21 changes: 21 additions & 0 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Throwables;
import com.mojang.blaze3d.platform.GlDebug;
import com.mojang.blaze3d.platform.InputConstants;
import com.sun.jna.platform.unix.LibC;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.gl.GLDebug;
import net.coderbot.iris.gl.shader.ShaderCompileException;
Expand Down Expand Up @@ -31,6 +32,7 @@
import net.fabricmc.loader.api.Version;
import net.minecraft.ChatFormatting;
import net.minecraft.SharedConstants;
import net.minecraft.Util;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
Expand All @@ -42,6 +44,7 @@
import net.minecraft.world.level.dimension.DimensionType;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.Configuration;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -87,6 +90,7 @@ public class Iris {
private static KeyMapping reloadKeybind;
private static KeyMapping toggleShadersKeybind;
private static KeyMapping shaderpackScreenKeybind;
private static KeyMapping wireframeKeybind;

private static final Map<String, String> shaderPackOptionQueue = new HashMap<>();
// Flag variable used when reloading
Expand All @@ -98,6 +102,14 @@ public class Iris {
private static UpdateChecker updateChecker;
private static boolean fallback;

static {
// Custom fix only for me for Plasma 6
if (FabricLoader.getInstance().isDevelopmentEnvironment() && Util.getPlatform() == Util.OS.LINUX && System.getProperty("user.name").contains("ims")) {
LibC.INSTANCE.setenv("__GL_THREADED_OPTIMIZATIONS", "0", 1);
Configuration.GLFW_LIBRARY_NAME.set("/usr/lib/libglfw.so");
}
}

// Change this for snapshots!
private static String backupVersionNumber = "1.19.4";

Expand All @@ -121,6 +133,7 @@ public void onEarlyInitialize() {
reloadKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.reload", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_R, "iris.keybinds"));
toggleShadersKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.toggleShaders", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_K, "iris.keybinds"));
shaderpackScreenKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.shaderPackSelection", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "iris.keybinds"));
wireframeKeybind = KeyBindingHelper.registerKeyBinding(new KeyMapping("iris.keybind.wireframe", InputConstants.Type.KEYSYM, InputConstants.UNKNOWN.getValue(), "iris.keybinds"));

try {
if (!Files.exists(getShaderpacksDirectory())) {
Expand Down Expand Up @@ -248,9 +261,17 @@ public static void handleKeybinds(Minecraft minecraft) {
}
} else if (shaderpackScreenKeybind.consumeClick()) {
minecraft.setScreen(new ShaderPackScreen(null));
} else if (wireframeKeybind.consumeClick()) {
if (irisConfig.areDebugOptionsEnabled() && minecraft.player != null && !Minecraft.getInstance().isLocalServer()) {
minecraft.player.displayClientMessage(Component.literal("No cheating; wireframe only in singleplayer!"), false);
}
}
}

public static boolean shouldActivateWireframe() {
return irisConfig.areDebugOptionsEnabled() && wireframeKeybind.isDown();
}

public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IOException {
irisConfig.setShadersEnabled(enabled);
irisConfig.save();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/coderbot/iris/features/FeatureFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum FeatureFlags {
CUSTOM_IMAGES(() -> true, IrisRenderSystem::supportsImageLoadStore),
PER_BUFFER_BLENDING(() -> true, IrisRenderSystem::supportsBufferBlending),
COMPUTE_SHADERS(() -> true, IrisRenderSystem::supportsCompute),
TESSELATION_SHADERS(() -> true, IrisRenderSystem::supportsTesselation),
ENTITY_TRANSLUCENT(() -> true, () -> true),
REVERSED_CULLING(() -> true, () -> true),
SSBO(() -> true, IrisRenderSystem::supportsSSBO),
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class IrisRenderSystem {
private static DSAAccess dsaState;
private static boolean hasMultibind;
private static boolean supportsCompute;
private static boolean supportsTesselation;
private static int polygonMode = GL43C.GL_FILL;
private static int backupPolygonMode = GL43C.GL_FILL;
private static int[] samplers;

public static void initRenderer() {
Expand All @@ -59,6 +62,7 @@ public static void initRenderer() {
hasMultibind = GL.getCapabilities().OpenGL45 || GL.getCapabilities().GL_ARB_multi_bind;

supportsCompute = GL.getCapabilities().glDispatchCompute != MemoryUtil.NULL;
supportsTesselation = GL.getCapabilities().GL_ARB_tessellation_shader || GL.getCapabilities().OpenGL40;

samplers = new int[SamplerLimits.get().getMaxTextureUnits()];
}
Expand Down Expand Up @@ -365,6 +369,10 @@ public static boolean supportsCompute() {
return supportsCompute;
}

public static boolean supportsTesselation() {
return supportsTesselation;
}

public static int genSampler() {
return GL33C.glGenSamplers();
}
Expand Down Expand Up @@ -425,6 +433,23 @@ public static void deleteBuffers(int glId) {
GL43C.glDeleteBuffers(glId);
}

public static void setPolygonMode(int mode) {
if (mode != polygonMode) {
polygonMode = mode;
GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, mode);
}
}

public static void overridePolygonMode() {
backupPolygonMode = polygonMode;
setPolygonMode(GL43C.GL_FILL);
}

public static void restorePolygonMode() {
setPolygonMode(backupPolygonMode);
backupPolygonMode = GL43C.GL_FILL;
}

public interface DSAAccess {
void generateMipmaps(int texture, int target);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.coderbot.iris.gl.framebuffer;

public record ViewportData(float scale, float viewportX, float viewportY) {
private static ViewportData DEFAULT = new ViewportData(1.0f, 0.0f, 0.0f);

public static ViewportData defaultValue() {
return DEFAULT;
}
}
4 changes: 3 additions & 1 deletion src/main/java/net/coderbot/iris/gl/shader/ShaderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum ShaderType {
VERTEX(GL20.GL_VERTEX_SHADER),
GEOMETRY(GL32C.GL_GEOMETRY_SHADER),
FRAGMENT(GL20.GL_FRAGMENT_SHADER),
COMPUTE(GL43C.GL_COMPUTE_SHADER);
COMPUTE(GL43C.GL_COMPUTE_SHADER),
TESSELATION_CONTROL(GL43C.GL_TESS_CONTROL_SHADER),
TESSELATION_EVAL(GL43C.GL_TESS_EVALUATION_SHADER);

public final int id;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class MixinGameRenderer {
private ArrayList<Program> iris$reloadGeometryShaders() {
ArrayList<Program> programs = Lists.newArrayList();
programs.addAll(IrisProgramTypes.GEOMETRY.getPrograms().values());
programs.addAll(IrisProgramTypes.TESS_CONTROL.getPrograms().values());
programs.addAll(IrisProgramTypes.TESS_EVAL.getPrograms().values());
return programs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.mojang.blaze3d.platform.GlStateManager;
import net.coderbot.iris.gl.blending.DepthColorStorage;
import net.coderbot.iris.vertices.ImmediateState;
import org.lwjgl.opengl.GL43C;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GlStateManager.class)
Expand All @@ -24,4 +27,18 @@ public class MixinGlStateManager_DepthColorOverride {
ci.cancel();
}
}

@Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V"), remap = false)
private static void iris$modify(int mode, int count, int type, long indices) {
if (mode == GL43C.GL_TRIANGLES && ImmediateState.usingTessellation) {
mode = GL43C.GL_PATCHES;
}

GL43C.glDrawElements(mode, count, type, indices);
}

@Inject(method = "_glUseProgram", at = @At("TAIL"), remap = false)
private static void iris$resetTessellation(int pInt0, CallbackInfo ci) {
ImmediateState.usingTessellation = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class MixinGlStateManager_FramebufferBinding {
private static int iris$drawFramebuffer = 0;
private static int iris$readFramebuffer = 0;
private static int iris$program = 0;

@Inject(method = "_glBindFramebuffer(II)V", at = @At("HEAD"), cancellable = true, remap = false)
private static void iris$avoidRedundantBind(int target, int framebuffer, CallbackInfo ci) {
Expand Down Expand Up @@ -43,6 +44,15 @@ public class MixinGlStateManager_FramebufferBinding {
}
}

@Inject(method = "_glUseProgram", at = @At("HEAD"), cancellable = true, remap = false)
private static void iris$avoidRedundantBind2(int pInt0, CallbackInfo ci) {
if (iris$program == pInt0) {
ci.cancel();
} else {
iris$program = pInt0;
}
}

@Inject(method = "_glDeleteFramebuffers(I)V", at = @At("HEAD"), remap = false)
private static void iris$trackFramebufferDelete(int framebuffer, CallbackInfo ci) {
if (iris$drawFramebuffer == framebuffer) {
Expand Down
15 changes: 15 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,6 +7,7 @@
import org.joml.Matrix4f;
import net.coderbot.iris.Iris;
import net.coderbot.iris.fantastic.WrappingMultiBufferSource;
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.program.Program;
import net.coderbot.iris.layer.IsOutlineRenderStateShard;
import net.coderbot.iris.layer.OuterWrappedRenderType;
Expand All @@ -22,6 +23,7 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
Expand All @@ -31,6 +33,8 @@
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL43C;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.client.Options;

Expand Down Expand Up @@ -69,6 +73,9 @@ public class MixinLevelRenderer {
@Shadow
private Frustum cullingFrustum;

@Shadow
private @Nullable ClientLevel level;

// Begin shader rendering after buffers have been cleared.
// At this point we've ensured that Minecraft's main framebuffer is cleared.
// This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to
Expand All @@ -90,6 +97,10 @@ public class MixinLevelRenderer {
if (pipeline.shouldDisableFrustumCulling()) {
this.cullingFrustum = new NonCullingFrustum();
}

if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) {
IrisRenderSystem.setPolygonMode(GL43C.GL_LINE);
}
}

// Begin shader rendering after buffers have been cleared.
Expand All @@ -113,6 +124,10 @@ public class MixinLevelRenderer {
Minecraft.getInstance().getProfiler().popPush("iris_final");
pipeline.finalizeLevelRendering();
pipeline = null;

if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) {
IrisRenderSystem.setPolygonMode(GL43C.GL_FILL);
}
}

// Setup shadow terrain & render shadows before the main terrain setup. We need to do things in this order to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public class MixinProgramManager {
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getGeometry() != null) {
((ExtendedShader) shader).getGeometry().close();
}
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessControl() != null) {
((ExtendedShader) shader).getTessControl().close();
}
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessEval() != null) {
((ExtendedShader) shader).getTessEval().close();
}
}
}
9 changes: 8 additions & 1 deletion src/main/java/net/coderbot/iris/mixin/MixinProgramType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.coderbot.iris.pipeline.newshader.IrisProgramTypes;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL32C;
import org.lwjgl.opengl.GL42C;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
Expand All @@ -23,6 +24,12 @@ public class MixinProgramType {
IrisProgramTypes.GEOMETRY
= ProgramTypeAccessor.createProgramType("GEOMETRY", baseOrdinal, "geometry", ".gsh", GL32C.GL_GEOMETRY_SHADER);

$VALUES = ArrayUtils.addAll($VALUES, IrisProgramTypes.GEOMETRY);
IrisProgramTypes.TESS_CONTROL
= ProgramTypeAccessor.createProgramType("TESS_CONTROL", baseOrdinal + 1, "tess_control", ".tcs", GL42C.GL_TESS_CONTROL_SHADER);

IrisProgramTypes.TESS_EVAL
= ProgramTypeAccessor.createProgramType("TESS_EVAL", baseOrdinal + 2, "tess_eval", ".tes", GL42C.GL_TESS_EVALUATION_SHADER);

$VALUES = ArrayUtils.addAll($VALUES, IrisProgramTypes.GEOMETRY, IrisProgramTypes.TESS_CONTROL, IrisProgramTypes.TESS_EVAL);
}
}
11 changes: 2 additions & 9 deletions src/main/java/net/coderbot/iris/mixin/MixinShaderInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.blaze3d.shaders.Uniform;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.IrisRenderSystem;
import net.coderbot.iris.gl.blending.DepthColorStorage;
import net.coderbot.iris.pipeline.WorldRenderingPipeline;
import net.coderbot.iris.pipeline.newshader.CoreWorldRenderingPipeline;
Expand All @@ -13,9 +12,6 @@
import net.coderbot.iris.pipeline.newshader.fallback.FallbackShader;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.lwjgl.opengl.ARBTextureSwizzle;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -24,9 +20,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Objects;

@Mixin(ShaderInstance.class)
public abstract class MixinShaderInstance implements ShaderInstanceInterface {
Expand Down Expand Up @@ -85,11 +78,11 @@ private static boolean shouldOverrideShaders() {

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/GsonHelper;parse(Ljava/io/Reader;)Lcom/google/gson/JsonObject;"))
public void iris$setupGeometryShader(ResourceProvider resourceProvider, String string, VertexFormat vertexFormat, CallbackInfo ci) {
this.iris$createGeometryShader(resourceProvider, string);
this.iris$createExtraShaders(resourceProvider, string);
}

@Override
public void iris$createGeometryShader(ResourceProvider provider, String name) {
public void iris$createExtraShaders(ResourceProvider provider, String name) {
//no-op, used for ExtendedShader to call before the super constructor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,9 @@ private Pass createDefaultPass() {

private Pass createPass(ProgramSource source, InputAvailability availability, boolean shadow, ProgramId id) {
// TODO: Properly handle empty shaders?
Map<PatchShaderType, String> transformed = null; // 1.16 is the zombie haunting us all
String vertex = transformed.get(PatchShaderType.VERTEX);
String geometry = transformed.get(PatchShaderType.GEOMETRY);
String fragment = transformed.get(PatchShaderType.FRAGMENT);

ShaderPrinter.printProgram(source.getName()).addSources(transformed).print();

ProgramBuilder builder = ProgramBuilder.begin(source.getName(), vertex, geometry, fragment,
IrisSamplers.WORLD_RESERVED_TEXTURE_UNITS);

return createPassInner(builder, source.getParent().getPack().getIdMap(), source.getDirectives(), source.getParent().getPackDirectives(), availability, shadow, id);
return createPassInner(null, source.getParent().getPack().getIdMap(), source.getDirectives(), source.getParent().getPackDirectives(), availability, shadow, id);
}

private Pass createPassInner(ProgramBuilder builder, IdMap map, ProgramDirectives programDirectives,
Expand Down
Loading

0 comments on commit 92c7ba3

Please sign in to comment.