diff --git a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp index c259c634..01b3f7ec 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.cpp @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2021 Skyline Team and Contributors (https://github.com/skyline-emu/) +#include +#include #include #include #include @@ -555,7 +557,7 @@ namespace skyline::gpu::interconnect { } } - void CommandExecutor::Submit(std::function &&callback) { + void CommandExecutor::Submit(std::function &&callback, bool wait) { for (const auto &flushCallback : flushCallbacks) flushCallback(); @@ -581,6 +583,21 @@ namespace skyline::gpu::interconnect { callback(); ResetInternal(); + + if (wait) { + std::condition_variable cv; + std::mutex mutex; + bool gpuDone{}; + + waiterThread.Queue(nullptr, [&cv, &mutex, &gpuDone] { + std::scoped_lock lock{mutex}; + gpuDone = true; + cv.notify_one(); + }); + + std::unique_lock lock{mutex}; + cv.wait(lock, [&gpuDone] { return gpuDone; }); + } } void CommandExecutor::LockPreserve() { diff --git a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h index 4fd4d0bd..d1225b76 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/command_executor.h @@ -301,8 +301,9 @@ namespace skyline::gpu::interconnect { /** * @brief Execute all the nodes and submit the resulting command buffer to the GPU * @param callback A function to call upon GPU completion of the submission + * @param wait Whether to wait synchronously for GPU completion of the submit */ - void Submit(std::function &&callback = {}); + void Submit(std::function &&callback = {}, bool wait = false); /** * @brief Locks all preserve attached buffers/textures diff --git a/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp b/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp index dfa48b73..49fe7b94 100644 --- a/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp +++ b/app/src/main/cpp/skyline/soc/gm20b/gpfifo.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#include #include +#include #include #include #include @@ -156,7 +158,7 @@ namespace skyline::soc::gm20b { void ChannelGpfifo::Process(GpEntry gpEntry) { // Submit if required by the GpEntry, this is needed as some games dynamically generate pushbuffer contents if (gpEntry.sync == GpEntry::Sync::Wait) - channelCtx.executor.Submit(); + channelCtx.executor.Submit({}, *state.settings->useDirectMemoryImport); if (!gpEntry.size) { // This is a GPFIFO control entry, all control entries have a zero length and contain no pushbuffers