diff --git a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java index f904ef285..d1ac6bba8 100644 --- a/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java +++ b/src/main/java/net/coderbot/iris/pipeline/transform/ShaderTransformer.java @@ -6,8 +6,13 @@ import net.coderbot.iris.gl.shader.ShaderType; import net.coderbot.iris.pipeline.transform.parameter.Parameters; import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters; +import org.antlr.v4.runtime.BailErrorStrategy; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ConsoleErrorListener; +import org.antlr.v4.runtime.DefaultErrorStrategy; +import org.antlr.v4.runtime.Parser; +import org.antlr.v4.runtime.atn.PredictionMode; import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.TerminalNode; import org.taumc.glsl.Util; @@ -130,6 +135,18 @@ public static

Map transform(Stri } } + private static void configureNoError(Parser parser) { + parser.setErrorHandler(new BailErrorStrategy()); + parser.removeErrorListeners(); + parser.getInterpreter().setPredictionMode(PredictionMode.SLL); + } + + private static void configureError(Parser parser) { + parser.setErrorHandler(new DefaultErrorStrategy()); + parser.addErrorListener(ConsoleErrorListener.INSTANCE); + parser.getInterpreter().setPredictionMode(PredictionMode.LL); + } + private static

Map transformInternal(EnumMap inputs, Patch patchType, P parameters) { EnumMap result = new EnumMap<>(PatchShaderType.class); EnumMap types = new EnumMap<>(PatchShaderType.class); @@ -186,28 +203,22 @@ private static

Map transformInte GLSLLexer lexer = new GLSLLexer(CharStreams.fromString(input)); GLSLParser parser = new GLSLParser(new CommonTokenStream(lexer)); parser.setBuildParseTree(true); - var translationUnit = parser.translation_unit(); - - switch(patchType) { - case SODIUM_TERRAIN: - SodiumTransformer.transform(translationUnit, parameters); - break; - case COMPOSITE: - CompositeDepthTransformer.transform(translationUnit); - break; - case ATTRIBUTES: - AttributeTransformer.transform(translationUnit, (AttributeParameters) parameters, profile, versionInt); - break; - default: - throw new IllegalStateException("Unknown patch type: " + patchType.name()); + configureNoError(parser); + + GLSLParser.Translation_unitContext translationUnit; + try { + translationUnit = doTransform(parser, patchType, parameters, profile, versionInt); + } catch (Exception e) { + lexer.reset(); + parser.reset(); + configureError(parser); + translationUnit = doTransform(parser, patchType, parameters, profile, versionInt); } // Check if we need to patch in texture LOD extension enabling if (versionInt <= 120 && (Util.containsCall(translationUnit, "texture2DLod") || Util.containsCall(translationUnit, "texture3DLod"))) { textureLodExtensionPatches.add(translationUnit); } - - CompatibilityTransformer.transformEach(translationUnit, parameters); types.put(type, translationUnit); prepatched.put(type, profileString); } @@ -230,6 +241,25 @@ private static

Map transformInte return result; } + private static GLSLParser.Translation_unitContext doTransform(GLSLParser parser, Patch patchType, Parameters parameters, String profile, int versionInt) { + GLSLParser.Translation_unitContext translationUnit = parser.translation_unit(); + switch (patchType) { + case SODIUM_TERRAIN: + SodiumTransformer.transform(translationUnit, parameters); + break; + case COMPOSITE: + CompositeDepthTransformer.transform(translationUnit); + break; + case ATTRIBUTES: + AttributeTransformer.transform(translationUnit, (AttributeParameters) parameters, profile, versionInt); + break; + default: + throw new IllegalStateException("Unknown patch type: " + patchType.name()); + } + CompatibilityTransformer.transformEach(translationUnit, parameters); + return translationUnit; + } + public static void applyIntelHd4000Workaround(GLSLParser.Translation_unitContext translationUnit) { Util.renameFunctionCall(translationUnit, "ftransform", "iris_ftransform"); }