mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-15 00:43:52 +00:00
fix(rendering): wait all frame fences before freeing shared descriptor sets
deferAfterFrameFence only waits for one frame slot's fence, but shared resources (material descriptor sets, vertex/index buffers) are bound by both in-flight frames' command buffers. On AMD RADV this caused vkFreeDescriptorSets errors and eventual SIGSEGV. Add deferAfterAllFrameFences: queues to every frame slot with a shared counter so cleanup runs exactly once, after the last slot is fenced. Use it for WMO, terrain, water, and character model shared resources. Per-frame bone sets keep using deferAfterFrameFence (already correct). Also fix character renderer vertex format: R8G8B8A8_UINT -> _SINT to match shader's ivec4 input (RADV validation rejects the mismatch).
This commit is contained in:
parent
def821055b
commit
3ac8c4d95f
6 changed files with 31 additions and 10 deletions
|
|
@ -194,6 +194,23 @@ void VkContext::deferAfterFrameFence(std::function<void()>&& fn) {
|
|||
deferredCleanup_[currentFrame].push_back(std::move(fn));
|
||||
}
|
||||
|
||||
void VkContext::deferAfterAllFrameFences(std::function<void()>&& fn) {
|
||||
// Shared resources (material descriptor sets, vertex/index buffers) are
|
||||
// bound by every in-flight frame's command buffer. deferAfterFrameFence
|
||||
// only waits for ONE slot's fence — the other slot may still be executing.
|
||||
// Add to every slot; a shared counter ensures the lambda runs exactly once,
|
||||
// after the LAST slot has been fenced.
|
||||
auto counter = std::make_shared<uint32_t>(MAX_FRAMES_IN_FLIGHT);
|
||||
auto sharedFn = std::make_shared<std::function<void()>>(std::move(fn));
|
||||
for (uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
||||
deferredCleanup_[i].push_back([counter, sharedFn]() {
|
||||
if (--(*counter) == 0) {
|
||||
(*sharedFn)();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void VkContext::runDeferredCleanup(uint32_t frameIndex) {
|
||||
auto& q = deferredCleanup_[frameIndex];
|
||||
if (q.empty()) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue