diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 1fb74c777..b16152c04 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -112,7 +112,7 @@ namespace dxvk { D3D9DeviceEx::~D3D9DeviceEx() { Flush(); - SynchronizeCsThread(); + SynchronizeCsThread(DxvkCsThread::SynchronizeAll); delete m_initializer; delete m_converter; @@ -328,7 +328,7 @@ namespace dxvk { return hr; Flush(); - SynchronizeCsThread(); + SynchronizeCsThread(DxvkCsThread::SynchronizeAll); return D3D_OK; } @@ -4064,6 +4064,7 @@ namespace dxvk { bool D3D9DeviceEx::WaitForResource( const Rc& Resource, + uint64_t SequenceNumber, DWORD MapFlags) { // Wait for the any pending D3D9 command to be executed // on the CS thread so that we can determine whether the @@ -4075,7 +4076,7 @@ namespace dxvk { : DxvkAccess::Read; if (!Resource->isInUse(access)) - SynchronizeCsThread(); + SynchronizeCsThread(SequenceNumber); if (Resource->isInUse(access)) { if (MapFlags & D3DLOCK_DONOTWAIT) { @@ -4089,7 +4090,7 @@ namespace dxvk { // Make sure pending commands using the resource get // executed on the the GPU if we have to wait for it Flush(); - SynchronizeCsThread(); + SynchronizeCsThread(SequenceNumber); m_dxvkDevice->waitForResource(Resource, access); } @@ -4242,10 +4243,10 @@ namespace dxvk { std::memset(physSlice.mapPtr, 0, physSlice.length); } else if (!skipWait) { - if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappedBuffer, D3DLOCK_DONOTWAIT)) + if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), D3DLOCK_DONOTWAIT)) pResource->EnableStagingBufferUploads(Subresource); - if (!WaitForResource(mappedBuffer, Flags)) + if (!WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), Flags)) return D3DERR_WASSTILLDRAWING; } } @@ -4324,7 +4325,7 @@ namespace dxvk { }); } - if (!WaitForResource(mappedBuffer, Flags)) + if (!WaitForResource(mappedBuffer, DxvkCsThread::SynchronizeAll, Flags)) return D3DERR_WASSTILLDRAWING; } else { // If we are a new alloc, and we weren't written by the GPU @@ -4536,7 +4537,7 @@ namespace dxvk { pitch, std::min(convertFormat.PlaneCount, 2u) * pitch * texLevelExtentBlockCount.height); Flush(); - SynchronizeCsThread(); + SynchronizeCsThread(DxvkCsThread::SynchronizeAll); m_converter->ConvertFormat( convertFormat, @@ -4653,10 +4654,10 @@ namespace dxvk { const bool directMapping = pResource->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_DIRECT; const bool skipWait = (!wasWrittenByGPU && (usesStagingBuffer || readOnly || (noOverlap && !directMapping))) || noOverwrite; if (!skipWait) { - if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappingBuffer, D3DLOCK_DONOTWAIT)) + if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappingBuffer, pResource->GetMappingBufferSequenceNumber(), D3DLOCK_DONOTWAIT)) pResource->EnableStagingBufferUploads(); - if (!WaitForResource(mappingBuffer, Flags)) + if (!WaitForResource(mappingBuffer, pResource->GetMappingBufferSequenceNumber(), Flags)) return D3DERR_WASSTILLDRAWING; pResource->SetWrittenByGPU(false); @@ -4772,14 +4773,14 @@ namespace dxvk { } - void D3D9DeviceEx::SynchronizeCsThread() { + void D3D9DeviceEx::SynchronizeCsThread(uint64_t SequenceNumber) { D3D9DeviceLock lock = LockDevice(); // Dispatch current chunk so that all commands // recorded prior to this function will be run FlushCsChunk(); - m_csThread.synchronize(DxvkCsThread::SynchronizeAll); + m_csThread.synchronize(SequenceNumber); } @@ -7348,7 +7349,7 @@ namespace dxvk { return hr; Flush(); - SynchronizeCsThread(); + SynchronizeCsThread(DxvkCsThread::SynchronizeAll); return D3D_OK; } diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index d12c59dc2..3b38825ae 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -662,6 +662,7 @@ namespace dxvk { bool WaitForResource( const Rc& Resource, + uint64_t SequenceNumber, DWORD MapFlags); /** @@ -731,7 +732,7 @@ namespace dxvk { void CreateConstantBuffers(); - void SynchronizeCsThread(); + void SynchronizeCsThread(uint64_t SequenceNumber); void Flush();