[Fix] (MG_Backend/DirectVulkan): add move ctor for BackendProgramObject

This commit is contained in:
2026-02-17 21:57:29 +08:00
parent b69b6b2987
commit 12d514229c
2 changed files with 36 additions and 3 deletions
@@ -83,4 +83,4 @@ namespace MobileGL::MG_Backend::DirectVulkan {
return entry.stages;
}
} // namespace MobileGL::MG_Backend::DirectVulkan
} // namespace MobileGL::MG_Backend::DirectVulkan
@@ -29,12 +29,45 @@ namespace MobileGL::MG_Backend::DirectVulkan {
Vector<VkPipelineShaderStageCreateInfo> stages;
Vector<VkShaderModule> modules;
BackendProgramObject() = default;
BackendProgramObject(const BackendProgramObject&) = delete;
BackendProgramObject& operator=(const BackendProgramObject&) = delete;
BackendProgramObject(BackendProgramObject&& other) noexcept {
hash = other.hash;
device = other.device;
stages = std::move(other.stages);
modules = std::move(other.modules);
other.hash = 0;
other.device = VK_NULL_HANDLE;
}
BackendProgramObject& operator=(BackendProgramObject&& other) noexcept {
if (this == &other) {
return *this;
}
DestroyModules();
stages.clear();
hash = other.hash;
device = other.device;
stages = std::move(other.stages);
modules = std::move(other.modules);
other.hash = 0;
other.device = VK_NULL_HANDLE;
return *this;
}
~BackendProgramObject() {
DestroyModules();
stages.clear();
}
private:
void DestroyModules() {
for (auto module: modules) {
vkDestroyShaderModule(device, module, nullptr);
if (module != VK_NULL_HANDLE && device != VK_NULL_HANDLE) {
vkDestroyShaderModule(device, module, nullptr);
}
}
modules.clear();
stages.clear();
}
};