From adadf362a395149fdae54f7784302e1e095165f8 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 23 Jul 2018 16:08:01 +0200 Subject: [PATCH] [d3d11] Optimize WaitForResource behaviour when resource is already idle We don't have to flush everything in this case, just flushing the current CS chunk is enough to determine if the resource is in use by the GPU. --- src/d3d11/d3d11_context_imm.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 711a0f84..b1499f47 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -521,16 +521,24 @@ namespace dxvk { // Wait for the any pending D3D11 command to be executed // on the CS thread so that we can determine whether the // resource is currently in use or not. - Flush(); + FlushCsChunk(); SynchronizeCsThread(); if (Resource->isInUse()) { - if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) + if (MapFlags & D3D11_MAP_FLAG_DO_NOT_WAIT) { + // We don't have to wait, but misbehaving games may + // still try to spin on `Map` until the resource is + // idle, so we should flush pending commands + FlushImplicit(); return false; - - // TODO implement properly in DxvkDevice - while (Resource->isInUse()) - dxvk::this_thread::yield(); + } else { + // Make sure pending commands using the resource get + // executed on the the GPU if we have to wait for it + Flush(); + + while (Resource->isInUse()) + dxvk::this_thread::yield(); + } } return true;