Skip to content

Commit 4f26116

Browse files
committed
feat: vulkan implementation with cinnabar
1 parent de2be1a commit 4f26116

17 files changed

Lines changed: 674 additions & 124 deletions

File tree

build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ plugins {
1010
// This will cause loom to completely break apart and throw itself into oblivion.
1111
// I have no idea how to fix it, and honestly, I don't want to know.
1212

13+
allprojects {
14+
repositories {
15+
maven("https://pkg.frst.cloud/releases") {
16+
name = "frstCloudReleases"
17+
}
18+
maven("https://maven.logix.dev/snapshots")
19+
}
20+
}
21+
1322
subprojects {
1423
pluginManager.withPlugin("java") {
1524
apply(plugin = rootProject.libs.plugins.licenser.get().pluginId)

buildSrc/src/main/kotlin/org/polyfrost/gradle/addDependencies.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private val fabricApiModuleVersions = mapOf(
4242
"api-base-12109" to "0.5.2+2fa446b294", // 1.21.9
4343
"api-base-12110" to "1.0.0+14b92d8968", // 1.21.10
4444
"api-base-12111" to "1.0.5+4ebb5c0853", // 1.21.11
45-
"api-base-260100" to "2.0.0+574290ba7d", // 26.1
45+
"api-base-260100" to "2.0.3+ece06323c3", // 26.1
4646
"lifecycle-events-v1-common" to "1.1.0+2c3f108c81e6", // Common (Legacy Fabric API)
4747
"lifecycle-events-v1-10809" to "1.1.0+1.8.9+2c3f108c81e6", // 1.8.9
4848
"lifecycle-events-v1-11202" to "1.1.0+1.12.2+2c3f108c81e6", // 1.12.2
@@ -65,7 +65,7 @@ private val fabricApiModuleVersions = mapOf(
6565
"lifecycle-events-v1-12109" to "2.6.8+33df5e6e94", // 1.21.9
6666
"lifecycle-events-v1-12110" to "2.6.9+33df5e6e68", // 1.21.10
6767
"lifecycle-events-v1-12111" to "2.6.15+4ebb5c0853", // 1.21.11
68-
"lifecycle-events-v1-260100" to "4.0.2+a208210e7d", // 26.1
68+
"lifecycle-events-v1-260100" to "4.0.5+c82f0461c3", // 26.1
6969
"keybindings-api-v1-common" to "1.1.1+281301ea81e6", // Common (Legacy Fabric API)
7070
"keybindings-api-v1-10809" to "1.1.1+1.8.9+2c3f108c81e6", // 1.8.9
7171
"keybindings-api-v1-11202" to "1.1.1+1.12.2+2c3f108c81e6", // 1.12.2
@@ -88,7 +88,7 @@ private val fabricApiModuleVersions = mapOf(
8888
"key-binding-api-v1-12109" to "1.1.0+4ec8267494", // 1.21.9
8989
"key-binding-api-v1-12110" to "1.1.1+b3ba9c4868", // 1.21.10
9090
"key-binding-api-v1-12111" to "1.1.7+4fc5413f53", // 1.21.11
91-
"key-mapping-api-v1-260100" to "2.0.0+574290ba7d", // 26.1
91+
"key-mapping-api-v1-260100" to "2.0.4+e2bdee78c3", // 26.1
9292
"rendering-api-v1-common" to "1.0.0+7c545fdb81e6", // Common (Legacy Fabric API)
9393
"rendering-api-v1-10809" to "1.0.0+1.8.9+2c3f108c81e6", // 1.8.9
9494
"rendering-api-v1-11202" to "1.0.0+1.8.9+2c3f108c81e6", // 1.12.2
@@ -111,7 +111,7 @@ private val fabricApiModuleVersions = mapOf(
111111
"rendering-v1-12109" to "15.0.2+9bce411b94", // 1.21.9
112112
"rendering-v1-12110" to "16.0.1+328a75ba68", // 1.21.10
113113
"rendering-v1-12111" to "16.2.5+1fb1cde953", // 1.21.11
114-
"rendering-v1-260100" to "18.0.0+a9f246707d", // 26.1
114+
"rendering-v1-260100" to "23.0.2+f348b6c3c3", // 26.1
115115
"screen-api-v1-11605" to "1.0.1+3cc0f0907d", // 1.16.5
116116
"screen-api-v1-11701" to "1.0.5+cf39a74318", // 1.17.1
117117
"screen-api-v1-11802" to "1.0.11+d882b91560", // 1.18.2
@@ -131,7 +131,7 @@ private val fabricApiModuleVersions = mapOf(
131131
"screen-api-v1-12109" to "3.0.2+86b3ae5794", // 1.21.9
132132
"screen-api-v1-12110" to "3.1.0+9c82a79868", // 1.21.10
133133
"screen-api-v1-12111" to "3.1.7+4ebb5c0853", // 1.21.11
134-
"screen-api-v1-260100" to "4.0.0+574290ba7d", // 26.1
134+
"screen-api-v1-260100" to "5.0.1+d871b99ec3", // 26.1
135135
"command-api-v1-11605" to "1.1.3+3cc0f0907d", // 1.16.5
136136
"command-api-v1-11701" to "1.1.4+cf39a74318", // 1.17.1
137137
"command-api-v1-11802" to "1.1.10+d7c144a860", // 1.18.2
@@ -151,7 +151,7 @@ private val fabricApiModuleVersions = mapOf(
151151
"command-api-v2-12109" to "2.3.5+33df5e6e94", // 1.21.9
152152
"command-api-v2-12110" to "2.3.7+328a75ba68", // 1.21.10
153153
"command-api-v2-12111" to "2.4.6+4ebb5c0853", // 1.21.11
154-
"command-api-v2-260100" to "3.0.0+574290ba7d", // 26.1
154+
"command-api-v2-260100" to "3.0.5+e2bdee78c3", // 26.1
155155
"transitive-access-wideners-v1-11802" to "1.1.0+e747827960", // 1.18.2
156156
"transitive-access-wideners-v1-11902" to "1.3.3+08b73de490", // 1.19.2
157157
"transitive-access-wideners-v1-11904" to "3.3.0+1b5f819af4", // 1.19.4
@@ -169,7 +169,7 @@ private val fabricApiModuleVersions = mapOf(
169169
"transitive-access-wideners-v1-12109" to "6.5.2+5d9dbead94", // 1.21.9
170170
"transitive-access-wideners-v1-12110" to "6.5.3+41eb434368", // 1.21.10
171171
"transitive-access-wideners-v1-12111" to "7.0.7+1fb1cde953", // 1.21.11
172-
"transitive-access-wideners-v1-260100" to "8.0.1+a208210e7d", // 26.1
172+
"transitive-access-wideners-v1-260100" to "8.0.11+d871b99ec3", // 26.1
173173
)
174174

175175
/**
@@ -268,7 +268,7 @@ fun Project.provideIncludedDependencies(version: Triple<Int, Int, Int>?, loader:
268268
}
269269
if (version != null) {
270270
actualDeps.add(OCDependency("dev.deftu:textile-${shenanigans}-$loader:${libs.findVersion("textile").get().displayName}", true))
271-
actualDeps.add(OCDependency("dev.deftu:omnicore-${shenanigans}-$loader:${libs.findVersion("omnicore").get().displayName}", true))
271+
actualDeps.add(OCDependency("org.polyfrost:omnicore-${shenanigans}-$loader:${libs.findVersion("omnicore").get().displayName}", true))
272272
}
273273

274274
return actualDeps
@@ -289,6 +289,10 @@ fun Project.provideFabricApiDependency(version: Triple<Int, Int, Int>): List<OCD
289289
// Modern Fabric
290290
val finalList = mutableListOf<String>()
291291
finalList.addAll(fabricApiModules)
292+
if (version.first >= 2) {
293+
finalList.remove("screen-api-v1")
294+
finalList.remove("rendering-v1")
295+
}
292296
if (version.first >= 2 || version.second >= 18) {
293297
finalList.add("transitive-access-wideners-v1")
294298
}

gradle/libs.versions.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ copycat = "0.1.3"
2020
copycat-image-awt = "0.1.1"
2121

2222
# Per version
23-
textile = "1.0.0-beta.17"
23+
textile = "1.0.0-beta.18"
2424
omnicore = "1.0.0-beta.41"
2525
lwjgl = "3.3.3" # All downloaded by the isolated-lwjgl3-loader
2626

@@ -42,9 +42,9 @@ jetbrains-idea-ext = "1.3"
4242
log4j-api = "2.0-beta9" # used because this is the version that 1.8.9 supports, so we have to compile against the same (annoying)
4343

4444
# Compose
45-
compose = "1.10.2"
45+
compose = "1.11.0-alpha04"
4646
compose-navigation = "2.9.1"
47-
skiko = "0.9.37.4"
47+
skiko = "0.696.0"
4848

4949
lifecycle = "2.11.0-alpha01"
5050
viewmodel = "2.10.0-beta01"

minecraft/build.gradle.kts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import java.text.SimpleDateFormat
1919
import java.util.Date
2020
import java.util.function.Predicate
2121
import kotlin.io.path.absolutePathString
22+
import java.util.zip.ZipEntry
23+
import java.util.zip.ZipFile
24+
import java.util.zip.ZipOutputStream
2225
import java.lang.Boolean as JBoolean
2326

2427
plugins {
@@ -49,6 +52,7 @@ toolkitLoomHelper {
4952
useProperty("mixin.debug.export", "true", GameSide.CLIENT)
5053
useProperty("debugBytecode", "true", GameSide.CLIENT)
5154
useProperty("forge.logging.console.level", "debug", GameSide.CLIENT)
55+
useProperty("oshi.os.windows.wmi.timeout", "3000", GameSide.CLIENT)
5256
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX) {
5357
useProperty("fml.earlyprogresswindow", "false", GameSide.CLIENT)
5458
}
@@ -336,6 +340,10 @@ dependencies {
336340
ksp(rootProject.project(":modules:relocator"))
337341
annotationProcessor(rootProject.project(":modules:relocator"))
338342

343+
if (properties["minecraft.vulkan"] != null) {
344+
implementation("graphics.cinnabar:cinnabar-fabric:26.1-snapshot-9-0.0.7-beta-85-gd3508cc")
345+
}
346+
339347
for (project in rootProject.project(":modules").subprojects) {
340348
if ("relocator" in project.path) {
341349
compileOnly(project(project.path))
@@ -368,6 +376,60 @@ dependencies {
368376
compileOnly("net.azureaaron:dandelion:1.0.0-alpha.3") { isTransitive = false }
369377
}
370378
api("dev.deftu:enhancedeventbus:2.0.0") // TODO
379+
if (properties["minecraft.vulkan"] != null) {
380+
// i couldnt find a way to get it to work
381+
// soooooooooooooooooooooooooooooooo
382+
val fabricApiPatchSrc = configurations.create("fabricApiPatchSrc") {
383+
isCanBeConsumed = false
384+
isCanBeResolved = true
385+
}
386+
dependencies.add(fabricApiPatchSrc.name, "net.fabricmc.fabric-api:fabric-screen-api-v1:4.0.0+9f78a5a8ed") { isTransitive = false }
387+
dependencies.add(fabricApiPatchSrc.name, "net.fabricmc.fabric-api:fabric-rendering-v1:23.0.2+f348b6c3c3") { isTransitive = false }
388+
389+
val patchedFabricApiDir = layout.buildDirectory.dir("patched-fabric-api")
390+
391+
val patchFabricApiMods by tasks.registering {
392+
inputs.files(fabricApiPatchSrc)
393+
outputs.dir(patchedFabricApiDir)
394+
doLast {
395+
val outDir = patchedFabricApiDir.get().asFile
396+
outDir.mkdirs()
397+
val jarFiles: Set<File> = fabricApiPatchSrc.resolvedConfiguration.resolvedArtifacts.map { it.file }.toSet()
398+
for (jar: File in jarFiles) {
399+
val mixinJson: String? = when {
400+
"screen-api" in jar.name -> "fabric-screen-api-v1.mixins.json"
401+
"rendering-v1" in jar.name -> "fabric-rendering-v1.mixins.json"
402+
else -> null
403+
}
404+
val outFile = File(outDir, jar.name)
405+
ZipFile(jar).use { zf ->
406+
ZipOutputStream(outFile.outputStream().buffered()).use { zos ->
407+
zf.entries().asSequence().forEach { entry ->
408+
val bytes = zf.getInputStream(entry).readBytes()
409+
val content = if (mixinJson != null && entry.name == mixinJson) {
410+
var json = String(bytes)
411+
.replace("\"required\": true", "\"required\": false")
412+
.replace("\"defaultRequire\": 1", "\"defaultRequire\": 0")
413+
if ("rendering-v1" in mixinJson) {
414+
json = json.replace(Regex("\"client\"\\s*:\\s*\\[.*?\\]", RegexOption.DOT_MATCHES_ALL), "\"client\": []")
415+
}
416+
json.toByteArray()
417+
} else bytes
418+
zos.putNextEntry(ZipEntry(entry.name))
419+
zos.write(content)
420+
zos.closeEntry()
421+
}
422+
}
423+
}
424+
}
425+
}
426+
}
427+
428+
val patchedScreenApi = patchedFabricApiDir.map { it.file("fabric-screen-api-v1-4.0.0+9f78a5a8ed.jar") }
429+
val patchedRenderingV1 = patchedFabricApiDir.map { it.file("fabric-rendering-v1-23.0.2+f348b6c3c3.jar") }
430+
maybeModApi(files(patchedScreenApi) { builtBy(patchFabricApiMods) })
431+
maybeModApi(files(patchedRenderingV1) { builtBy(patchFabricApiMods) })
432+
}
371433
}
372434

373435
tasks {

minecraft/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ private static void registerEventHandlers() {
186186
EventManager.register(InitializationEvent.class, e -> HudManager.INSTANCE.initialize());
187187
EventManager.register(HudRenderEvent.class, e -> {
188188
if (!SkiaCtx.INSTANCE.isReady()) return;
189-
SkiaCtx.INSTANCE.queueDraw((Runnable) () -> {
189+
SkiaCtx.INSTANCE.queueHudDraw(() -> {
190190
var ctx = new RenderContext(SkiaCtx.INSTANCE.getCanvas());
191191
HudManager.INSTANCE.render(ctx, OmniClient.getWindow().getScreenWidth(), OmniClient.getWindow().getScreenHeight());
192192
});
193+
SkiaCtx.INSTANCE.drawNow();
193194
});
194195
EventManager.register(HudEditorToggleEvent.class, e -> {
195196
if (e.open) {

minecraft/src/main/java/org/polyfrost/oneconfig/internal/OneConfigMixinInit.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,15 @@ public List<String> getMixins() {
123123

124124
mixins.add("skia.Mixin_InitSkia");
125125
mixins.add("skia.Mixin_SkiaFrame");
126+
mixins.add("skia.Mixin_SkiaFrameVk");
126127
mixins.add("skia.Mixin_InitSkiaFontRenderer");
127128
mixins.add("skia.Mixin_FixComposeRaceCondition");
128129

130+
try {
131+
Class.forName("org.polyfrost.oneconfig.internal.ui.services.CinnabarVulkanService");
132+
mixins.add("skia.Mixin_CinnabarSkiaFlush");
133+
} catch (ClassNotFoundException ignored) {}
134+
129135
{
130136
Logger logger = LogManager.getLogger(OneConfigMixinInit.class);
131137
logger.info("Loaded {} non-common Mixins", mixins.size());

minecraft/src/main/java/org/polyfrost/oneconfig/internal/mixin/skia/Mixin_SkiaFrame.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ public class Mixin_SkiaFrame {
2121
SkiaCtx.INSTANCE.recreateSurface(this.framebufferWidth, this.framebufferHeight);
2222
}
2323

24-
@Inject(method = "updateDisplay", at = @At("HEAD"))
24+
@Inject(method = "updateDisplay", at = @At("HEAD"), require = 0)
2525
void impl$onDraw(CallbackInfo ci) {
26-
SkiaCtx.INSTANCE.draw();
26+
if (!SkiaCtx.INSTANCE.isVulkanMode()) {
27+
SkiaCtx.INSTANCE.draw();
28+
}
29+
}
30+
31+
@Inject(method = "updateDisplay(Lcom/mojang/blaze3d/TracyFrameCapture;)V", at = @At("HEAD"), require = 0)
32+
void impl$onDrawNew(CallbackInfo ci) {
33+
if (!SkiaCtx.INSTANCE.isVulkanMode()) {
34+
SkiaCtx.INSTANCE.draw();
35+
}
2736
}
2837
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.polyfrost.oneconfig.internal.mixin.skia;
2+
3+
import net.minecraft.client.Minecraft;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
6+
@Mixin(Minecraft.class)
7+
public class Mixin_SkiaFrameVk {
8+
}

0 commit comments

Comments
 (0)