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 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 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="!allEngineCanUseGPU"
>
<q-tooltip
anchor="center start"
self="center right"
transition-show="jump-left"
transition-hide="jump-right"
:target="!allEngineCanUseGPU"
>
お使いのエンジンはCPU版のためGPUモードを利用できません。
</q-tooltip>
</q-btn-toggle>
</q-card-actions>
</q-card>
Expand Down Expand Up @@ -714,6 +724,10 @@ export default defineComponent({
set: (val) => emit("update:modelValue", val),
});

const allEngineCanUseGPU = computed(
() => store.getters.ALL_ENGINE_CAN_USE_GPU
);

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

return {
settingDialogOpenedComputed,
allEngineCanUseGPU,
engineMode,
inheritAudioInfoMode,
activePointScrollMode,
Expand Down
46 changes: 46 additions & 0 deletions src/store/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { EngineInfo } from "@/type/preload";

export const engineStoreState: EngineStoreState = {
engineStates: {},
engineSupportedDevices: {},
};

export const engineStore = createPartialStore<EngineStoreTypes>({
Expand Down Expand Up @@ -195,6 +196,9 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
if (state.engineStates[engineId] === "STARTING") {
await dispatch("START_WAITING_ENGINE", { engineId });
await dispatch("FETCH_AND_SET_ENGINE_MANIFEST", { engineId });
await dispatch("FETCH_AND_SET_ENGINE_SUPPORTED_DEVICES", {
engineId,
});
await dispatch("LOAD_CHARACTER", { engineId });
}

Expand Down Expand Up @@ -360,4 +364,46 @@ export const engineStore = createPartialStore<EngineStoreTypes>({
});
},
},

SET_ENGINE_SUPPORTED_DEVICES: {
mutation(state, { engineId, supportedDevices }) {
state.engineSupportedDevices = {
...state.engineSupportedDevices,
[engineId]: supportedDevices,
};
},
},

FETCH_AND_SET_ENGINE_SUPPORTED_DEVICES: {
async action({ dispatch, commit }, { engineId }) {
const supportedDevices = await dispatch("INSTANTIATE_ENGINE_CONNECTOR", {
engineId,
}).then(
async (instance) =>
await instance.invoke("supportedDevicesSupportedDevicesGet")({})
);

commit("SET_ENGINE_SUPPORTED_DEVICES", {
engineId,
supportedDevices: supportedDevices,
});
},
},

ENGINE_CAN_USE_GPU: {
getter: (state) => (engineId) => {
const supportedDevices = state.engineSupportedDevices[engineId];

return supportedDevices?.cuda || supportedDevices?.dml;
},
},

// TODO:エンジン毎の設定が可能になれば消す
ALL_ENGINE_CAN_USE_GPU: {
getter: (state, getters) => {
return state.engineIds.every((engineId) =>
getters.ENGINE_CAN_USE_GPU(engineId)
);
},
},
});
18 changes: 18 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AccentPhrase,
AudioQuery,
EngineManifest,
SupportedDevicesInfo,
UserDictWord,
} from "@/openapi";
import { createCommandMutationTree, PayloadRecipeTree } from "./command";
Expand Down Expand Up @@ -691,6 +692,7 @@ export type CommandStoreTypes = {

export type EngineStoreState = {
engineStates: Record<string, EngineState>;
engineSupportedDevices: Record<string, SupportedDevicesInfo>;
};

export type EngineStoreTypes = {
Expand Down Expand Up @@ -787,6 +789,22 @@ export type EngineStoreTypes = {
FETCH_AND_SET_ENGINE_MANIFEST: {
action(payload: { engineId: string }): void;
};

SET_ENGINE_SUPPORTED_DEVICES: {
mutation: { engineId: string; supportedDevices: SupportedDevicesInfo };
};

FETCH_AND_SET_ENGINE_SUPPORTED_DEVICES: {
action(payload: { engineId: string }): void;
};

ENGINE_CAN_USE_GPU: {
getter: (engineId: string) => boolean;
};

ALL_ENGINE_CAN_USE_GPU: {
getter: boolean;
};
};

/*
Expand Down
1 change: 1 addition & 0 deletions tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe("store/vuex.js test", () => {
engineStates: {
"88022f86-c823-436e-85a3-500c629749c4": "STARTING",
},
engineSupportedDevices: {},
characterInfos: {},
defaultStyleIds: [],
userCharacterOrder: [],
Expand Down