Repository navigation
Runtime: O(1) LayoutTracker rollback and unlock tracker_mutex before vkQueuePresentKHR in VulkanPresenter - #1744
Conversation
…vkQueuePresentKHR in VulkanPresenter
Flyander
left a comment
There was a problem hiding this comment.
Revu le head db9b090 : la sauvegarde/restauration ciblée couvre l’unique transition tracker du subresource 0, et le verrou est relâché après vkQueueSubmit tout en préservant l’ordre de soumission. Cela retire la copie de la map complète à chaque frame et évite de tenir tracker_mutex_ pendant vkQueuePresentKHR. Le test couvre l’échec submit, l’état d’une autre ressource et la lecture concurrente pendant present. Petite réserve non bloquante : la vérification concurrente dépend d’une attente fixe de 30 ms; une condition_variable avec un délai borné limiterait les faux échecs sur runner chargé. Checks CI encore en attente.
Vonsek
left a comment
There was a problem hiding this comment.
The tracker commit/rollback ordering looks consistent with the submit lock at db9b0904. There are two failure modes in the new test's reader:
- A 30 ms sleep can expire before the reader is scheduled on a loaded runner, giving a false regression. Have the worker signal that it has started, then wait for completion with a bounded timeout inside the present hook.
- If the present hook starts the reader and the real
vkQueuePresentKHRreturns an error,EXPECT(presenter.present(...) == VK_SUCCESS)returns before the join. The thread destructor then terminates the test. Capture the present result, join the reader, then check the result.
Reviewed by source. AI-assisted.
…ble and join before EXPECT
|
Thanks @Flyander and @Vonsek for catching both points! Updated in
Re-verified on Windows 11 (MinGW-w64
AI-assisted. |
|
Tested
AI-assisted (Claude Code). |
|
Tested 6933e0c on Windows 11 (26200), MSVC 19.4x (VS 2022 Build Tools), Ninja RelWithDebInfo: pass on both GPUs of a two-GPU PC.
No game files. AI-assisted check (Claude Code), Vonsek3. |
Claimed on #1548 (comment) (follow-up to merged #1619 addressing @dracbat's review note).
Changes (
runtime/src/vulkan_present.h)LayoutTrackeron everyPresent():VulkanPresenter::record()only touches subresource 0 ({VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}) ofsourceviadetail::initialize().context_.tracker_(std::unordered_map<ResourceId, Entry>+ per-image layout vectors) undertracker_mutex_on every frame,submit()now recordscontext_.tracker_.layout(source, 0)(when tracked), records directly intocontext_.tracker_, and restores subresource 0 in O(1) ifvkResetFencesorvkQueueSubmitfails.#include <optional>and the extraLayoutTracker¶meter onrecord().tracker_mutex_immediately aftervkQueueSubmit(beforevkQueuePresentKHR):tracker_lock.unlock()now happen right aftervkQueueSubmitreturns inside thesubmit_mutex()block, preserving strict submission order without blocking other threads'emit()/layout()calls whilevkQueuePresentKHRruns.Tests (
runtime/test/vk_presenter_sync_test.cpp)1000..1511) during the failed-submit rollback check and verifiessourcerolls back toUNDEFINEDwhile other tracked layouts stay intact.vkQueuePresentKHRand spawns a reader thread callingcontext.layout(1, 0)insidevkQueuePresentKHR, verifyingtracker_mutex_is already released before presentation and sees the committedVK_IMAGE_LAYOUT_GENERAL.Verification
main89b047cd): Failed on Intel UHD atline 237: unblocked_during_present(tracker_mutex_remained locked duringvkQueuePresentKHR).-std=c++20 -O2 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers, 0 warnings in touched files):0x8086:0xa7a8, driver101.7092, Vulkan1.4.323):vk_presenter_sync_test3/3 passed.0x10de:0x2d98, driver621.24, Vulkan1.4.357):vk_presenter_sync_test3/3 passed.AI-assisted: written and verified with an AI coding assistant; all code, negative control, and multi-GPU runs reviewed and executed locally. No game data.