Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat[Zink]: Allow Zink to use System Vulkan driver #434

Merged
merged 9 commits into from
Jul 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ public LaunchOptions getLaunchOptions(String version, JavaVersion javaVersion, F
.setServerIp(vs.getServerIp())
.setJavaAgents(javaAgents)
.setBEGesture(vs.isBeGesture())
.setVkDriverSystem(vs.isVKDriverSystem())
.setRenderer(vs.getRenderer());

File json = getModpackConfiguration(version);
Expand Down
18 changes: 18 additions & 0 deletions FCL/src/main/java/com/tungsten/fcl/setting/VersionSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ public void setBeGesture(boolean beGesture) {
beGestureProperty.set(beGesture);
}

private final BooleanProperty VKDriverSystemProperty = new SimpleBooleanProperty(this, "vulkanDriverSystem", true);

public BooleanProperty VKDriverSystemProperty() {
return VKDriverSystemProperty;
}

public boolean isVKDriverSystem() {
return VKDriverSystemProperty.get();
}

public void setVKDriverSystem(boolean vulkanDriverSystem) {
VKDriverSystemProperty.set(vulkanDriverSystem);
}

private final StringProperty controllerProperty = new SimpleStringProperty(this, "controller", "Default");

public StringProperty controllerProperty() {
Expand Down Expand Up @@ -370,6 +384,7 @@ public void addPropertyChangedListener(InvalidationListener listener) {
scaleFactorProperty.addListener(listener);
isolateGameDirProperty.addListener(listener);
beGestureProperty.addListener(listener);
VKDriverSystemProperty.addListener(listener);
controllerProperty.addListener(listener);
rendererProperty.addListener(listener);
}
Expand All @@ -391,6 +406,7 @@ public VersionSetting clone() {
versionSetting.setScaleFactor(getScaleFactor());
versionSetting.setIsolateGameDir(isIsolateGameDir());
versionSetting.setBeGesture(isBeGesture());
versionSetting.setVKDriverSystem(isVKDriverSystem());
versionSetting.setController(getController());
versionSetting.setRenderer(getRenderer());
return versionSetting;
Expand All @@ -415,6 +431,7 @@ public JsonElement serialize(VersionSetting src, Type typeOfSrc, JsonSerializati
obj.addProperty("notCheckGame", src.isNotCheckGame());
obj.addProperty("notCheckJVM", src.isNotCheckJVM());
obj.addProperty("beGesture", src.isBeGesture());
obj.addProperty("vulkanDriverSystem", src.isVKDriverSystem());
obj.addProperty("controller", src.getController());
obj.addProperty("renderer", src.getRenderer().ordinal());
obj.addProperty("isolateGameDir", src.isIsolateGameDir());
Expand Down Expand Up @@ -446,6 +463,7 @@ public VersionSetting deserialize(JsonElement json, Type typeOfT, JsonDeserializ
vs.setNotCheckGame(Optional.ofNullable(obj.get("notCheckGame")).map(JsonElement::getAsBoolean).orElse(false));
vs.setNotCheckJVM(Optional.ofNullable(obj.get("notCheckJVM")).map(JsonElement::getAsBoolean).orElse(false));
vs.setBeGesture(Optional.ofNullable(obj.get("beGesture")).map(JsonElement::getAsBoolean).orElse(false));
vs.setVKDriverSystem(Optional.ofNullable(obj.get("vulkanDriverSystem")).map(JsonElement::getAsBoolean).orElse(false));
vs.setController(Optional.ofNullable(obj.get("controller")).map(JsonElement::getAsString).orElse("Default"));
vs.setRenderer(FCLConfig.Renderer.values()[Optional.ofNullable(obj.get("renderer")).map(JsonElement::getAsInt).orElse(FCLConfig.Renderer.RENDERER_GL4ES.ordinal())]);
vs.setIsolateGameDir(Optional.ofNullable(obj.get("isolateGameDir")).map(JsonElement::getAsBoolean).orElse(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class VersionSettingPage extends FCLCommonPage implements ManageUI.Versio

private FCLSwitch isolateWorkingDirSwitch;
private FCLSwitch beGestureSwitch;
private FCLSwitch vulkanDriverSystemSwitch;
private FCLSwitch noGameCheckSwitch;
private FCLSwitch noJVMCheckSwitch;

Expand Down Expand Up @@ -119,6 +120,7 @@ private void create() {
specialSettingSwitch.addCheckedChangeListener();
isolateWorkingDirSwitch = findViewById(R.id.edit_game_dir);
beGestureSwitch = findViewById(R.id.edit_controller_injector);
vulkanDriverSystemSwitch = findViewById(R.id.vulkan_driver_system);
noGameCheckSwitch = findViewById(R.id.edit_not_check_game);
noJVMCheckSwitch = findViewById(R.id.edit_not_check_java);

Expand Down Expand Up @@ -286,6 +288,7 @@ public void loadVersion(Profile profile, String versionId) {
FXUtils.unbindBoolean(noGameCheckSwitch, lastVersionSetting.notCheckGameProperty());
FXUtils.unbindBoolean(noJVMCheckSwitch, lastVersionSetting.notCheckJVMProperty());
FXUtils.unbindBoolean(beGestureSwitch, lastVersionSetting.beGestureProperty());
FXUtils.unbindBoolean(vulkanDriverSystemSwitch, lastVersionSetting.VKDriverSystemProperty());
FXUtils.unbindSelection(javaSpinner, lastVersionSetting.javaProperty());
FXUtils.unbindSelection(rendererSpinner, lastVersionSetting.rendererProperty());
scaleFactorSeekbar.percentProgressProperty().unbindBidirectional(lastVersionSetting.scaleFactorProperty());
Expand All @@ -307,6 +310,7 @@ public void loadVersion(Profile profile, String versionId) {
FXUtils.bindBoolean(noGameCheckSwitch, versionSetting.notCheckGameProperty());
FXUtils.bindBoolean(noJVMCheckSwitch, versionSetting.notCheckJVMProperty());
FXUtils.bindBoolean(beGestureSwitch, versionSetting.beGestureProperty());
FXUtils.bindBoolean(vulkanDriverSystemSwitch, versionSetting.VKDriverSystemProperty());
FXUtils.bindSelection(javaSpinner, versionSetting.javaProperty());
FXUtils.bindSelection(rendererSpinner, versionSetting.rendererProperty());
scaleFactorSeekbar.percentProgressProperty().bindBidirectional(versionSetting.scaleFactorProperty());
Expand Down
36 changes: 36 additions & 0 deletions FCL/src/main/res/layout/page_version_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,42 @@

</androidx.appcompat.widget.LinearLayoutCompat>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>

<androidx.appcompat.widget.LinearLayoutCompat
android:minHeight="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">

<com.tungsten.fcllibrary.component.view.FCLTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:auto_text_tint="true"
android:layout_gravity="center"
android:singleLine="true"
android:text="@string/settings_fcl_vulkan_driver_system"/>

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>

<com.tungsten.fcllibrary.component.view.FCLSwitch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/vulkan_driver_system"/>

</androidx.appcompat.widget.LinearLayoutCompat>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
Expand Down
1 change: 1 addition & 0 deletions FCL/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@

<string name="settings_fcl_controller">Controller</string>
<string name="settings_fcl_controller_injector">BE Gesture</string>
<string name="settings_fcl_vulkan_driver_system">Allow zink to use System Vulkan driver</string>
<string name="settings_fcl_renderer">Renderer</string>
<string name="settings_fcl_renderer_gl4es" translatable="false">Holy GL4ES (OpenGL 2.1)</string>
<string name="settings_fcl_renderer_virgl" translatable="false">VirGLRenderer (OpenGL 4.3)</string>
Expand Down
20 changes: 20 additions & 0 deletions FCLCore/src/main/java/com/tungsten/fclcore/game/LaunchOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class LaunchOptions implements Serializable {
private Integer height;
private String serverIp;
private boolean beGesture;
private boolean vulkanDriverSystem;
private FCLConfig.Renderer renderer;

/**
Expand Down Expand Up @@ -165,6 +166,13 @@ public boolean isBeGesture() {
return beGesture;
}

/**
* vulkan Driver System
*/
public boolean isVKDriverSystem() {
return vulkanDriverSystem;
}

/**
* Renderer
*/
Expand Down Expand Up @@ -293,6 +301,13 @@ public boolean isBeGesture() {
return options.beGesture;
}

/**
* vulkanDriverSystem
*/
public boolean isVKDriverSystem() {
return options.vulkanDriverSystem;
}

/**
* Renderer
*/
Expand Down Expand Up @@ -384,6 +399,11 @@ public Builder setBEGesture(boolean beGesture) {
return this;
}

public Builder setVkDriverSystem(boolean vulkanDriverSystem) {
options.vulkanDriverSystem = vulkanDriverSystem;
return this;
}

public Builder setRenderer(FCLConfig.Renderer renderer) {
options.renderer = renderer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.tungsten.fclauncher.bridge.FCLBridge;
import com.tungsten.fclauncher.plugins.FFmpegPlugin;
import com.tungsten.fclauncher.utils.Architecture;
import com.tungsten.fclcore.game.LaunchOptions;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -139,6 +140,9 @@ private static void addCommonEnv(FCLConfig config, HashMap<String, String> envMa
envMap.put("PATH", FFmpegPlugin.libraryPath + ":" + envMap.get("PATH"));
envMap.put("LD_LIBRARY_PATH", FFmpegPlugin.libraryPath);
}
if (options.isVKDriverSystem()) {
envMap.put("VULKAN_DRIVER_SYSTEM", "1");
}
}

private static void addRendererEnv(FCLConfig config, HashMap<String, String> envMap) {
Expand Down
14 changes: 8 additions & 6 deletions FCLauncher/src/main/jni/glfw/osmesa_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ static void set_vulkan_ptr(void* ptr) {
}

void load_vulkan() {
if(getenv("VULKAN_DRIVER_SYSTEM") == NULL && android_get_device_api_level() >= 28) {
#ifdef ADRENO_POSSIBLE
void* result = load_turnip_vulkan();
if(result != NULL) {
printf("AdrenoSupp: Loaded Turnip, loader address: %p\n", result);
set_vulkan_ptr(result);
return;
}
void* result = load_turnip_vulkan();
if(result != NULL) {
printf("AdrenoSupp: Loaded Turnip, loader address: %p\n", result);
set_vulkan_ptr(result);
return;
}
#endif
}
printf("OSMDroid: loading vulkan regularly...\n");
void* vulkan_ptr = dlopen("libvulkan.so", RTLD_LAZY | RTLD_LOCAL);
printf("OSMDroid: loaded vulkan, ptr=%p\n", vulkan_ptr);
Expand Down
Loading