Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/video_core/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct GPU::Impl {
std::unique_lock lck{sync_request_mutex};
const u64 fence = ++last_sync_fence;
sync_requests.emplace_back(std::forward<Func>(action));
pending_sync_requests.fetch_add(1, std::memory_order_release);
return fence;
}

Expand All @@ -165,10 +166,16 @@ struct GPU::Impl {

/// Tick pending requests within the GPU.
void TickWork() {
// Fast path for the overwhelmingly common empty queue: do not lock per draw.
// A new request racing this check is processed on the next tick, as before.
if (pending_sync_requests.load(std::memory_order_acquire) == 0) {
return;
}
std::unique_lock lck{sync_request_mutex};
while (!sync_requests.empty()) {
auto request = std::move(sync_requests.front());
sync_requests.pop_front();
pending_sync_requests.fetch_sub(1, std::memory_order_relaxed);
sync_request_mutex.unlock();
request();
current_sync_fence.fetch_add(1, std::memory_order_release);
Expand Down Expand Up @@ -393,6 +400,7 @@ struct GPU::Impl {
std::condition_variable sync_cv;

std::list<std::function<void()>> sync_requests;
std::atomic<u32> pending_sync_requests{};
std::atomic<u64> current_sync_fence{};
u64 last_sync_fence{};

Expand Down
Loading