|
|
@ -29,8 +29,7 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, |
|
|
system.RegisterHostThread(); |
|
|
system.RegisterHostThread(); |
|
|
|
|
|
|
|
|
// Wait for first GPU command before acquiring the window context
|
|
|
// Wait for first GPU command before acquiring the window context
|
|
|
while (state.queue.Empty()) |
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
state.queue.Wait(); |
|
|
|
|
|
|
|
|
// If emulation was stopped during disk shader loading, abort before trying to acquire context
|
|
|
// If emulation was stopped during disk shader loading, abort before trying to acquire context
|
|
|
if (!state.is_running) { |
|
|
if (!state.is_running) { |
|
|
@ -57,11 +56,17 @@ static void RunThread(Core::System& system, VideoCore::RendererBase& renderer, |
|
|
} else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) { |
|
|
} else if (const auto* invalidate = std::get_if<InvalidateRegionCommand>(&next.data)) { |
|
|
rasterizer->OnCPUWrite(invalidate->addr, invalidate->size); |
|
|
rasterizer->OnCPUWrite(invalidate->addr, invalidate->size); |
|
|
} else if (std::holds_alternative<EndProcessingCommand>(next.data)) { |
|
|
} else if (std::holds_alternative<EndProcessingCommand>(next.data)) { |
|
|
return; |
|
|
|
|
|
|
|
|
ASSERT(state.is_running == false); |
|
|
} else { |
|
|
} else { |
|
|
UNREACHABLE(); |
|
|
UNREACHABLE(); |
|
|
} |
|
|
} |
|
|
state.signaled_fence.store(next.fence); |
|
|
state.signaled_fence.store(next.fence); |
|
|
|
|
|
if (next.block) { |
|
|
|
|
|
// We have to lock the write_lock to ensure that the condition_variable wait not get a
|
|
|
|
|
|
// race between the check and the lock itself.
|
|
|
|
|
|
std::lock_guard lk(state.write_lock); |
|
|
|
|
|
state.cv.notify_all(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -69,13 +74,7 @@ ThreadManager::ThreadManager(Core::System& system_, bool is_async_) |
|
|
: system{system_}, is_async{is_async_} {} |
|
|
: system{system_}, is_async{is_async_} {} |
|
|
|
|
|
|
|
|
ThreadManager::~ThreadManager() { |
|
|
ThreadManager::~ThreadManager() { |
|
|
if (!thread.joinable()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Notify GPU thread that a shutdown is pending
|
|
|
|
|
|
PushCommand(EndProcessingCommand()); |
|
|
|
|
|
thread.join(); |
|
|
|
|
|
|
|
|
ShutDown(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ThreadManager::StartThread(VideoCore::RendererBase& renderer, |
|
|
void ThreadManager::StartThread(VideoCore::RendererBase& renderer, |
|
|
@ -112,9 +111,8 @@ void ThreadManager::FlushRegion(VAddr addr, u64 size) { |
|
|
case Settings::GPUAccuracy::Extreme: { |
|
|
case Settings::GPUAccuracy::Extreme: { |
|
|
auto& gpu = system.GPU(); |
|
|
auto& gpu = system.GPU(); |
|
|
u64 fence = gpu.RequestFlush(addr, size); |
|
|
u64 fence = gpu.RequestFlush(addr, size); |
|
|
PushCommand(GPUTickCommand()); |
|
|
|
|
|
while (fence > gpu.CurrentFlushRequestFence()) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
PushCommand(GPUTickCommand(), true); |
|
|
|
|
|
ASSERT(fence <= gpu.CurrentFlushRequestFence()); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
@ -131,23 +129,45 @@ void ThreadManager::FlushAndInvalidateRegion(VAddr addr, u64 size) { |
|
|
rasterizer->OnCPUWrite(addr, size); |
|
|
rasterizer->OnCPUWrite(addr, size); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ThreadManager::WaitIdle() const { |
|
|
|
|
|
while (state.last_fence > state.signaled_fence.load(std::memory_order_relaxed) && |
|
|
|
|
|
system.IsPoweredOn()) { |
|
|
|
|
|
|
|
|
void ThreadManager::ShutDown() { |
|
|
|
|
|
if (!state.is_running) { |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
std::lock_guard lk(state.write_lock); |
|
|
|
|
|
state.is_running = false; |
|
|
|
|
|
state.cv.notify_all(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!thread.joinable()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Notify GPU thread that a shutdown is pending
|
|
|
|
|
|
PushCommand(EndProcessingCommand()); |
|
|
|
|
|
thread.join(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ThreadManager::OnCommandListEnd() { |
|
|
void ThreadManager::OnCommandListEnd() { |
|
|
PushCommand(OnCommandListEndCommand()); |
|
|
PushCommand(OnCommandListEndCommand()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
u64 ThreadManager::PushCommand(CommandData&& command_data) { |
|
|
|
|
|
const u64 fence{++state.last_fence}; |
|
|
|
|
|
state.queue.Push(CommandDataContainer(std::move(command_data), fence)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
u64 ThreadManager::PushCommand(CommandData&& command_data, bool block) { |
|
|
if (!is_async) { |
|
|
if (!is_async) { |
|
|
// In synchronous GPU mode, block the caller until the command has executed
|
|
|
// In synchronous GPU mode, block the caller until the command has executed
|
|
|
WaitIdle(); |
|
|
|
|
|
|
|
|
block = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::unique_lock lk(state.write_lock); |
|
|
|
|
|
const u64 fence{++state.last_fence}; |
|
|
|
|
|
state.queue.Push(CommandDataContainer(std::move(command_data), fence, block)); |
|
|
|
|
|
|
|
|
|
|
|
if (block) { |
|
|
|
|
|
state.cv.wait(lk, [this, fence] { |
|
|
|
|
|
return fence <= state.signaled_fence.load(std::memory_order_relaxed) || |
|
|
|
|
|
!state.is_running; |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return fence; |
|
|
return fence; |
|
|
|