Skip to content

Commit 45bbcef

Browse files
committed
feat: Panama native optimization on java 25+
1 parent 48e01ee commit 45bbcef

File tree

22 files changed

+610
-89
lines changed

22 files changed

+610
-89
lines changed

build.gradle.kts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
import com.falsepattern.zanama.tasks.ZanamaTranslate
12
import com.falsepattern.zigbuild.options.ZigBuildOptions
23
import com.falsepattern.zigbuild.tasks.ZigBuildTask
34
import com.falsepattern.zigbuild.toolchain.ZigVersion
45

56
plugins {
67
id("com.falsepattern.fpgradle-mc") version "2.1.0"
8+
id("com.falsepattern.zanama") version "0.2.0"
79
id("com.falsepattern.zigbuild") version "0.1.1"
810
}
911

1012
group = "com.falsepattern"
1113

1214
minecraft_fp {
15+
java {
16+
modernRuntimeVersion = JavaVersion.VERSION_25
17+
}
1318
mod {
1419
modid = "falsetweaks"
1520
name = "FalseTweaks"
@@ -85,15 +90,50 @@ val zigBuildTask = tasks.register<ZigBuildTask>("buildNatives") {
8590
sourceFiles.from(layout.projectDirectory.dir("zig-util"))
8691
sourceFiles.from(layout.projectDirectory.file("build.zig"))
8792
sourceFiles.from(layout.projectDirectory.file("build.zig.zon"))
93+
94+
dependsOn("extractZanama")
95+
}
96+
97+
val translateJavaSourcesCpuID = layout.buildDirectory.dir("generated/sources/zanama/cpuid")
98+
val translateJavaSourcesFalseTweaks = layout.buildDirectory.dir("generated/sources/zanama/falsetweaks")
99+
100+
val zigTranslateCpuID = tasks.register<ZanamaTranslate>("zigTranslateCpuID") {
101+
from = zigPrefix.map { it.file("cpuid.json") }
102+
into = translateJavaSourcesCpuID
103+
rootPkg = "com.falsepattern.falsetweaks.modules.natives.panama"
104+
bindRoot = "falsetweaks"
105+
className = "CpuID_z"
106+
dependsOn(zigBuildTask)
107+
}
108+
val zigTranslateFalseTweaks = tasks.register<ZanamaTranslate>("zigTranslateFalseTweaks") {
109+
from = zigPrefix.map { it.file("FalseTweaks.json") }
110+
into = translateJavaSourcesFalseTweaks
111+
rootPkg = "com.falsepattern.falsetweaks.modules.natives.panama"
112+
bindRoot = "falsetweaks"
113+
className = "FalseTweaks_z"
114+
dependsOn(zigBuildTask)
88115
}
89116

117+
118+
val panamaNatives = jarInJar_fp("panama") {
119+
this.javaCompatibility = modern
120+
this.javaVersion = JavaVersion.VERSION_25
121+
this.artifactName = "falsetweaks-panama"
122+
this.artifactVersion = "1.0.0"
123+
}
124+
tasks.named<JavaCompile>(panamaNatives.compileJavaTaskName) {
125+
dependsOn(zigTranslateCpuID, zigTranslateFalseTweaks)
126+
}
127+
128+
panamaNatives.java.srcDirs(translateJavaSourcesCpuID, translateJavaSourcesFalseTweaks)
129+
90130
tasks.processResources.configure {
91131
dependsOn(zigBuildTask)
92-
from(configurations.compileClasspath.map { it.filter { file -> file.name.contains("megatraceservice") } }) {
93-
into("META-INF/falsepatternlib_repo/mega/megatraceservice/1.2.0/")
132+
into("META-INF/falsepatternlib_repo/mega/megatraceservice/1.2.0/") {
133+
from(configurations.compileClasspath.map { it.filter { file -> file.name.contains("megatraceservice") } })
94134
}
95-
from(zigPrefix.map { it.dir("lib") }) {
96-
into(minecraft_fp.mod.rootPkg.map { "/" + it.replace('.', '/') + "/modules/natives" } ) {
135+
into(minecraft_fp.mod.rootPkg.map { "/" + it.replace('.', '/') + "/modules/natives" } ) {
136+
from(zigPrefix.map { it.dir("lib") }) {
97137
include("*.pak")
98138
}
99139
}
@@ -102,7 +142,9 @@ tasks.processResources.configure {
102142
repositories {
103143
cursemavenEX()
104144
modrinthEX()
105-
exclusive(mavenpattern(), "com.falsepattern", "makamys", "org.embeddedt.celeritas")
145+
exclusive(mavenpattern(), "makamys", "org.embeddedt.celeritas") {
146+
includeModule("com.falsepattern", "falsepatternlib-mc1.7.10")
147+
}
106148
exclusive(mega(), "codechicken", "mega")
107149
exclusive(mega_uploads(), "optifine")
108150
exclusive(venmaven(), "com.ventooth")
@@ -119,6 +161,7 @@ dependencies {
119161
compileOnly("mega:megatraceservice:1.2.0")
120162
compileOnly("com.ventooth:swansong-mc1.7.10:1.2.1:dev")
121163
compileOnly("maven.modrinth:etfuturum:2.6.2:dev")
164+
add(panamaNatives.compileOnlyConfigurationName, "com.falsepattern:zanama-rt:0.2.0")
122165

123166
val beddiumVersion = "1.0.4"
124167
val beddiumVersionJ21 = "$beddiumVersion-j21"

build.zig

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,23 @@
2020

2121
const std = @import("std");
2222
const x86 = @import("src/main/zig/cpuid/x86_util.zig");
23+
const zanama = @import("zanama");
2324
pub fn build(b: *std.Build) void {
25+
const zanama_dep = b.dependency("zanama", .{});
26+
const zb = zanama.Build.init(b, .ReleaseFast, zanama_dep);
27+
28+
const packer = b.addExecutable(.{
29+
.name = "packer",
30+
.root_module = b.addModule("packer", .{
31+
.root_source_file = b.path("zig-util/packer.zig"),
32+
.target = b.graph.host,
33+
}),
34+
});
35+
const run_packer = b.addRunArtifact(packer);
36+
const natives_file = "natives.pak";
37+
const install_step = b.getInstallStep();
38+
install_step.dependOn(&b.addInstallLibFile(run_packer.addOutputFileArg(natives_file), natives_file).step);
2439
for ([_]std.Target.Os.Tag{.windows, .linux}) |os| {
25-
const packer = b.addExecutable(.{
26-
.name = "packer",
27-
.root_module = b.addModule("packer", .{
28-
.root_source_file = b.path("zig-util/packer.zig"),
29-
.target = b.graph.host,
30-
}),
31-
});
32-
const run_packer = b.addRunArtifact(packer);
33-
const natives_file = std.mem.concat(b.allocator, u8, &.{@tagName(os), ".pak"}) catch @panic("OOM");
34-
b.getInstallStep().dependOn(&b.addInstallLibFile(run_packer.addOutputFileArg(natives_file), natives_file).step);
3540
const baseline_target = b.resolveTargetQuery(.{
3641
.os_tag = os,
3742
.cpu_arch = .x86_64,
@@ -51,13 +56,14 @@ pub fn build(b: *std.Build) void {
5156
.optimize = .ReleaseFast,
5257
.strip = true,
5358
});
59+
const name = std.mem.concat(b.allocator, u8, &.{"jni-", @tagName(os)}) catch @panic("OOM");
5460
libjni_mod.addImport("jni", jni_module);
5561
const libjni = b.addLibrary(.{
5662
.linkage = .dynamic,
57-
.name = "jni",
63+
.name = name,
5864
.root_module = libjni_mod,
5965
});
60-
run_packer.addArg("jni");
66+
run_packer.addArg(name);
6167
run_packer.addFileArg(libjni.getEmittedBin());
6268
}
6369
{
@@ -66,37 +72,47 @@ pub fn build(b: *std.Build) void {
6672
.target = baseline_target,
6773
.optimize = .ReleaseSmall,
6874
.strip = true,
75+
.imports = &.{
76+
.{ .name = "zanama", .module = zanama_dep.module("api") },
77+
}
6978
});
70-
const libcpuid = b.addLibrary(.{
71-
.linkage = .dynamic,
72-
.name = "cpuid",
73-
.root_module = libcpuid_mod,
74-
});
75-
run_packer.addArg("cpuid");
76-
run_packer.addFileArg(libcpuid.getEmittedBin());
79+
const libs = zb.createZanamaLibsResolved("cpuid", libcpuid_mod, &.{baseline_target});
80+
for (libs.artifacts) |artifact| {
81+
run_packer.addArg(artifact.name);
82+
run_packer.addFileArg(artifact.getEmittedBin());
83+
}
84+
const install_json = b.addInstallFile(libs.json, "cpuid.json");
85+
install_json.step.dependOn(libs.json_step);
86+
install_step.dependOn(&install_json.step);
7787
}
78-
for (x86.supported_models) |model| {
79-
const target = b.resolveTargetQuery(.{
80-
.os_tag = os,
81-
.cpu_arch = .x86_64,
82-
.cpu_model = .{ .explicit = model },
83-
.abi = .gnu,
84-
});
88+
{
89+
var targets: [x86.supported_models.len]std.Build.ResolvedTarget = undefined;
90+
for (x86.supported_models, 0..) |model, i| {
91+
targets[i] = b.resolveTargetQuery(.{
92+
.os_tag = os,
93+
.cpu_arch = .x86_64,
94+
.cpu_model = .{ .explicit = model },
95+
.abi = .gnu,
96+
});
97+
}
8598
const lib_mod = b.createModule(.{
8699
.root_source_file = b.path("src/main/zig/lib.zig"),
87-
.target = target,
88100
.optimize = .ReleaseFast,
89101
.strip = true,
102+
.imports = &.{
103+
.{ .name = "zanama", .module = zanama_dep.module("api") },
104+
}
90105
});
91-
const name = std.mem.concat(b.allocator, u8, &.{"FalseTweaks-", model.name}) catch @panic("OOM");
92-
const lib = b.addLibrary(.{
93-
.linkage = .dynamic,
94-
.name = name,
95-
.root_module = lib_mod,
96-
});
97-
run_packer.addFileInput(lib_mod.root_source_file.?);
98-
run_packer.addArg(name);
99-
run_packer.addFileArg(lib.getEmittedBin());
106+
107+
const libs = zb.createZanamaLibsResolved("FalseTweaks", lib_mod, &targets);
108+
109+
for (libs.artifacts) |artifact| {
110+
run_packer.addArg(artifact.name);
111+
run_packer.addFileArg(artifact.getEmittedBin());
112+
}
113+
const install_json = b.addInstallFile(libs.json, "FalseTweaks.json");
114+
install_json.step.dependOn(libs.json_step);
115+
install_step.dependOn(&install_json.step);
100116
}
101117
}
102118
}

build.zig.zon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
.url = "git+https://github.com/FalsePattern/zig-jni/?ref=main#623722601e43367991e177b2bb68d93334ea0ab2",
99
.hash = "jni-0.0.1-qf3mHDEMBABJFhRTwdr-4hjeqHfRjq8WN1KolBYYM2S3",
1010
},
11+
.zanama = .{
12+
.path = "build/zanama",
13+
}
1114
},
1215
.paths = .{
1316
"build.zig",

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/camera/Native_ClippingHelperImplMixin.java renamed to src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/camera/JNI_ClippingHelperImplMixin.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,26 @@
3636

3737
@Mixin(value = ClippingHelperImpl.class,
3838
priority = 1100)
39-
public abstract class Native_ClippingHelperImplMixin extends ClippingHelper {
39+
public abstract class JNI_ClippingHelperImplMixin extends ClippingHelper {
4040
@Unique
4141
private float[] ft$nativeUploadFrustumArray;
4242

4343
@Inject(method = "init",
4444
at = @At("RETURN"),
4545
require = 1)
4646
private void upload(CallbackInfo ci) {
47-
if (Natives.isLoaded()) {
48-
val frustum = this.frustum;
49-
final float[] frust;
50-
if (this.ft$nativeUploadFrustumArray == null) {
51-
this.ft$nativeUploadFrustumArray = frust = new float[24];
52-
} else {
53-
frust = this.ft$nativeUploadFrustumArray;
54-
}
55-
for (int i = 0; i < 4; i++) {
56-
for (int j = 0; j < 6; j++) {
57-
frust[i * 6 + j] = frustum[j][i];
58-
}
47+
val frustum = this.frustum;
48+
final float[] frust;
49+
if (this.ft$nativeUploadFrustumArray == null) {
50+
this.ft$nativeUploadFrustumArray = frust = new float[24];
51+
} else {
52+
frust = this.ft$nativeUploadFrustumArray;
53+
}
54+
for (int i = 0; i < 4; i++) {
55+
for (int j = 0; j < 6; j++) {
56+
frust[i * 6 + j] = frustum[j][i];
5957
}
60-
Clipping.setFrustum(frust);
6158
}
59+
Clipping.setFrustum(frust);
6260
}
6361
}

src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/camera/Native_ClippingHelperMixin.java renamed to src/main/java/com/falsepattern/falsetweaks/mixin/mixins/client/camera/JNI_ClippingHelperMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import net.minecraft.client.renderer.culling.ClippingHelper;
3030

3131
@Mixin(ClippingHelper.class)
32-
public abstract class Native_ClippingHelperMixin {
32+
public abstract class JNI_ClippingHelperMixin {
3333
/**
3434
* @author FalsePattern
3535
* @reason Native optimization
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.mixin.mixins.client.camera;
24+
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
29+
import stubpackage.com.falsepattern.falsetweaks.modules.natives.panama.ClippingExtras;
30+
31+
import net.minecraft.client.renderer.culling.ClippingHelper;
32+
import net.minecraft.client.renderer.culling.ClippingHelperImpl;
33+
34+
@Mixin(value = ClippingHelperImpl.class,
35+
priority = 1100)
36+
public abstract class Panama_ClippingHelperImplMixin extends ClippingHelper {
37+
@Inject(method = "init",
38+
at = @At("RETURN"),
39+
require = 1)
40+
private void upload(CallbackInfo ci) {
41+
ClippingExtras.setFrustum(frustum);
42+
}
43+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of FalseTweaks.
3+
*
4+
* Copyright (C) 2022-2025 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalseTweaks is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, only version 3 of the License.
13+
*
14+
* FalseTweaks is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with FalseTweaks. If not, see <https://www.gnu.org/licenses/>.
21+
*/
22+
23+
package com.falsepattern.falsetweaks.mixin.mixins.client.camera;
24+
25+
import org.spongepowered.asm.mixin.Mixin;
26+
import org.spongepowered.asm.mixin.Overwrite;
27+
import stubpackage.com.falsepattern.falsetweaks.modules.natives.panama.Clipping;
28+
29+
import net.minecraft.client.renderer.culling.ClippingHelper;
30+
31+
@Mixin(ClippingHelper.class)
32+
public abstract class Panama_ClippingHelperMixin {
33+
/**
34+
* @author FalsePattern
35+
* @reason Native optimization
36+
*/
37+
@Overwrite
38+
public boolean isBoxInFrustum(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
39+
return Clipping.isBoxInFrustum((float) minX, (float) minY, (float) minZ, (float) maxX, (float) maxY, (float) maxZ);
40+
}
41+
}

src/main/java/com/falsepattern/falsetweaks/mixin/plugin/standard/Mixin.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public enum Mixin implements IMixins {
150150
client("ao.littletiles.LittleBlockRenderHelperMixin")),
151151

152152
ClippingHelper(Phase.EARLY,
153-
() -> ModuleConfig.CLIPPING_HELPER_OPTS && !(ModuleConfig.natives && Natives.isLoaded()),
153+
() -> ModuleConfig.CLIPPING_HELPER_OPTS && !(ModuleConfig.natives && (Natives.isJNI() || Natives.isPanama())),
154154
client("camera.Perf_ClippingHelperMixin")),
155155
ClippingHelper_NoFastCraft(Phase.EARLY,
156156
() -> ModuleConfig.CLIPPING_HELPER_OPTS,
@@ -163,10 +163,14 @@ public enum Mixin implements IMixins {
163163
ModuleConfig::THREADED_CHUNK_UPDATES,
164164
require(SwanSong),
165165
client("camera.swansong.Multi_ShaderEngineMixin")),
166-
ClippingHelper_Native(Phase.EARLY,
167-
() -> ModuleConfig.CLIPPING_HELPER_OPTS && ModuleConfig.natives && Natives.isLoaded(),
168-
client("camera.Native_ClippingHelperMixin",
169-
"camera.Native_ClippingHelperImplMixin")),
166+
ClippingHelper_JNI(Phase.EARLY,
167+
() -> ModuleConfig.CLIPPING_HELPER_OPTS && ModuleConfig.natives && Natives.isJNI(),
168+
client("camera.JNI_ClippingHelperMixin",
169+
"camera.JNI_ClippingHelperImplMixin")),
170+
ClippingHelper_Panama(Phase.EARLY,
171+
() -> ModuleConfig.CLIPPING_HELPER_OPTS && ModuleConfig.natives && Natives.isPanama(),
172+
client("camera.Panama_ClippingHelperMixin",
173+
"camera.Panama_ClippingHelperImplMixin")),
170174

171175
RenderDistance(Phase.EARLY,
172176
() -> ModuleConfig.UNLOCK_RENDER_DISTANCE,

0 commit comments

Comments
 (0)