Skip to content

Commit

Permalink
update to glsl-transformer 2.0.0-pre10
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Mar 20, 2023
1 parent 3d91128 commit faeee46
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void getModDependencies(ModDependencyCollector d) {
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.anarres:jcpp:1.4.14"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(FabricMaven.URL, new MavenId(FabricMaven.GROUP_ID + ".fabric-api", "fabric-key-binding-api-v1", "1.0.12+54e5b2ec60"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));

jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre9"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("io.github.douira:glsl-transformer:2.0.0-pre10"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));
jij(d.addMaven(Maven.MAVEN_CENTRAL, new MavenId("org.antlr:antlr4-runtime:4.11.1"), ModDependencyFlag.COMPILE, ModDependencyFlag.RUNTIME));

if (SODIUM) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.coderbot.iris.Iris;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -18,6 +16,9 @@
import io.github.douira.glsl_transformer.ast.node.VersionStatement;
import io.github.douira.glsl_transformer.ast.print.PrintType;
import io.github.douira.glsl_transformer.ast.query.Root;
import io.github.douira.glsl_transformer.ast.query.RootSupplier;
import io.github.douira.glsl_transformer.ast.query.index.ExternalDeclarationIndex;
import io.github.douira.glsl_transformer.ast.query.index.NodeIndex;
import io.github.douira.glsl_transformer.ast.query.index.PrefixIdentifierIndex;
import io.github.douira.glsl_transformer.ast.transform.EnumASTTransformer;
import io.github.douira.glsl_transformer.token_filter.ChannelFilter;
Expand Down Expand Up @@ -156,11 +157,19 @@ public boolean isTokenAllowed(Token token) {

private static final List<String> internalPrefixes = List.of("iris_", "irisMain", "moj_import");

private static final RootSupplier PREFIX_UNORDERED_ED_EXACT = new RootSupplier(
NodeIndex::withUnordered,
PrefixIdentifierIndex::withPrefix,
ExternalDeclarationIndex::withOnlyExact);

static {
Root.identifierIndexFactory = PrefixIdentifierIndex::withPrefix;
transformer = new EnumASTTransformer<Parameters, PatchShaderType>(PatchShaderType.class) {
{
setRootSupplier(PREFIX_UNORDERED_ED_EXACT);
}

@Override
public TranslationUnit parseTranslationUnit(String input) throws RecognitionException {
public TranslationUnit parseTranslationUnit(Root rootInstance, String input) {
// parse #version directive using an efficient regex before parsing so that the
// parser can be set to the correct version
Matcher matcher = versionPattern.matcher(input);
Expand All @@ -174,7 +183,7 @@ public TranslationUnit parseTranslationUnit(String input) throws RecognitionExce
}
transformer.getLexer().version = version;

return super.parseTranslationUnit(input);
return super.parseTranslationUnit(rootInstance, input);
}
};
transformer.setTransformation((trees, parameters) -> {
Expand All @@ -198,7 +207,7 @@ public TranslationUnit parseTranslationUnit(String input) throws RecognitionExce
+ id.getName() + ". See debugging.md for more information.");
});

Root.indexBuildSession(tree, () -> {
Root.indexBuildSession(root, () -> {
VersionStatement versionStatement = tree.getVersionStatement();
if (versionStatement == null) {
throw new IllegalStateException("Missing the version statement!");
Expand Down Expand Up @@ -353,8 +362,8 @@ public static Map<PatchShaderType, String> patchSodium(String vertex, String geo
float positionScale, float positionOffset, float textureScale,
Object2ObjectMap<Tri<String, TextureType, TextureStage>, String> textureMap) {
return transform(vertex, geometry, fragment,
new SodiumParameters(Patch.SODIUM, textureMap, alpha, inputs, positionScale, positionOffset,
textureScale));
new SodiumParameters(Patch.SODIUM, textureMap, alpha, inputs, positionScale, positionOffset,
textureScale));
}

public static Map<PatchShaderType, String> patchComposite(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import io.github.douira.glsl_transformer.ast.node.external_declaration.ExternalDeclaration;
import io.github.douira.glsl_transformer.ast.query.Root;
import io.github.douira.glsl_transformer.ast.query.match.AutoHintedMatcher;
import io.github.douira.glsl_transformer.ast.query.match.Matcher;
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint;
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
import io.github.douira.glsl_transformer.parser.ParseShape;
import net.coderbot.iris.gl.shader.ShaderType;
import net.coderbot.iris.pipeline.transform.PatchShaderType;
import net.coderbot.iris.pipeline.transform.parameter.AttributeParameters;
Expand Down Expand Up @@ -123,7 +123,7 @@ private static void patchTextureMatrices(
}

private static final AutoHintedMatcher<ExternalDeclaration> uniformVec4EntityColor = new AutoHintedMatcher<>(
"uniform vec4 entityColor;", Matcher.externalDeclarationPattern);
"uniform vec4 entityColor;", ParseShape.EXTERNAL_DECLARATION);

// Add entity color -> overlay color attribute support.
public static void patchOverlayColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint;
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
import io.github.douira.glsl_transformer.ast.transform.Template;
import io.github.douira.glsl_transformer.parser.ParseShape;
import io.github.douira.glsl_transformer.util.Type;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.blending.AlphaTest;
Expand All @@ -36,11 +37,11 @@

public class CommonTransformer {
public static final AutoHintedMatcher<Expression> glTextureMatrix0 = new AutoHintedMatcher<>(
"gl_TextureMatrix[0]", Matcher.expressionPattern);
"gl_TextureMatrix[0]", ParseShape.EXPRESSION);
public static final AutoHintedMatcher<Expression> glTextureMatrix1 = new AutoHintedMatcher<>(
"gl_TextureMatrix[1]", Matcher.expressionPattern);
"gl_TextureMatrix[1]", ParseShape.EXPRESSION);
public static final Matcher<ExternalDeclaration> sampler = new Matcher<>(
"uniform Type name;", Matcher.externalDeclarationPattern) {
"uniform Type name;", ParseShape.EXTERNAL_DECLARATION) {
{
markClassedPredicateWildcard("type",
pattern.getRoot().identifierIndex.getUnique("Type").getAncestor(TypeSpecifier.class),
Expand All @@ -52,7 +53,7 @@ public class CommonTransformer {
};

private static final AutoHintedMatcher<Expression> glFragDataI = new AutoHintedMatcher<>(
"gl_FragData[index]", Matcher.expressionPattern) {
"gl_FragData[index]", ParseShape.EXPRESSION) {
{
markClassedPredicateWildcard("index",
pattern.getRoot().identifierIndex.getUnique("index").getAncestor(ReferenceExpression.class),
Expand Down Expand Up @@ -83,7 +84,7 @@ private static void renameAndWrapShadow(ASTParser t, Root root, String oldName,
id -> {
FunctionCallExpression functionCall = (FunctionCallExpression) id.getParent();
functionCall.getFunctionName().setName(innerName);
FunctionCallExpression wrapper = (FunctionCallExpression) t.parseExpression(id, "vec4()");
FunctionCallExpression wrapper = (FunctionCallExpression) t.parseExpression(root, "vec4()");
functionCall.replaceBy(wrapper);
wrapper.getParameters().add(functionCall);
});
Expand Down Expand Up @@ -146,7 +147,7 @@ public static void transform(
}
for (long index : replaceIndexesSet) {
tree.injectNode(ASTInjectionPoint.BEFORE_DECLARATIONS,
fragDataDeclaration.getInstanceFor(tree,
fragDataDeclaration.getInstanceFor(root,
new LiteralExpression(Type.INT32, index),
new Identifier("iris_FragData" + index)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint;
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
import io.github.douira.glsl_transformer.ast.transform.Template;
import io.github.douira.glsl_transformer.parser.ParseShape;
import io.github.douira.glsl_transformer.util.Type;
import net.coderbot.iris.Iris;
import net.coderbot.iris.gl.shader.ShaderType;
Expand All @@ -55,7 +56,7 @@ public class CompatibilityTransformer {
static Logger LOGGER = LogManager.getLogger(CompatibilityTransformer.class);

private static final AutoHintedMatcher<Expression> sildursWaterFract = new AutoHintedMatcher<>(
"fract(worldpos.y + 0.001)", Matcher.expressionPattern);
"fract(worldpos.y + 0.001)", ParseShape.EXPRESSION);

private static StorageQualifier getConstQualifier(TypeQualifier qualifier) {
if (qualifier == null) {
Expand Down Expand Up @@ -234,7 +235,7 @@ private static class DeclarationMatcher extends Matcher<ExternalDeclaration> {
private final StorageType storageType;

public DeclarationMatcher(StorageType storageType) {
super("out float name;", Matcher.externalDeclarationPattern);
super("out float name;", ParseShape.EXTERNAL_DECLARATION);
this.storageType = storageType;
}

Expand Down Expand Up @@ -591,7 +592,7 @@ public static void transformGrouped(

private static final Matcher<ExternalDeclaration> nonLayoutOutDeclarationMatcher = new Matcher<ExternalDeclaration>(
"out float name;",
Matcher.externalDeclarationPattern) {
ParseShape.EXTERNAL_DECLARATION) {
{
markClassWildcard("qualifier", pattern.getRoot().nodeIndex.getUnique(TypeQualifier.class));
markClassWildcard("type", pattern.getRoot().nodeIndex.getUnique(BuiltinNumericTypeSpecifier.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import io.github.douira.glsl_transformer.ast.node.external_declaration.ExternalDeclaration;
import io.github.douira.glsl_transformer.ast.query.Root;
import io.github.douira.glsl_transformer.ast.query.match.HintedMatcher;
import io.github.douira.glsl_transformer.ast.query.match.Matcher;
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint;
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
import io.github.douira.glsl_transformer.parser.ParseShape;

class CompositeDepthTransformer {
private static final HintedMatcher<ExternalDeclaration> uniformFloatCenterDepthSmooth = new HintedMatcher<>(
"uniform float name;", Matcher.externalDeclarationPattern, "centerDepthSmooth") {
"uniform float name;", ParseShape.EXTERNAL_DECLARATION, "centerDepthSmooth") {
{
markClassWildcard("name*",
pattern.getRoot().identifierIndex.getUnique("name").getAncestor(DeclarationMember.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import io.github.douira.glsl_transformer.ast.node.expression.ReferenceExpression;
import io.github.douira.glsl_transformer.ast.query.Root;
import io.github.douira.glsl_transformer.ast.query.match.AutoHintedMatcher;
import io.github.douira.glsl_transformer.ast.query.match.Matcher;
import io.github.douira.glsl_transformer.ast.transform.ASTInjectionPoint;
import io.github.douira.glsl_transformer.ast.transform.ASTParser;
import io.github.douira.glsl_transformer.parser.ParseShape;
import net.coderbot.iris.gl.shader.ShaderType;
import net.coderbot.iris.pipeline.transform.parameter.Parameters;

public class CompositeTransformer {
private static final AutoHintedMatcher<Expression> glTextureMatrix0To7 = new AutoHintedMatcher<Expression>(
"gl_TextureMatrix[index]", Matcher.expressionPattern) {
"gl_TextureMatrix[index]", ParseShape.EXPRESSION) {
{
markClassedPredicateWildcard("index",
pattern.getRoot().identifierIndex.getOne("index").getAncestor(ReferenceExpression.class),
Expand Down

0 comments on commit faeee46

Please sign in to comment.