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

#298 CPU版でGPUモードへの切り替えを不可能に #1140

Merged
merged 15 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 21 additions & 1 deletion src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@
{ label: 'CPU', value: 'switchCPU' },
{ label: 'GPU', value: 'switchGPU' },
]"
:disable="!canUseGPU"
>
<q-tooltip
anchor="center start"
self="center right"
transition-show="jump-left"
transition-hide="jump-right"
:target="!canUseGPU"
>
お使いのデバイスではGPUモードを利用できません。
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
</q-tooltip>
</q-btn-toggle>
</q-card-actions>
</q-card>
Expand Down Expand Up @@ -679,7 +689,7 @@
</template>

<script lang="ts">
import { defineComponent, computed, ref } from "vue";
import { defineComponent, computed, ref, onMounted } from "vue";
import { useStore } from "@/store";
import { useQuasar } from "quasar";
import {
Expand Down Expand Up @@ -714,6 +724,15 @@ export default defineComponent({
set: (val) => emit("update:modelValue", val),
});

const canUseGPU = computed({
get: () => store.state.canUseGPU,
set: () => {
store.dispatch("SET_CAN_USE_GPU");
},
});

onMounted(() => store.dispatch("SET_CAN_USE_GPU"));

const engineMode = computed({
get: () => (store.state.useGpu ? "switchGPU" : "switchCPU"),
set: (mode: string) => {
Expand Down Expand Up @@ -948,6 +967,7 @@ export default defineComponent({

return {
settingDialogOpenedComputed,
canUseGPU,
engineMode,
inheritAudioInfoMode,
activePointScrollMode,
Expand Down
6 changes: 6 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ export type SettingStoreTypes = {
export type UiStoreState = {
uiLockCount: number;
dialogLockCount: number;
canUseGPU: boolean;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
useGpu: boolean;
inheritAudioInfo: boolean;
activePointScrollMode: ActivePointScrollMode;
Expand Down Expand Up @@ -1185,6 +1186,11 @@ export type UiStoreTypes = {
RESET_PROGRESS: {
action(): void;
};

SET_CAN_USE_GPU: {
mutation: { canUseGPU: boolean };
action(): void;
};
};

/*
Expand Down
40 changes: 40 additions & 0 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function withProgress<T>(
export const uiStoreState: UiStoreState = {
uiLockCount: 0,
dialogLockCount: 0,
canUseGPU: false,
useGpu: false,
inheritAudioInfo: true,
activePointScrollMode: "OFF",
Expand Down Expand Up @@ -368,4 +369,43 @@ export const uiStore = createPartialStore<UiStoreTypes>({
dispatch("SET_PROGRESS", { progress: -1 });
},
},

SET_CAN_USE_GPU: {
mutation(state, { canUseGPU }) {
state.canUseGPU = canUseGPU;
},
async action({ commit, dispatch }) {
const engineInfos = await window.electron.engineInfos();

const engineIds = engineInfos.map((engineInfo) => engineInfo.uuid);

const canUseCudaOrDMLPromises = engineIds.map(async (engineId) =>
dispatch("INSTANTIATE_ENGINE_CONNECTOR", { engineId })
.then(
async (instance) =>
await instance.invoke("supportedDevicesSupportedDevicesGet")({})
)
.catch((e) => e)
);

const canUseCudaOrDMLArray = await Promise.all(canUseCudaOrDMLPromises);

const canUseGPU = canUseCudaOrDMLArray.reduce(
(prev, supportedDevices) => {
if (supportedDevices instanceof Error) {
return false;
}

const { cuda, dml } = supportedDevices;
const canEngineUseGPU = cuda || dml;

return prev && canEngineUseGPU;
},
true
);

// すべてのエンジンでcudaかdmlが利用可能ならtrue
commit("SET_CAN_USE_GPU", { canUseGPU: canUseGPU });
},
},
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
});