d3d12: Fix interframe sync

This commit is contained in:
vlj 2015-06-03 20:30:20 +02:00 committed by Vincent Lejeune
parent ac352cd083
commit a5fb8c95f4
2 changed files with 12 additions and 10 deletions

View file

@ -107,7 +107,7 @@ void D3D12GSRender::ResourceStorage::Reset()
void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device) void D3D12GSRender::ResourceStorage::Init(ID3D12Device *device)
{ {
m_frameFinished = 0; m_frameFinishedHandle = 0;
// Create a global command allocator // Create a global command allocator
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator)); device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_commandAllocator));
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_textureUploadCommandAllocator)); device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&m_textureUploadCommandAllocator));
@ -928,20 +928,21 @@ void D3D12GSRender::Flip()
check(m_swapChain->Present(Ini.GSVSyncEnable.GetValue() ? 1 : 0, 0)); check(m_swapChain->Present(Ini.GSVSyncEnable.GetValue() ? 1 : 0, 0));
// Add an event signaling queue completion // Add an event signaling queue completion
Microsoft::WRL::ComPtr<ID3D12Fence> fence;
m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)); m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&getNonCurrentResourceStorage().m_frameFinishedFence));
getNonCurrentResourceStorage().m_frameFinished = CreateEvent(0, 0, 0, 0); getNonCurrentResourceStorage().m_frameFinishedHandle = CreateEvent(0, 0, 0, 0);
fence->SetEventOnCompletion(1, getNonCurrentResourceStorage().m_frameFinished); getNonCurrentResourceStorage().m_frameFinishedFence->SetEventOnCompletion(1, getNonCurrentResourceStorage().m_frameFinishedHandle);
m_commandQueueGraphic->Signal(fence.Get(), 1); m_commandQueueGraphic->Signal(getNonCurrentResourceStorage().m_frameFinishedFence, 1);
// Flush // Flush
m_texturesCache.clear(); m_texturesCache.clear();
m_texturesRTTs.clear(); m_texturesRTTs.clear();
if (getCurrentResourceStorage().m_frameFinished) if (getCurrentResourceStorage().m_frameFinishedHandle)
{ {
WaitForSingleObject(getCurrentResourceStorage().m_frameFinished, INFINITE); WaitForSingleObject(getCurrentResourceStorage().m_frameFinishedHandle, INFINITE);
CloseHandle(getCurrentResourceStorage().m_frameFinished); CloseHandle(getCurrentResourceStorage().m_frameFinishedHandle);
getCurrentResourceStorage().m_frameFinishedFence->Release();
for (auto tmp : getCurrentResourceStorage().m_inUseConstantsBuffers) for (auto tmp : getCurrentResourceStorage().m_inUseConstantsBuffers)
m_constantsData.m_getPos = std::get<0>(tmp); m_constantsData.m_getPos = std::get<0>(tmp);

View file

@ -80,7 +80,8 @@ private:
struct ResourceStorage struct ResourceStorage
{ {
HANDLE m_frameFinished; ID3D12Fence* m_frameFinishedFence;
HANDLE m_frameFinishedHandle;
ID3D12CommandAllocator *m_commandAllocator; ID3D12CommandAllocator *m_commandAllocator;
ID3D12CommandAllocator *m_downloadCommandAllocator; ID3D12CommandAllocator *m_downloadCommandAllocator;
std::list<ID3D12GraphicsCommandList *> m_inflightCommandList; std::list<ID3D12GraphicsCommandList *> m_inflightCommandList;