diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.cpp index 8b417990..d639f40a 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.cpp @@ -83,4 +83,4 @@ namespace MobileGL::MG_Backend::DirectVulkan { return entry.stages; } -} // namespace MobileGL::MG_Backend::DirectVulkan \ No newline at end of file +} // namespace MobileGL::MG_Backend::DirectVulkan diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.h index b39fe2c3..48c52a14 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/ProgramFactory.h @@ -29,12 +29,45 @@ namespace MobileGL::MG_Backend::DirectVulkan { Vector stages; Vector 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(); } };