-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix abysmal tectonic performance w/ dfc
- Loading branch information
Showing
9 changed files
with
252 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MaxShortNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.ishland.c2me.opts.dfc.common.ast.binary; | ||
|
||
import com.ishland.c2me.opts.dfc.common.ast.AstNode; | ||
import com.ishland.c2me.opts.dfc.common.ast.EvalType; | ||
import com.ishland.c2me.opts.dfc.common.gen.BytecodeGen; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.Type; | ||
import org.objectweb.asm.commons.InstructionAdapter; | ||
|
||
public class MaxShortNode extends AbstractBinaryNode { | ||
|
||
private final double rightMax; | ||
|
||
public MaxShortNode(AstNode left, AstNode right, double rightMax) { | ||
super(left, right); | ||
this.rightMax = rightMax; | ||
} | ||
|
||
@Override | ||
protected AstNode newInstance(AstNode left, AstNode right) { | ||
return new MaxShortNode(left, right, this.rightMax); | ||
} | ||
|
||
@Override | ||
public double evalSingle(int x, int y, int z, EvalType type) { | ||
double evaled = this.left.evalSingle(x, y, z, type); | ||
return evaled >= this.rightMax ? evaled : Math.max(evaled, this.right.evalSingle(x, y, z, type)); | ||
} | ||
|
||
@Override | ||
public void evalMulti(double[] res, int[] x, int[] y, int[] z, EvalType type) { | ||
this.left.evalMulti(res, x, y, z, type); | ||
for (int i = 0; i < res.length; i++) { | ||
res[i] = res[i] >= this.rightMax ? res[i] : Math.max(res[i], this.right.evalSingle(x[i], y[i], z[i], type)); | ||
} | ||
} | ||
|
||
@Override | ||
public void doBytecodeGenSingle(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer) { | ||
String leftMethod = context.newSingleMethod(this.left); | ||
String rightMethod = context.newSingleMethod(this.right); | ||
|
||
Label minLabel = new Label(); | ||
|
||
context.callDelegateSingle(m, leftMethod); | ||
m.dup2(); | ||
m.dconst(this.rightMax); | ||
m.cmpl(Type.DOUBLE_TYPE); | ||
m.iflt(minLabel); | ||
m.areturn(Type.DOUBLE_TYPE); | ||
|
||
m.visitLabel(minLabel); | ||
context.callDelegateSingle(m, rightMethod); | ||
m.invokestatic( | ||
Type.getInternalName(Math.class), | ||
"max", | ||
Type.getMethodDescriptor(Type.DOUBLE_TYPE, Type.DOUBLE_TYPE, Type.DOUBLE_TYPE), | ||
false | ||
); | ||
m.areturn(Type.DOUBLE_TYPE); | ||
} | ||
|
||
@Override | ||
public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer) { | ||
context.delegateToSingle(m, localVarConsumer, this); | ||
m.areturn(Type.VOID_TYPE); | ||
} | ||
|
||
@Override | ||
protected void bytecodeGenMultiBody(InstructionAdapter m, int idx, int res1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
c2me-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/binary/MinShortNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.ishland.c2me.opts.dfc.common.ast.binary; | ||
|
||
import com.ishland.c2me.opts.dfc.common.ast.AstNode; | ||
import com.ishland.c2me.opts.dfc.common.ast.EvalType; | ||
import com.ishland.c2me.opts.dfc.common.gen.BytecodeGen; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.Type; | ||
import org.objectweb.asm.commons.InstructionAdapter; | ||
|
||
public class MinShortNode extends AbstractBinaryNode { | ||
|
||
private final double rightMin; | ||
|
||
public MinShortNode(AstNode left, AstNode right, double rightMin) { | ||
super(left, right); | ||
this.rightMin = rightMin; | ||
} | ||
|
||
@Override | ||
protected AstNode newInstance(AstNode left, AstNode right) { | ||
return new MinShortNode(left, right, this.rightMin); | ||
} | ||
|
||
@Override | ||
public double evalSingle(int x, int y, int z, EvalType type) { | ||
double evaled = this.left.evalSingle(x, y, z, type); | ||
return evaled <= this.rightMin ? evaled : Math.min(evaled, this.right.evalSingle(x, y, z, type)); | ||
} | ||
|
||
@Override | ||
public void evalMulti(double[] res, int[] x, int[] y, int[] z, EvalType type) { | ||
this.left.evalMulti(res, x, y, z, type); | ||
for (int i = 0; i < res.length; i++) { | ||
res[i] = res[i] <= this.rightMin ? res[i] : Math.min(res[i], this.right.evalSingle(x[i], y[i], z[i], type)); | ||
} | ||
} | ||
|
||
@Override | ||
public void doBytecodeGenSingle(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer) { | ||
String leftMethod = context.newSingleMethod(this.left); | ||
String rightMethod = context.newSingleMethod(this.right); | ||
|
||
Label minLabel = new Label(); | ||
|
||
context.callDelegateSingle(m, leftMethod); | ||
m.dup2(); | ||
m.dconst(this.rightMin); | ||
m.cmpg(Type.DOUBLE_TYPE); | ||
m.ifgt(minLabel); | ||
m.areturn(Type.DOUBLE_TYPE); | ||
|
||
m.visitLabel(minLabel); | ||
context.callDelegateSingle(m, rightMethod); | ||
m.invokestatic( | ||
Type.getInternalName(Math.class), | ||
"min", | ||
Type.getMethodDescriptor(Type.DOUBLE_TYPE, Type.DOUBLE_TYPE, Type.DOUBLE_TYPE), | ||
false | ||
); | ||
m.areturn(Type.DOUBLE_TYPE); | ||
} | ||
|
||
@Override | ||
public void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer) { | ||
context.delegateToSingle(m, localVarConsumer, this); | ||
m.areturn(Type.VOID_TYPE); | ||
} | ||
|
||
@Override | ||
protected void bytecodeGenMultiBody(InstructionAdapter m, int idx, int res1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...-opts-dfc/src/main/java/com/ishland/c2me/opts/dfc/common/ast/dfvisitor/StripBlending.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.ishland.c2me.opts.dfc.common.ast.dfvisitor; | ||
|
||
import net.minecraft.world.gen.chunk.ChunkNoiseSampler; | ||
import net.minecraft.world.gen.densityfunction.DensityFunction; | ||
import net.minecraft.world.gen.densityfunction.DensityFunctionTypes; | ||
|
||
public class StripBlending implements DensityFunction.DensityFunctionVisitor { | ||
|
||
public static final StripBlending INSTANCE = new StripBlending(); | ||
|
||
private StripBlending() { | ||
} | ||
|
||
@Override | ||
public DensityFunction apply(DensityFunction densityFunction) { | ||
return switch (densityFunction) { | ||
case ChunkNoiseSampler.BlendAlphaDensityFunction f -> DensityFunctionTypes.constant(1.0); | ||
case ChunkNoiseSampler.BlendOffsetDensityFunction f -> DensityFunctionTypes.constant(0.0); | ||
case DensityFunctionTypes.BlendAlpha f -> DensityFunctionTypes.constant(1.0); | ||
case DensityFunctionTypes.BlendOffset f -> DensityFunctionTypes.constant(0.0); | ||
default -> densityFunction; | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters