From 35133381b60fa115d679e7a4c764a289155241e5 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 29 Jul 2022 03:16:06 +0530 Subject: [PATCH] Fix V-Sync `KEvent` construction order The V-Sync `KEvent` would be used by the presentation thread prior to construction leading to dereferencing an invalid value, this has been fixed by changing the order of construction to move the construction of the presentation thread after the V-Sync event. --- app/src/main/cpp/skyline/gpu/presentation_engine.cpp | 4 ++-- app/src/main/cpp/skyline/gpu/presentation_engine.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index 6276f242..9d967faa 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -26,9 +26,9 @@ namespace skyline::gpu { gpu{gpu}, acquireFence{gpu.vkDevice, vk::FenceCreateInfo{}}, presentationTrack{static_cast(trace::TrackIds::Presentation), perfetto::ProcessTrack::Current()}, + vsyncEvent{std::make_shared(state, true)}, choreographerThread{&PresentationEngine::ChoreographerThread, this}, - presentationThread{&PresentationEngine::PresentationThread, this}, - vsyncEvent{std::make_shared(state, true)} { + presentationThread{&PresentationEngine::PresentationThread, this} { auto desc{presentationTrack.Serialize()}; desc.set_name("Presentation"); perfetto::TrackEvent::SetTrackDescriptor(presentationTrack, desc); diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.h b/app/src/main/cpp/skyline/gpu/presentation_engine.h index 97e22eb1..03b3b5b7 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.h +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.h @@ -47,6 +47,10 @@ namespace skyline::gpu { i64 averageFrametimeDeviationNs{}; //!< The average deviation of frametimes in nanoseconds perfetto::Track presentationTrack; //!< Perfetto track used for presentation events + public: + std::shared_ptr vsyncEvent; //!< Signalled every time a frame is drawn + + private: std::thread choreographerThread; //!< A thread for signalling the V-Sync event and measure the refresh cycle duration using AChoreographer ALooper *choreographerLooper{}; i64 lastChoreographerTime{}; //!< The timestamp of the last invocation of Choreographer::doFrame @@ -97,8 +101,6 @@ namespace skyline::gpu { void UpdateSwapchain(texture::Format format, texture::Dimensions extent); public: - std::shared_ptr vsyncEvent; //!< Signalled every time a frame is drawn - PresentationEngine(const DeviceState &state, GPU &gpu); ~PresentationEngine();