mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-04-27 12:51:52 +00:00
workaround: leak Vulkan instance & device
Some checks are pending
(CI) lsfg-vk / build (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (24.08) (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (25.08) (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-ui (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (23.08) (push) Waiting to run
Some checks are pending
(CI) lsfg-vk / build (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (24.08) (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (25.08) (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-ui (push) Waiting to run
(CI/Flatpak) lsfg-vk / flatpak-extensions (23.08) (push) Waiting to run
comments document why this is needed. closes #59
This commit is contained in:
parent
ceff118e8a
commit
94d243bc2d
4 changed files with 39 additions and 2 deletions
|
|
@ -129,4 +129,11 @@ namespace lsfgvk::backend {
|
||||||
std::vector<std::unique_ptr<Context>> m_contexts;
|
std::vector<std::unique_ptr<Context>> m_contexts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Make all lsfg-vk instances leaking.
|
||||||
|
/// This is to workaround a bug in the Vulkan loader, which
|
||||||
|
/// makes it impossible to destroy Vulkan instances and devices.
|
||||||
|
///
|
||||||
|
void makeLeaking();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
@ -77,6 +78,12 @@ namespace lsfgvk::backend {
|
||||||
/// @return the RenderDoc API
|
/// @return the RenderDoc API
|
||||||
[[nodiscard]] const auto& getRenderDocAPI() const { return this->renderdoc; }
|
[[nodiscard]] const auto& getRenderDocAPI() const { return this->renderdoc; }
|
||||||
#endif
|
#endif
|
||||||
|
// Movable, non-copyable, custom destructor
|
||||||
|
InstanceImpl(const InstanceImpl&) = delete;
|
||||||
|
InstanceImpl& operator=(const InstanceImpl&) = delete;
|
||||||
|
InstanceImpl(InstanceImpl&&) = default;
|
||||||
|
InstanceImpl& operator=(InstanceImpl&&) = default;
|
||||||
|
~InstanceImpl();
|
||||||
private:
|
private:
|
||||||
vk::Vulkan vk;
|
vk::Vulkan vk;
|
||||||
ShaderRegistry shaders;
|
ShaderRegistry shaders;
|
||||||
|
|
@ -634,3 +641,24 @@ void Instance::closeContext(const Context& context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance::~Instance() = default;
|
Instance::~Instance() = default;
|
||||||
|
|
||||||
|
// leaking shenanigans
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool leaking{false}; // NOLINT
|
||||||
|
}
|
||||||
|
|
||||||
|
InstanceImpl::~InstanceImpl() {
|
||||||
|
if (!leaking) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
new vk::Vulkan(std::move(this->vk));
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "lsfg-vk: failed to leak Vulkan instance\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void backend::makeLeaking() {
|
||||||
|
leaking = true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -232,8 +232,8 @@ namespace {
|
||||||
// destroy layer info
|
// destroy layer info
|
||||||
// NOTE: there's no real way of unloading the layer without a deconstructor.
|
// NOTE: there's no real way of unloading the layer without a deconstructor.
|
||||||
// multiple instances just aren't common enough to worry about it.
|
// multiple instances just aren't common enough to worry about it.
|
||||||
// NOTE2: it doesn't really matter anyways, because the myvkDestroyDevice code
|
// NOTE2: this IS a memory leak, because the VkInstance inside of root->backend
|
||||||
// freezes the entire thing anyways.
|
// cannot be destroyed, due to a Vulkan-Loader limitation/bug.
|
||||||
delete layer_info;
|
delete layer_info;
|
||||||
layer_info = nullptr;
|
layer_info = nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@ Swapchain::Swapchain(const vk::Vulkan& vk, backend::Instance& backend,
|
||||||
backend->closeContext(ctx);
|
backend->closeContext(ctx);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
backend::makeLeaking(); // don't worry about it :3
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
throw ls::error("failed to create swapchain context", e);
|
throw ls::error("failed to create swapchain context", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue