From dad5dd1b3bcec962a8c4d0a54b94f7ee3f7e4db2 Mon Sep 17 00:00:00 2001 From: IMS212 Date: Tue, 10 Dec 2024 09:08:00 -0800 Subject: [PATCH] Try making the unswizzle more reliable --- .../net/irisshaders/iris/gl/IrisRenderSystem.java | 15 +++++++++++++++ .../MixinGlStateManager_FramebufferBinding.java | 3 +++ .../iris/pipeline/programs/ExtendedShader.java | 8 +------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java b/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java index 00c859348b..19e8d80784 100644 --- a/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java +++ b/common/src/main/java/net/irisshaders/iris/gl/IrisRenderSystem.java @@ -6,6 +6,7 @@ import com.mojang.blaze3d.vertex.VertexSorting; import net.irisshaders.iris.Iris; import net.irisshaders.iris.gl.sampler.SamplerLimits; +import net.irisshaders.iris.gl.texture.TextureType; import net.irisshaders.iris.mixin.GlStateManagerAccessor; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -14,6 +15,7 @@ import org.joml.Vector3i; import org.lwjgl.opengl.ARBDirectStateAccess; import org.lwjgl.opengl.ARBDrawBuffersBlend; +import org.lwjgl.opengl.ARBTextureSwizzle; import org.lwjgl.opengl.EXTShaderImageLoadStore; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GL30C; @@ -44,6 +46,7 @@ public class IrisRenderSystem { private static int polygonMode = GL43C.GL_FILL; private static int backupPolygonMode = GL43C.GL_FILL; private static int[] samplers; + private static int textureToUnswizzle; public static void initRenderer() { if (GL.getCapabilities().OpenGL45) { @@ -486,6 +489,18 @@ public static void restoreCullingState() { cullingState = true; } + public static void onProgramUse() { + if (textureToUnswizzle != 0) { + IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, + new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA}); + textureToUnswizzle = 0; + } + } + + public static void setUnswizzle(int shaderTexture) { + textureToUnswizzle = shaderTexture; + } + public interface DSAAccess { void generateMipmaps(int texture, int target); diff --git a/common/src/main/java/net/irisshaders/iris/mixin/MixinGlStateManager_FramebufferBinding.java b/common/src/main/java/net/irisshaders/iris/mixin/MixinGlStateManager_FramebufferBinding.java index 972e74b2cb..a81d0b5db5 100644 --- a/common/src/main/java/net/irisshaders/iris/mixin/MixinGlStateManager_FramebufferBinding.java +++ b/common/src/main/java/net/irisshaders/iris/mixin/MixinGlStateManager_FramebufferBinding.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.platform.GlConst; import com.mojang.blaze3d.platform.GlStateManager; +import net.irisshaders.iris.gl.IrisRenderSystem; import org.lwjgl.opengl.GL30C; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; @@ -54,6 +55,8 @@ public class MixinGlStateManager_FramebufferBinding { ci.cancel(); } + IrisRenderSystem.onProgramUse(); + iris$program = pInt0; } diff --git a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java index 77b3b172cc..3d1c0820ec 100644 --- a/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java +++ b/common/src/main/java/net/irisshaders/iris/pipeline/programs/ExtendedShader.java @@ -146,12 +146,6 @@ public void clear() { BlendModeOverride.restore(); } - if (intensitySwizzle && textureToUnswizzle != 0) { - IrisRenderSystem.texParameteriv(textureToUnswizzle, TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, - new int[]{GL30C.GL_RED, GL30C.GL_GREEN, GL30C.GL_BLUE, GL30C.GL_ALPHA}); - textureToUnswizzle = 0; - } - Minecraft.getInstance().getMainRenderTarget().bindWrite(false); super.clear(); @@ -184,7 +178,7 @@ public void apply() { GlStateManager._activeTexture(i); if (intensitySwizzle) { - this.textureToUnswizzle = RenderSystem.getShaderTexture(0); + IrisRenderSystem.setUnswizzle(RenderSystem.getShaderTexture(0)); IrisRenderSystem.texParameteriv(RenderSystem.getShaderTexture(0), TextureType.TEXTURE_2D.getGlType(), ARBTextureSwizzle.GL_TEXTURE_SWIZZLE_RGBA, new int[]{GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED, GL30C.GL_RED}); }