Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ public void setNotPatchNatives(boolean notPatchNatives) {
notPatchNativesProperty.set(notPatchNatives);
}

private final BooleanProperty notAutoChooseGPUProperty = new SimpleBooleanProperty(this, "notAutoChooseGPU", false);

public BooleanProperty notAutoChooseGPUProperty() {
return notAutoChooseGPUProperty;

}

public boolean isNotAutoChooseGPU() {
return notAutoChooseGPUProperty.get();
}

public void setNotAutoChooseGPU(boolean notAutoChooseGPU) {
notAutoChooseGPUProperty.set(notAutoChooseGPU);
}

private final BooleanProperty showLogsProperty = new SimpleBooleanProperty(this, "showLogs", false);

public BooleanProperty showLogsProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public final class AdvancedVersionSettingPage extends StackPane implements Decor
private final OptionToggleButton noGameCheckPane;
private final OptionToggleButton noJVMCheckPane;
private final OptionToggleButton noNativesPatchPane;
private final OptionToggleButton noAutoChooseGPUPane;
private final OptionToggleButton useNativeGLFWPane;
private final OptionToggleButton useNativeOpenALPane;
private final ComponentSublist nativesDirSublist;
Expand Down Expand Up @@ -192,6 +193,9 @@ public AdvancedVersionSettingPage(Profile profile, @Nullable String versionId, V
noNativesPatchPane = new OptionToggleButton();
noNativesPatchPane.setTitle(i18n("settings.advanced.dont_patch_natives"));

noAutoChooseGPUPane = new OptionToggleButton();
noAutoChooseGPUPane.setTitle("不自动选择 GPU"); // TODO: i18n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

插个眼:建议用「显卡」这个术语。Windows 和隔壁 PCL 也是这么用的。


useNativeGLFWPane = new OptionToggleButton();
useNativeGLFWPane.setTitle(i18n("settings.advanced.use_native_glfw"));

Expand All @@ -200,7 +204,7 @@ public AdvancedVersionSettingPage(Profile profile, @Nullable String versionId, V

workaroundPane.getContent().setAll(
nativesDirSublist, rendererPane, noJVMArgsPane, noGameCheckPane,
noJVMCheckPane, noNativesPatchPane
noJVMCheckPane, noNativesPatchPane, noAutoChooseGPUPane
);

if (OperatingSystem.CURRENT_OS.isLinuxOrBSD()) {
Expand Down Expand Up @@ -236,6 +240,7 @@ void bindProperties() {
noJVMCheckPane.selectedProperty().bindBidirectional(versionSetting.notCheckJVMProperty());
noJVMArgsPane.selectedProperty().bindBidirectional(versionSetting.noJVMArgsProperty());
noNativesPatchPane.selectedProperty().bindBidirectional(versionSetting.notPatchNativesProperty());
noAutoChooseGPUPane.selectedProperty().bindBidirectional(versionSetting.notAutoChooseGPUProperty());
useNativeGLFWPane.selectedProperty().bindBidirectional(versionSetting.useNativeGLFWProperty());
useNativeOpenALPane.selectedProperty().bindBidirectional(versionSetting.useNativeOpenALProperty());

Expand Down Expand Up @@ -277,6 +282,7 @@ void unbindProperties() {
noJVMCheckPane.selectedProperty().unbindBidirectional(versionSetting.notCheckJVMProperty());
noJVMArgsPane.selectedProperty().unbindBidirectional(versionSetting.noJVMArgsProperty());
noNativesPatchPane.selectedProperty().unbindBidirectional(versionSetting.notPatchNativesProperty());
noAutoChooseGPUPane.selectedProperty().unbindBidirectional(versionSetting.notAutoChooseGPUProperty());
useNativeGLFWPane.selectedProperty().unbindBidirectional(versionSetting.useNativeGLFWProperty());
useNativeOpenALPane.selectedProperty().unbindBidirectional(versionSetting.useNativeOpenALProperty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.jackhuang.hmcl.util.io.Unzipper;
import org.jackhuang.hmcl.util.platform.Bits;
import org.jackhuang.hmcl.util.platform.*;
import org.jackhuang.hmcl.util.platform.hardware.GraphicsCard;
import org.jackhuang.hmcl.util.platform.hardware.HardwareVendor;
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;

import java.io.*;
Expand Down Expand Up @@ -524,7 +526,24 @@ private Map<String, String> getEnvVars() {
env.put("INST_JAVA", options.getJava().getBinary().toString());

Renderer renderer = options.getRenderer();
if (renderer != Renderer.DEFAULT) {
if (renderer == Renderer.DEFAULT) {
List<GraphicsCard> graphicsCards = SystemInfo.getGraphicsCards();
if (graphicsCards != null && graphicsCards.size() == 2) {
GraphicsCard card0 = graphicsCards.get(0);
GraphicsCard card1 = graphicsCards.get(1);

if (card0.getType() != null && card1.getType() != null
&& card0.getType() != card1.getType()) {
GraphicsCard discreteGraphicsCard = card0.getType() == GraphicsCard.Type.Discrete ? card0 : card1;
if (HardwareVendor.NVIDIA.equals(discreteGraphicsCard.getVendor())) {
// https://askubuntu.com/a/1350825
env.put("__NV_PRIME_RENDER_OFFLOAD", "1");
env.put("__GLX_VENDOR_LIBRARY_NAME", "nvidia");
env.put("__VK_LAYER_NV_optimus", "NVIDIA_only");
}
}
}
} else {
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
if (renderer != Renderer.LLVMPIPE)
env.put("GALLIUM_DRIVER", renderer.name().toLowerCase(Locale.ROOT));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public String getName() {
return name;
}

public @Nullable Type getType() {
return type;
}

public @Nullable HardwareVendor getVendor() {
return vendor;
}
Expand Down