mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2025-10-30 07:01:10 +00:00
fix semaphore deletion
This commit is contained in:
parent
d5cfab75d7
commit
3689390c56
4 changed files with 30 additions and 8 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "core/commandbuffer.hpp"
|
||||
#include "core/commandpool.hpp"
|
||||
#include "core/descriptorpool.hpp"
|
||||
#include "core/fence.hpp"
|
||||
#include "core/image.hpp"
|
||||
#include "core/semaphore.hpp"
|
||||
#include "shaderchains/alpha.hpp"
|
||||
|
|
@ -67,6 +68,7 @@ namespace LSFG {
|
|||
std::vector<std::array<Core::Semaphore, 8>> outSemaphores;
|
||||
std::array<Core::CommandBuffer, 8> cmdBuffers1;
|
||||
std::vector<std::array<Core::CommandBuffer, 8>> cmdBuffers2;
|
||||
std::array<std::vector<std::optional<Core::Fence>>, 8> doneFences;
|
||||
uint64_t fc{0};
|
||||
|
||||
Shaderchains::Downsample downsampleChain;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "context.hpp"
|
||||
#include "core/fence.hpp"
|
||||
#include "core/semaphore.hpp"
|
||||
#include "lsfg.hpp"
|
||||
|
||||
|
|
@ -28,8 +29,10 @@ Context::Context(const Core::Device& device, uint32_t width, uint32_t height, in
|
|||
this->cmdPool = Core::CommandPool(device);
|
||||
|
||||
// prepare vectors
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
this->internalSemaphores.at(i).resize(outN.size());
|
||||
this->doneFences.at(i).resize(outN.size());
|
||||
}
|
||||
for (size_t i = 0; i < outN.size(); i++) {
|
||||
this->outSemaphores.emplace_back();
|
||||
this->cmdBuffers2.emplace_back();
|
||||
|
|
@ -114,6 +117,14 @@ Context::Context(const Core::Device& device, uint32_t width, uint32_t height, in
|
|||
|
||||
void Context::present(const Core::Device& device, int inSem,
|
||||
const std::vector<int>& outSem) {
|
||||
auto& doneFences = this->doneFences.at(this->fc % 8);
|
||||
for (auto& fenceOptional : doneFences) {
|
||||
if (!fenceOptional.has_value())
|
||||
continue;
|
||||
if (!fenceOptional->wait(device, UINT64_MAX))
|
||||
throw vulkan_error(VK_ERROR_DEVICE_LOST, "Fence wait timed out");
|
||||
}
|
||||
|
||||
auto& inSemaphore = this->inSemaphores.at(this->fc % 8);
|
||||
inSemaphore = Core::Semaphore(device, inSem);
|
||||
auto& internalSemaphores = this->internalSemaphores.at(this->fc % 8);
|
||||
|
|
@ -134,10 +145,11 @@ void Context::present(const Core::Device& device, int inSem,
|
|||
{ inSemaphore }, std::nullopt,
|
||||
internalSemaphores, std::nullopt);
|
||||
|
||||
|
||||
for (size_t pass = 0; pass < outSem.size(); pass++) {
|
||||
auto& outSemaphore = this->outSemaphores.at(pass).at(this->fc % 8);
|
||||
outSemaphore = Core::Semaphore(device, outSem.at(pass));
|
||||
auto& outFenceOptional = this->doneFences.at(fc % 8).at(pass);
|
||||
outFenceOptional.emplace(Core::Fence(device));
|
||||
|
||||
auto& cmdBuffer2 = this->cmdBuffers2.at(pass).at(this->fc % 8);
|
||||
cmdBuffer2 = Core::CommandBuffer(device, this->cmdPool);
|
||||
|
|
@ -158,7 +170,7 @@ void Context::present(const Core::Device& device, int inSem,
|
|||
|
||||
cmdBuffer2.end();
|
||||
|
||||
cmdBuffer2.submit(device.getComputeQueue(), std::nullopt,
|
||||
cmdBuffer2.submit(device.getComputeQueue(), outFenceOptional,
|
||||
{ internalSemaphores.at(pass) }, std::nullopt,
|
||||
{ outSemaphore }, std::nullopt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,15 +58,17 @@ void LSFG::deleteContext(int32_t id) {
|
|||
if (it == contexts.end())
|
||||
throw LSFG::vulkan_error(VK_ERROR_DEVICE_LOST, "No such context");
|
||||
|
||||
vkDeviceWaitIdle(device->handle());
|
||||
contexts.erase(it);
|
||||
}
|
||||
|
||||
void LSFG::finalize() {
|
||||
if (!instance.has_value() && !device.has_value())
|
||||
if (!instance.has_value() || !device.has_value())
|
||||
return;
|
||||
|
||||
Globals::uninitializeGlobals();
|
||||
|
||||
instance.reset();
|
||||
vkDeviceWaitIdle(device->handle());
|
||||
device.reset();
|
||||
instance.reset();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ VkResult LsContext::present(const Hooks::DeviceInfo& info, const void* pNext, Vk
|
|||
// 1. copy swapchain image to frame_0/frame_1
|
||||
int preCopySemaphoreFd{};
|
||||
pass.preCopySemaphores.at(0) = Mini::Semaphore(info.device, &preCopySemaphoreFd);
|
||||
// pass.preCopySemaphores.at(1) = Mini::Semaphore(info.device);
|
||||
pass.preCopySemaphores.at(1) = Mini::Semaphore(info.device);
|
||||
pass.preCopyBuf = Mini::CommandBuffer(info.device, this->cmdPool);
|
||||
pass.preCopyBuf.begin();
|
||||
|
||||
|
|
@ -75,9 +75,15 @@ VkResult LsContext::present(const Hooks::DeviceInfo& info, const void* pNext, Vk
|
|||
true, false);
|
||||
|
||||
pass.preCopyBuf.end();
|
||||
|
||||
std::vector<VkSemaphore> gameRenderSemaphores2 = gameRenderSemaphores;
|
||||
if (this->frameIdx > 0)
|
||||
gameRenderSemaphores2.emplace_back(this->passInfos.at((this->frameIdx - 1) % 8)
|
||||
.preCopySemaphores.at(1).handle());
|
||||
pass.preCopyBuf.submit(info.queue.second,
|
||||
gameRenderSemaphores,
|
||||
{ pass.preCopySemaphores.at(0).handle() });
|
||||
gameRenderSemaphores2,
|
||||
{ pass.preCopySemaphores.at(0).handle(),
|
||||
pass.preCopySemaphores.at(1).handle() });
|
||||
|
||||
// 2. render intermediary frames
|
||||
std::vector<int> renderSemaphoreFds(info.frameGen);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue