From 4f6a67af36b170566e0ca68d19bdcf3f2ee48d0c Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Wed, 13 Jul 2022 21:40:41 +0530 Subject: [PATCH] Fix `Texture` Trap Data Race The trap callbacks did not wait on the `Texture` to complete synchronization to the guest, this resulted in races where the contents written to the texture would be overwritten by the synced content. This commit fixes that by waiting on the fences at the end of the trap callback. --- app/src/main/cpp/skyline/gpu/texture/texture.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/cpp/skyline/gpu/texture/texture.cpp b/app/src/main/cpp/skyline/gpu/texture/texture.cpp index f144c092..4480f95f 100644 --- a/app/src/main/cpp/skyline/gpu/texture/texture.cpp +++ b/app/src/main/cpp/skyline/gpu/texture/texture.cpp @@ -150,6 +150,7 @@ namespace skyline::gpu { if (!lock) return false; SynchronizeGuest(true); // We can skip trapping since the caller will do it + WaitOnFence(); return true; }, [this] { DirtyState expectedState{DirtyState::Clean}; @@ -161,6 +162,7 @@ namespace skyline::gpu { return false; SynchronizeGuest(true); dirtyState = DirtyState::CpuDirty; // We need to assume the texture is dirty since we don't know what the guest is writing + WaitOnFence(); return true; }); }