buffer_cache: Fix race condition

This commit is contained in:
IndecisiveTurtle 2025-06-24 01:59:21 +03:00
parent 1af9e17176
commit 0edfa4643f
4 changed files with 9 additions and 7 deletions

View File

@ -17,6 +17,8 @@
#include "video_core/renderer_vulkan/vk_rasterizer.h"
#include "video_core/renderer_vulkan/vk_scheduler.h"
std::thread::id gpu_id;
namespace AmdGpu {
static const char* dcb_task_name{"DCB_TASK"};
@ -89,7 +91,7 @@ void Liverpool::ProcessCommands() {
void Liverpool::Process(std::stop_token stoken) {
Common::SetCurrentThreadName("shadPS4:GpuCommandProcessor");
gpu_id = std::this_thread::get_id();
while (!stoken.stop_requested()) {
{
std::unique_lock lk{submit_mutex};

View File

@ -288,13 +288,13 @@ bool BufferCache::CommitPendingDownloads(bool wait_done) {
}
}
};
const u64 wait_tick = scheduler.CurrentTick();
scheduler.Flush();
{
std::scoped_lock lk{queue_mutex};
async_downloads.emplace(std::move(writeback_host), scheduler.CurrentTick(),
current_download_tick);
async_downloads.emplace(std::move(writeback_host), wait_tick, current_download_tick);
}
queue_cv.notify_one();
scheduler.Flush();
if (wait_done) {
WaitForTargetTick(current_download_tick);
}

View File

@ -62,9 +62,6 @@ void Rasterizer::CpSync() {
}
bool Rasterizer::CommitPendingDownloads(bool wait_done) {
SCOPE_EXIT {
scheduler.PopPendingOperations();
};
return buffer_cache.CommitPendingDownloads(wait_done);
}

View File

@ -8,6 +8,8 @@
#include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_scheduler.h"
extern std::thread::id gpu_id;
namespace Vulkan {
std::mutex Scheduler::submit_mutex;
@ -68,6 +70,7 @@ void Scheduler::EndRendering() {
void Scheduler::PopPendingOperations() {
master_semaphore.Refresh();
while (!pending_ops.empty() && master_semaphore.IsFree(pending_ops.front().gpu_tick)) {
ASSERT(gpu_id == std::this_thread::get_id());
ASSERT(op_scope == 0);
++op_scope;
pending_ops.front().callback();