From 9c193e02829f63c653c3cc875479f2fc450710c9 Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 26 May 2015 18:36:05 +0200 Subject: [PATCH] d3d12: Implement semaphore --- rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp | 42 +++++++++++++++++++++++++++ rpcs3/Emu/RSX/D3D12/D3D12GSRender.h | 3 ++ 2 files changed, 45 insertions(+) diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index d812a05350..3363b60122 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -1162,4 +1162,46 @@ void D3D12GSRender::WriteDepthBuffer() fence->Release(); downloadCommandList->Release(); } + + +void D3D12GSRender::semaphorePGRAPHBackendRelease(u32 offset, u32 value) +{ + ID3D12Fence *fence; + check( + m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)) + ); + HANDLE handle = CreateEvent(0, FALSE, FALSE, 0); + fence->SetEventOnCompletion(1, handle); + m_commandQueueGraphic->Signal(fence, 1); + + std::thread valueChangerThread([=]() { + WaitForSingleObject(handle, INFINITE); + CloseHandle(handle); + fence->Release(); + vm::write32(m_label_addr + offset, value); + }); + valueChangerThread.detach(); +} + +void D3D12GSRender::semaphorePFIFOAcquire(u32 offset, u32 value) +{ + + ID3D12Fence *fence; + check( + m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)) + ); + m_commandQueueGraphic->Wait(fence, 1); + + std::thread valueChangerThread([=]() { + while (true) + { + u32 val = vm::read32(m_label_addr + offset); + if (val == value) break; + } + fence->Signal(1); + fence->Release(); + } + ); + valueChangerThread.join(); +} #endif \ No newline at end of file diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index dcd1399d63..697d3fbda4 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -119,6 +119,9 @@ public: D3D12GSRender(); virtual ~D3D12GSRender(); + virtual void semaphorePGRAPHBackendRelease(u32 offset, u32 value) override; + virtual void semaphorePFIFOAcquire(u32 offset, u32 value) override; + private: virtual void Close() override;