Skip to content

Commit

Permalink
feat: Support assign linux dedicated gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Feb 2, 2024
1 parent 5134eee commit 6c7c771
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 420 deletions.
2 changes: 1 addition & 1 deletion xmcl
2 changes: 2 additions & 0 deletions xmcl-electron-app/main/definedPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { pluginUncaughtError } from '@xmcl/runtime/uncaughtError/pluginUncaughtE
import { LauncherAppPlugin } from '~/app'
import { definedServices } from './definedServices'
import { pluginSetupWorker } from './pluginSetupWorker'
import { pluginNvdiaGPULinux } from './pluginNvdiaGPULinux'

export const definedPlugins: LauncherAppPlugin[] = [
pluginAutoUpdate,
Expand All @@ -44,6 +45,7 @@ export const definedPlugins: LauncherAppPlugin[] = [
pluginEncodingWorker,
pluginSetupWorker,
pluginLaunchPrecheck,
pluginNvdiaGPULinux,
pluginUncaughtError,

pluginMediaProtocol,
Expand Down
29 changes: 29 additions & 0 deletions xmcl-electron-app/main/pluginNvdiaGPULinux.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { app as elec } from 'electron'
import { LauncherAppPlugin } from '~/app'
import { LaunchService } from '~/launch'
import { kSettings } from '~/settings'

export const pluginNvdiaGPULinux: LauncherAppPlugin = async (app) => {
app.registry.get(LaunchService).then((servi) => {
servi.registerMiddleware({
name: 'nvidia-gpu-linux',
async onBeforeLaunch(input, output) {
if (app.platform.os !== 'linux') return
const settings = await app.registry.get(kSettings)
if (settings.linuxEnableDedicatedGPUOptimization) {
const env = output.extraExecOption?.env || {}
const info = (await elec.getGPUInfo('basic')) as any
const gpus =
info?.gpuDevice
?.filter((v: any) => v?.vendorId !== 5140)
.map((v: any) => v.vendorId) || []
if (gpus.some((g: string) => g?.toLowerCase().includes('nvidia'))) {
env.__NV_PRIME_RENDER_OFFLOAD = '1'
env.__GLX_VENDOR_LIBRARY_NAME = 'nvidia'
output.extraExecOption = { ...output.extraExecOption, env }
}
}
},
})
})
}
2 changes: 1 addition & 1 deletion xmcl-electron-app/main/pluginPowerMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const pluginPowerMonitor: LauncherAppPlugin = async (app) => {

app.registry.get(LaunchService).then((servi) => {
servi.registerMiddleware({
name: 'gpu-optimization',
name: 'power-plan-monitor',
async onBeforeLaunch(input, output) {
const javaPath = output.javaPath
try {
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ setting:
focus: Layout der Fokussierung
layoutDescription: Layout des Launcher, der verschiedene Logiken der Benutzeroberfläche anzeigt
layoutTitle: Layout
linuxEnableDedicatedGPUOptimization: Weisen Sie eine dedizierte GPU zu
linuxEnableDedicatedGPUOptimizationDescription: Diese Option weist dem Minecraft-Prozess eine dedizierte GPU zu.
linuxTitlebar: Native Titelleiste
linuxTitlebarDescription: Verwenden Sie die native Linux-Titelleiste für den Launcher
location: Speicherort
Expand All @@ -1239,6 +1241,7 @@ setting:
insgesamt. 0 bedeutet keine Einschränkungen.
maxSocketsTitle: Maximale Anzahl von HTTP-Sockets
name: Globale Einstellungen | Globale Einstellungen
network: Netzwerkeinstellungen
officialWebsite: Офіційний сайт
particleMode:
bubble: Blasen
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ setting:
focus: Focus Layout
layoutDescription: The launcher layout reprensenting different UI logic
layoutTitle: Layout
linuxEnableDedicatedGPUOptimization: Assign Dedicated GPU
linuxEnableDedicatedGPUOptimizationDescription: This option will assign dedicated GPU to Minecraft process.
linuxTitlebar: Native title bar
linuxTitlebarDescription: Use native linux title bar for launcher
location: Store Location
Expand All @@ -1158,6 +1160,7 @@ setting:
total. 0 means no limit.
maxSocketsTitle: Max HTTP sockets
name: Global Setting | Global Settings
network: Network Settings
officialWebsite: Official Website
particleMode:
bubble: Bubble
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/es-ES.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,8 @@ setting:
El diseño del lanzador representa una lógica de interfaz de usuario
diferente
layoutTitle: Diseño
linuxEnableDedicatedGPUOptimization: Asignar GPU dedicada
linuxEnableDedicatedGPUOptimizationDescription: Esta opción asignará GPU dedicada al proceso de Minecraft.
linuxTitlebar: Barra de Título Nativa en Linux
linuxTitlebarDescription: Usar la barra de título nativa de Linux para el lanzador
location: Ubicación del Almacenamiento
Expand All @@ -887,6 +889,7 @@ setting:
los anfitriones. 0 significa sin límite.
maxSocketsTitle: Máximo de Conexiones HTTP
name: Configuración Global | Configuraciones Globales
network: Configuración de la red
officialWebsite: Sitio Web Oficial
particleMode:
bubble: Burbuja
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,8 @@ setting:
La disposition du launcher représentant différentes logiques d'interface
utilisateur
layoutTitle: Mise en page
linuxEnableDedicatedGPUOptimization: Attribuer un GPU dédié
linuxEnableDedicatedGPUOptimizationDescription: Cette option attribuera un GPU dédié au processus Minecraft.
linuxTitlebar: Barre de titre native
linuxTitlebarDescription: Utiliser la barre de titre Linux native pour le launcher
location: Emplacement du magasin
Expand All @@ -1198,6 +1200,7 @@ setting:
name: |-
Paramètre global |
Paramètres globaux
network: Paramètres réseau
officialWebsite: Site officiel
particleMode:
bubble: Bulles
Expand Down
2 changes: 2 additions & 0 deletions xmcl-keystone-ui/locales/gl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ launchBlocked:
mod:
searchOnCurseforge: Busca {name} en curseforge
setting:
linuxEnableDedicatedGPUOptimization: Asignar GPU dedicada
linuxEnableDedicatedGPUOptimizationDescription: Esta opción asignará unha GPU dedicada ao proceso de Minecraft.
maunalUpdateHint: |-
A versión non se pode actualizar automaticamente.
Volve descargar o iniciador do sitio web!
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,8 @@ setting:
focus: Макет фокусировки
layoutDescription: Макет лаунчера, отражающий различную логику пользовательского интерфейса
layoutTitle: Макет
linuxEnableDedicatedGPUOptimization: Назначить выделенный графический процессор
linuxEnableDedicatedGPUOptimizationDescription: Эта опция назначит выделенный графический процессор процессу Minecraft.
linuxTitlebar: Нативный заголовок окна
linuxTitlebarDescription: Использовать нативный заголовок окна Linux для лаунчера
location: Расположение хранилища
Expand All @@ -1119,6 +1121,7 @@ setting:
для всех хостов в целом. 0 означает отсутствие ограничений.
maxSocketsTitle: Максимальное количество HTTP-сокетов
name: Глобальная настройка | Глобальные настройки
network: Настройки сети
officialWebsite: Официальный сайт
particleMode:
bubble: Пузыри
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,8 @@ setting:
focus: Макет фокусування
layoutDescription: Макет лаунчера, що відображає різну логіку інтерфейсу користувача
layoutTitle: Макет
linuxEnableDedicatedGPUOptimization: Призначити виділений графічний процесор
linuxEnableDedicatedGPUOptimizationDescription: Ця опція призначить виділений графічний процесор для процесу Minecraft.
linuxTitlebar: Рідний рядок заголовка
linuxTitlebarDescription: Використовувати рідний рядок заголовка linux для панелі запуску
location: Розташування сховища
Expand All @@ -1167,6 +1169,7 @@ setting:
загалом. 0 означає відсутність обмежень.
maxSocketsTitle: Максимальна кількість HTTP-сокетів
name: Глобальне налаштування | Глобальні налаштування
network: Мережеві налаштування
officialWebsite: Офіційний сайт
particleMode:
bubble: Бульбашки
Expand Down
3 changes: 3 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,8 @@ setting:
focus: 聚焦布局
layoutDescription: 不同的布局有不同的UI交互逻辑
layoutTitle: 布局
linuxEnableDedicatedGPUOptimization: 分配专用 GPU
linuxEnableDedicatedGPUOptimizationDescription: 此选项将为 Minecraft 进程分配专用 GPU。
linuxTitlebar: 原生顶端栏
linuxTitlebarDescription: 使用 Linux 系统原生的顶端栏
location: 数据存储位置
Expand All @@ -1111,6 +1113,7 @@ setting:
maxSocketsDescription: 控制最大的并发 HTTP 链接数量。0 代表不限制数量。
maxSocketsTitle: 最大 HTTP 连接数量
name: 设置
network: 网络设置
officialWebsite: 官网地址
particleMode:
bubble: 气泡
Expand Down
26 changes: 26 additions & 0 deletions xmcl-keystone-ui/src/components/SettingHeader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div
class="v-heading w-full"
>
<h3 class="text-h5 my-4">
<slot />
</h3>
<v-divider />
</div>
</template>
<style scoped>
.v-heading {
display: inline-block;
top: 0;
padding: 0 16px;
z-index: 3;
}
.text-h5 {
font-size: 1.4rem !important;
font-weight: 400;
line-height: 1.8rem;
letter-spacing: normal !important;
font-family: "Roboto", sans-serif;
text-transform: none !important;
}
</style>
33 changes: 33 additions & 0 deletions xmcl-keystone-ui/src/components/SettingItemCheckbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<v-list-item @click="emit('input', !value)">
<v-list-item-action class="self-center">
<v-checkbox
v-model="model"
hide-details
@click.stop
/>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>
{{ title }}
</v-list-item-title>
<v-list-item-subtitle v-if="description">
{{ description }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
const props = defineProps<{
value: boolean
title: string
description?: string
}>()
const emit = defineEmits<{
(event: 'input', value: boolean): void
}>()
const model = useVModel(props, 'value', emit)
</script>
44 changes: 44 additions & 0 deletions xmcl-keystone-ui/src/components/SettingItemSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<template>
<v-list-item>
<v-list-item-content>
<v-list-item-title>
<slot
v-if="slots.title"
name="title"
/>
<template v-else>
{{ title }}
</template>
</v-list-item-title>
<v-list-item-subtitle>
{{ description }}
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-select
v-model="model"
filled
style="max-width: 185px"
hide-details
:items="items"
/>
</v-list-item-action>
</v-list-item>
</template>
<script setup lang="ts">
import { useVModel } from '@vueuse/core'
const props = defineProps<{
title: string
description?: string
select: string
items: Array<{ text: string; value: string }>
}>()
const emit = defineEmits<{
(event: 'update:select', value: string): void
}>()
const slots = useSlots()
const model = useVModel(props, 'select', emit)
</script>
18 changes: 5 additions & 13 deletions xmcl-keystone-ui/src/composables/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { InjectionKey, Ref } from 'vue'
import { useLocalStorageCacheBool } from './cache'
import { useState } from './syncableState'
import { useEnvironment } from './environment'
import useSWRV from 'swrv'

export function useUpdateSettings() {
const { checkUpdate } = useService(BaseServiceKey)
Expand Down Expand Up @@ -117,18 +116,10 @@ export function useSettings() {
get: () => locales.value.find(l => l.locale === state.value?.locale)?.locale || 'en',
set: v => state.value?.localeSet(v),
})
// const allowPrerelease = computed({
// get: () => state.allowPrerelease,
// set: v => state.allowPrereleaseSet(v),
// })
// const autoInstallOnAppQuit = computed({
// get: () => state.autoInstallOnAppQuit,
// set: v => state.autoInstallOnAppQuitSet(v),
// })
// const autoDownload = computed({
// get: () => state.autoDownload,
// set: v => state.autoDownloadSet(v),
// })
const linuxEnableDedicatedGPUOptimization = computed({
get: () => state.value?.linuxEnableDedicatedGPUOptimization ?? false,
set: v => state.value?.linuxEnableDedicatedGPUOptimizationSet(v),
})
const apiSetsPreference = computed({
get: () => state.value?.apiSetsPreference ?? '',
set: v => state.value?.apiSetsPreferenceSet(v),
Expand Down Expand Up @@ -184,6 +175,7 @@ export function useSettings() {
})

return {
linuxEnableDedicatedGPUOptimization,
developerMode,
httpProxyEnabled,
enableDiscord,
Expand Down
8 changes: 5 additions & 3 deletions xmcl-keystone-ui/src/views/Setting.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div
class="visible-scroll h-full overflow-auto p-4 xl:px-20 2xl:px-40"
<v-list
two-line
subheader
class="visible-scroll h-full w-full overflow-auto bg-transparent p-4 xl:px-20 2xl:px-40"
>
<SettingGeneral />
<SettingYggdrasilServices />
Expand All @@ -9,7 +11,7 @@
<SettingAppearance />
<SettingUpdateInfoDialog />
<SettingMigrationDialog />
</div>
</v-list>
</template>

<script lang=ts setup>
Expand Down

0 comments on commit 6c7c771

Please sign in to comment.