Skip to content

Commit e03ee7b

Browse files
authored
new: introduce density function compiler targetting jvm bytecode (#361)
2 parents 9bf0035 + 90262cc commit e03ee7b

File tree

98 files changed

+7872
-221
lines changed

Some content is hidden

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

98 files changed

+7872
-221
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.ishland.c2me.base.mixin.access;
2+
3+
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(ChunkNoiseSampler.class)
8+
public interface IChunkNoiseSampler {
9+
10+
@Accessor
11+
int getStartBlockX();
12+
13+
@Accessor
14+
int getStartBlockY();
15+
16+
@Accessor
17+
int getStartBlockZ();
18+
19+
@Accessor
20+
int getHorizontalCellBlockCount();
21+
22+
@Accessor
23+
int getVerticalCellBlockCount();
24+
25+
@Accessor
26+
boolean getIsInInterpolationLoop();
27+
28+
@Accessor
29+
boolean getIsSamplingForCaches();
30+
31+
@Accessor
32+
int getStartBiomeX();
33+
34+
@Accessor
35+
int getStartBiomeZ();
36+
37+
@Accessor
38+
int getHorizontalCellCount();
39+
40+
@Accessor
41+
int getVerticalCellCount();
42+
43+
@Accessor
44+
int getMinimumCellY();
45+
46+
@Accessor
47+
int getCellBlockX();
48+
49+
@Accessor
50+
int getCellBlockY();
51+
52+
@Accessor
53+
int getCellBlockZ();
54+
55+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ishland.c2me.base.mixin.access;
2+
3+
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Invoker;
6+
7+
@Mixin(ChunkNoiseSampler.DensityInterpolator.class)
8+
public interface IChunkNoiseSamplerDensityInterpolator {
9+
10+
@Invoker
11+
void invokeInterpolateX(double deltaX);
12+
13+
@Invoker
14+
void invokeInterpolateY(double deltaY);
15+
16+
@Invoker
17+
void invokeInterpolateZ(double deltaZ);
18+
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ishland.c2me.base.mixin.access;
2+
3+
import it.unimi.dsi.fastutil.doubles.Double2DoubleFunction;
4+
import net.minecraft.world.gen.densityfunction.DensityFunctionTypes;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
@Mixin(DensityFunctionTypes.WeirdScaledSampler.RarityValueMapper.class)
9+
public interface IDensityFunctionTypesWeirdScaledSamplerRarityValueMapper {
10+
11+
@Accessor
12+
Double2DoubleFunction getScaleFunction();
13+
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.ishland.c2me.base.mixin.access;
2+
3+
import net.minecraft.world.gen.densityfunction.DensityFunctions;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Invoker;
6+
7+
@Mixin(DensityFunctions.CaveScaler.class)
8+
public interface IDensityFunctionsCaveScaler {
9+
10+
@Invoker
11+
public static double invokeScaleCaves(double value) {
12+
throw new AbstractMethodError();
13+
}
14+
15+
@Invoker
16+
public static double invokeScaleTunnels(double value) {
17+
throw new AbstractMethodError();
18+
}
19+
20+
}

c2me-base/src/main/resources/c2me-base.accesswidener

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,40 @@ accessible class net/minecraft/client/option/SimpleOption$Callbacks
2020
accessible class net/minecraft/server/world/ServerChunkLoadingManager$TicketManager
2121
accessible class net/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator
2222
accessible class net/minecraft/server/world/ServerLightingProvider$Stage
23+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Noise
24+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Constant
2325
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$EndIslands
26+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Shift
27+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$ShiftA
28+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$ShiftB
29+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$YClampedGradient
30+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Clamp
31+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Unary
32+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$BinaryOperation
33+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$LinearOperation
34+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$LinearOperation$SpecificType
35+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$BinaryOperationLike
36+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$RegistryEntryHolder
37+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Wrapping
38+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Wrapping$Type
39+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Beardifier
40+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$BlendAlpha
41+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$BlendOffset
42+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$UnaryOperation
43+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$UnaryOperation$Type
44+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$ShiftedNoise
45+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$BlendDensity
46+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Positional
47+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$RangeChoice
48+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$WeirdScaledSampler
49+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Offset
50+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$FlatCache
51+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$Cache2D
52+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$CacheOnce
53+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$BlendAlphaDensityFunction
54+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$BlendOffsetDensityFunction
55+
accessible class net/minecraft/world/gen/chunk/ChunkNoiseSampler$CellCache
56+
accessible class net/minecraft/world/gen/densityfunction/DensityFunctions$CaveScaler
2457

2558
extendable class net/minecraft/client/option/SimpleOption
2659
extendable class net/minecraft/world/storage/RegionBasedStorage
@@ -31,6 +64,8 @@ accessible method net/minecraft/nbt/NbtCompound
3164
accessible method net/minecraft/nbt/NbtList <init> (Ljava/util/List;B)V
3265
accessible method net/minecraft/world/gen/surfacebuilder/MaterialRules$SequenceBlockStateRule <init> (Ljava/util/List;)V
3366
accessible method net/minecraft/world/storage/RegionBasedStorage <init> (Lnet/minecraft/world/storage/StorageKey;Ljava/nio/file/Path;Z)V
67+
accessible method net/minecraft/world/gen/densityfunction/DensityFunctionTypes$Wrapping <init> (Lnet/minecraft/world/gen/densityfunction/DensityFunctionTypes$Wrapping$Type;Lnet/minecraft/world/gen/densityfunction/DensityFunction;)V
68+
accessible method net/minecraft/world/gen/densityfunction/DensityFunctionTypes$RangeChoice <init> (Lnet/minecraft/world/gen/densityfunction/DensityFunction;DDLnet/minecraft/world/gen/densityfunction/DensityFunction;Lnet/minecraft/world/gen/densityfunction/DensityFunction;)V
3469

3570
extendable method net/minecraft/server/world/ChunkHolder combineSavingFuture (Ljava/util/concurrent/CompletableFuture;)V
3671
extendable method net/minecraft/server/world/ChunkHolder setCompletedLevel (I)V

c2me-base/src/main/resources/c2me-base.mixins.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
"access.IBlockEntity",
1313
"access.IChunkGenerator",
1414
"access.IChunkHolder",
15+
"access.IChunkNoiseSampler",
16+
"access.IChunkNoiseSamplerDensityInterpolator",
1517
"access.IChunkSection",
1618
"access.IChunkTicket",
1719
"access.IChunkTicketManager",
1820
"access.IChunkTicketManagerDistanceFromNearestPlayerTracker",
1921
"access.IChunkTicketManagerNearbyChunkTicketUpdater",
2022
"access.IChunkTickScheduler",
23+
"access.IDensityFunctionsCaveScaler",
24+
"access.IDensityFunctionTypesWeirdScaledSamplerRarityValueMapper",
2125
"access.IInterpolatedNoiseSampler",
2226
"access.IMultiNoiseBiomeSource",
2327
"access.INbtCompound",

c2me-opts-dfc/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
moduleDependencies(project, [
2+
"c2me-base",
3+
])
4+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.ishland.c2me.opts.dfc;
2+
3+
import com.ishland.c2me.base.common.config.ConfigSystem;
4+
5+
public class ModuleEntryPoint {
6+
7+
private static final boolean enabled = new ConfigSystem.ConfigAccessor()
8+
.key("vanillaWorldGenOptimizations.useDensityFunctionCompiler")
9+
.comment("""
10+
Whether to use density function compiler to accelerate world generation
11+
12+
Density function: https://minecraft.wiki/w/Density_function
13+
14+
This functionality compiles density functions from world generation
15+
datapacks (including vanilla generation) to JVM bytecode to increase
16+
performance by allowing JVM JIT to better optimize the code
17+
18+
Currently, all functions provided by vanilla are implemented.
19+
Chunk upgrades from pre-1.18 versions are not implemented and will
20+
fall back to the unoptimized version of density functions.
21+
""")
22+
.getBoolean(false, false);
23+
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ishland.c2me.opts.dfc.common.ast;
2+
3+
import com.ishland.c2me.opts.dfc.common.gen.BytecodeGen;
4+
import org.objectweb.asm.commons.InstructionAdapter;
5+
6+
public interface AstNode {
7+
8+
double evalSingle(int x, int y, int z, EvalType type);
9+
10+
void evalMulti(double[] res, int[] x, int[] y, int[] z, EvalType type);
11+
12+
AstNode[] getChildren();
13+
14+
AstNode transform(AstTransformer transformer);
15+
16+
void doBytecodeGenSingle(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer);
17+
18+
void doBytecodeGenMulti(BytecodeGen.Context context, InstructionAdapter m, BytecodeGen.Context.LocalVarConsumer localVarConsumer);
19+
20+
// data to be created as fields in generated code are only compared by class type
21+
boolean relaxedEquals(AstNode o);
22+
23+
int relaxedHashCode();
24+
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.ishland.c2me.opts.dfc.common.ast;
2+
3+
public interface AstTransformer {
4+
5+
AstNode transform(AstNode astNode);
6+
7+
}

0 commit comments

Comments
 (0)