Skip to content

Commit c6c2608

Browse files
committed
Merge remote-tracking branch 'origin/1.20.3' into 1.20.1
# Conflicts: # buildscript/src/main/java/Buildscript.java # src/main/resources/fabric.mod.json # src/sodiumCompatibility/java/net/coderbot/iris/compat/sodium/impl/shader_overrides/IrisChunkProgramOverrides.java
2 parents 48f219f + a3f561b commit c6c2608

File tree

51 files changed

+636
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+636
-141
lines changed

src/main/java/net/coderbot/iris/Iris.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.base.Throwables;
44
import com.mojang.blaze3d.platform.GlDebug;
55
import com.mojang.blaze3d.platform.InputConstants;
6+
import com.sun.jna.platform.unix.LibC;
67
import net.coderbot.iris.config.IrisConfig;
78
import net.coderbot.iris.gl.GLDebug;
89
import net.coderbot.iris.gl.shader.ShaderCompileException;
@@ -31,6 +32,7 @@
3132
import net.fabricmc.loader.api.Version;
3233
import net.minecraft.ChatFormatting;
3334
import net.minecraft.SharedConstants;
35+
import net.minecraft.Util;
3436
import net.minecraft.client.KeyMapping;
3537
import net.minecraft.client.Minecraft;
3638
import net.minecraft.client.multiplayer.ClientLevel;
@@ -42,6 +44,7 @@
4244
import net.minecraft.world.level.dimension.DimensionType;
4345
import org.jetbrains.annotations.NotNull;
4446
import org.lwjgl.glfw.GLFW;
47+
import org.lwjgl.system.Configuration;
4548

4649
import java.io.IOException;
4750
import java.io.InputStream;
@@ -87,6 +90,7 @@ public class Iris {
8790
private static KeyMapping reloadKeybind;
8891
private static KeyMapping toggleShadersKeybind;
8992
private static KeyMapping shaderpackScreenKeybind;
93+
private static KeyMapping wireframeKeybind;
9094

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

105+
static {
106+
// Custom fix only for me for Plasma 6
107+
if (FabricLoader.getInstance().isDevelopmentEnvironment() && Util.getPlatform() == Util.OS.LINUX && System.getProperty("user.name").contains("ims")) {
108+
LibC.INSTANCE.setenv("__GL_THREADED_OPTIMIZATIONS", "0", 1);
109+
Configuration.GLFW_LIBRARY_NAME.set("/usr/lib/libglfw.so");
110+
}
111+
}
112+
101113
// Change this for snapshots!
102114
private static String backupVersionNumber = "1.20.3";
103115

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

125138
try {
126139
if (!Files.exists(getShaderpacksDirectory())) {
@@ -248,9 +261,17 @@ public static void handleKeybinds(Minecraft minecraft) {
248261
}
249262
} else if (shaderpackScreenKeybind.consumeClick()) {
250263
minecraft.setScreen(new ShaderPackScreen(null));
264+
} else if (wireframeKeybind.consumeClick()) {
265+
if (irisConfig.areDebugOptionsEnabled() && minecraft.player != null && !Minecraft.getInstance().isLocalServer()) {
266+
minecraft.player.displayClientMessage(Component.literal("No cheating; wireframe only in singleplayer!"), false);
267+
}
251268
}
252269
}
253270

271+
public static boolean shouldActivateWireframe() {
272+
return irisConfig.areDebugOptionsEnabled() && wireframeKeybind.isDown();
273+
}
274+
254275
public static void toggleShaders(Minecraft minecraft, boolean enabled) throws IOException {
255276
irisConfig.setShadersEnabled(enabled);
256277
irisConfig.save();

src/main/java/net/coderbot/iris/features/FeatureFlags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum FeatureFlags {
1414
CUSTOM_IMAGES(() -> true, IrisRenderSystem::supportsImageLoadStore),
1515
PER_BUFFER_BLENDING(() -> true, IrisRenderSystem::supportsBufferBlending),
1616
COMPUTE_SHADERS(() -> true, IrisRenderSystem::supportsCompute),
17+
TESSELATION_SHADERS(() -> true, IrisRenderSystem::supportsTesselation),
1718
ENTITY_TRANSLUCENT(() -> true, () -> true),
1819
REVERSED_CULLING(() -> true, () -> true),
1920
SSBO(() -> true, IrisRenderSystem::supportsSSBO),

src/main/java/net/coderbot/iris/gl/IrisRenderSystem.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class IrisRenderSystem {
4242
private static DSAAccess dsaState;
4343
private static boolean hasMultibind;
4444
private static boolean supportsCompute;
45+
private static boolean supportsTesselation;
46+
private static int polygonMode = GL43C.GL_FILL;
47+
private static int backupPolygonMode = GL43C.GL_FILL;
4548
private static int[] samplers;
4649

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

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

6367
samplers = new int[SamplerLimits.get().getMaxTextureUnits()];
6468
}
@@ -365,6 +369,10 @@ public static boolean supportsCompute() {
365369
return supportsCompute;
366370
}
367371

372+
public static boolean supportsTesselation() {
373+
return supportsTesselation;
374+
}
375+
368376
public static int genSampler() {
369377
return GL33C.glGenSamplers();
370378
}
@@ -425,6 +433,23 @@ public static void deleteBuffers(int glId) {
425433
GL43C.glDeleteBuffers(glId);
426434
}
427435

436+
public static void setPolygonMode(int mode) {
437+
if (mode != polygonMode) {
438+
polygonMode = mode;
439+
GL43C.glPolygonMode(GL43C.GL_FRONT_AND_BACK, mode);
440+
}
441+
}
442+
443+
public static void overridePolygonMode() {
444+
backupPolygonMode = polygonMode;
445+
setPolygonMode(GL43C.GL_FILL);
446+
}
447+
448+
public static void restorePolygonMode() {
449+
setPolygonMode(backupPolygonMode);
450+
backupPolygonMode = GL43C.GL_FILL;
451+
}
452+
428453
public interface DSAAccess {
429454
void generateMipmaps(int texture, int target);
430455

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package net.coderbot.iris.gl.framebuffer;
2+
3+
public record ViewportData(float scale, float viewportX, float viewportY) {
4+
private static ViewportData DEFAULT = new ViewportData(1.0f, 0.0f, 0.0f);
5+
6+
public static ViewportData defaultValue() {
7+
return DEFAULT;
8+
}
9+
}

src/main/java/net/coderbot/iris/gl/shader/ShaderType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public enum ShaderType {
1313
VERTEX(GL20.GL_VERTEX_SHADER),
1414
GEOMETRY(GL32C.GL_GEOMETRY_SHADER),
1515
FRAGMENT(GL20.GL_FRAGMENT_SHADER),
16-
COMPUTE(GL43C.GL_COMPUTE_SHADER);
16+
COMPUTE(GL43C.GL_COMPUTE_SHADER),
17+
TESSELATION_CONTROL(GL43C.GL_TESS_CONTROL_SHADER),
18+
TESSELATION_EVAL(GL43C.GL_TESS_EVALUATION_SHADER);
1719

1820
public final int id;
1921

src/main/java/net/coderbot/iris/mixin/MixinGameRenderer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public class MixinGameRenderer {
6565
private ArrayList<Program> iris$reloadGeometryShaders() {
6666
ArrayList<Program> programs = Lists.newArrayList();
6767
programs.addAll(IrisProgramTypes.GEOMETRY.getPrograms().values());
68+
programs.addAll(IrisProgramTypes.TESS_CONTROL.getPrograms().values());
69+
programs.addAll(IrisProgramTypes.TESS_EVAL.getPrograms().values());
6870
return programs;
6971
}
7072

src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_DepthColorOverride.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.mojang.blaze3d.platform.GlStateManager;
44
import net.coderbot.iris.gl.blending.DepthColorStorage;
5+
import net.coderbot.iris.vertices.ImmediateState;
6+
import org.lwjgl.opengl.GL43C;
57
import org.spongepowered.asm.mixin.Mixin;
68
import org.spongepowered.asm.mixin.injection.At;
79
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.Redirect;
811
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
912

1013
@Mixin(GlStateManager.class)
@@ -24,4 +27,18 @@ public class MixinGlStateManager_DepthColorOverride {
2427
ci.cancel();
2528
}
2629
}
30+
31+
@Redirect(method = "_drawElements", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glDrawElements(IIIJ)V"), remap = false)
32+
private static void iris$modify(int mode, int count, int type, long indices) {
33+
if (mode == GL43C.GL_TRIANGLES && ImmediateState.usingTessellation) {
34+
mode = GL43C.GL_PATCHES;
35+
}
36+
37+
GL43C.glDrawElements(mode, count, type, indices);
38+
}
39+
40+
@Inject(method = "_glUseProgram", at = @At("TAIL"), remap = false)
41+
private static void iris$resetTessellation(int pInt0, CallbackInfo ci) {
42+
ImmediateState.usingTessellation = false;
43+
}
2744
}

src/main/java/net/coderbot/iris/mixin/MixinGlStateManager_FramebufferBinding.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
public class MixinGlStateManager_FramebufferBinding {
1717
private static int iris$drawFramebuffer = 0;
1818
private static int iris$readFramebuffer = 0;
19+
private static int iris$program = 0;
1920

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

47+
@Inject(method = "_glUseProgram", at = @At("HEAD"), cancellable = true, remap = false)
48+
private static void iris$avoidRedundantBind2(int pInt0, CallbackInfo ci) {
49+
if (iris$program == pInt0) {
50+
ci.cancel();
51+
} else {
52+
iris$program = pInt0;
53+
}
54+
}
55+
4656
@Inject(method = "_glDeleteFramebuffers(I)V", at = @At("HEAD"), remap = false)
4757
private static void iris$trackFramebufferDelete(int framebuffer, CallbackInfo ci) {
4858
if (iris$drawFramebuffer == framebuffer) {

src/main/java/net/coderbot/iris/mixin/MixinLevelRenderer.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import net.fabricmc.loader.api.FabricLoader;
77
import org.joml.Matrix4f;
88
import net.coderbot.iris.Iris;
9+
import net.coderbot.iris.fantastic.WrappingMultiBufferSource;
10+
import net.coderbot.iris.gl.IrisRenderSystem;
11+
import net.coderbot.iris.gl.program.Program;
912
import net.coderbot.iris.layer.IsOutlineRenderStateShard;
1013
import net.coderbot.iris.layer.OuterWrappedRenderType;
1114
import net.coderbot.iris.pipeline.HandRenderer;
@@ -17,12 +20,17 @@
1720
import net.coderbot.iris.uniforms.SystemTimeUniforms;
1821
import net.minecraft.client.Camera;
1922
import net.minecraft.client.Minecraft;
23+
import net.minecraft.client.multiplayer.ClientLevel;
2024
import net.minecraft.client.renderer.GameRenderer;
2125
import net.minecraft.client.renderer.LevelRenderer;
2226
import net.minecraft.client.renderer.LightTexture;
2327
import net.minecraft.client.renderer.RenderBuffers;
2428
import net.minecraft.client.renderer.RenderType;
2529
import net.minecraft.client.renderer.culling.Frustum;
30+
import net.minecraft.core.BlockPos;
31+
import net.minecraft.world.phys.Vec3;
32+
import org.jetbrains.annotations.Nullable;
33+
import org.lwjgl.opengl.GL43C;
2634
import org.spongepowered.asm.mixin.Final;
2735

2836
import org.spongepowered.asm.mixin.Mixin;
@@ -59,6 +67,9 @@ public class MixinLevelRenderer {
5967
@Shadow
6068
private Frustum cullingFrustum;
6169

70+
@Shadow
71+
private @Nullable ClientLevel level;
72+
6273
// Begin shader rendering after buffers have been cleared.
6374
// At this point we've ensured that Minecraft's main framebuffer is cleared.
6475
// This is important or else very odd issues will happen with shaders that have a final pass that doesn't write to
@@ -81,6 +92,10 @@ public class MixinLevelRenderer {
8192
if (pipeline.shouldDisableFrustumCulling()) {
8293
this.cullingFrustum = new NonCullingFrustum();
8394
}
95+
96+
if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) {
97+
IrisRenderSystem.setPolygonMode(GL43C.GL_LINE);
98+
}
8499
}
85100

86101
// Begin shader rendering after buffers have been cleared.
@@ -104,6 +119,10 @@ public class MixinLevelRenderer {
104119
Minecraft.getInstance().getProfiler().popPush("iris_final");
105120
pipeline.finalizeLevelRendering();
106121
pipeline = null;
122+
123+
if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) {
124+
IrisRenderSystem.setPolygonMode(GL43C.GL_FILL);
125+
}
107126
}
108127

109128
// Setup shadow terrain & render shadows before the main terrain setup. We need to do things in this order to

src/main/java/net/coderbot/iris/mixin/MixinProgramManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ public class MixinProgramManager {
1515
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getGeometry() != null) {
1616
((ExtendedShader) shader).getGeometry().close();
1717
}
18+
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessControl() != null) {
19+
((ExtendedShader) shader).getTessControl().close();
20+
}
21+
if (shader instanceof ExtendedShader && ((ExtendedShader) shader).getTessEval() != null) {
22+
((ExtendedShader) shader).getTessEval().close();
23+
}
1824
}
1925
}

0 commit comments

Comments
 (0)