Added barrier to DX12 overlay.

Gears5 seems to have a problem with the overlay. While loading and in the main menu, it works fine, but if you press enter, it crashes saying the GPU is not responding. Can't debug it with CODEX, it checks for a debugger.
Works fine on sniper elite5.
merge-requests/28/head
Nemirtingas 2019-10-17 18:03:19 +02:00
parent 695954e13a
commit 547cbdbb4e
2 changed files with 35 additions and 14 deletions

View File

@ -45,10 +45,13 @@ void DX12_Hook::resetRenderState()
{
pSrvDescHeap->Release();
for (UINT i = 0; i < bufferCount; ++i)
{
pCmdAlloc[i]->Release();
pBackBuffer[i]->Release();
}
pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc;
delete[]pBackBuffer;
ImGui_ImplDX12_Shutdown();
Windows_Hook::Inst()->resetRenderState();
@ -83,6 +86,8 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
bufferCount = sc_desc.BufferCount;
mainRenderTargets.clear();
{
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
@ -111,11 +116,10 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
SIZE_T rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = pRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
pMainRenderTargets = new D3D12_CPU_DESCRIPTOR_HANDLE[bufferCount];
pCmdAlloc = new ID3D12CommandAllocator * [bufferCount];
for (int i = 0; i < bufferCount; ++i)
{
pMainRenderTargets[i] = rtvHandle;
mainRenderTargets.push_back(rtvHandle);
rtvHandle.ptr += rtvDescriptorSize;
}
}
@ -132,7 +136,6 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
pCmdAlloc[j]->Release();
}
pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc;
return;
}
@ -147,16 +150,15 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
for (UINT i = 0; i < bufferCount; ++i)
pCmdAlloc[i]->Release();
pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc;
return;
}
pBackBuffer = new ID3D12Resource * [bufferCount];
for (UINT i = 0; i < bufferCount; i++)
{
ID3D12Resource* pBackBuffer = NULL;
pSwapChain3->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
pDevice->CreateRenderTargetView(pBackBuffer, NULL, pMainRenderTargets[i]);
pSwapChain3->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer[i]));
pDevice->CreateRenderTargetView(pBackBuffer[i], NULL, mainRenderTargets[i]);
}
ImGui::CreateContext();
@ -183,13 +185,28 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
UINT bufferIndex = pSwapChain3->GetCurrentBackBufferIndex();
D3D12_RESOURCE_BARRIER barrier = {};
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Transition.pResource = pBackBuffer[bufferIndex];
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
pCmdAlloc[bufferIndex]->Reset();
pCmdList->Reset(pCmdAlloc[bufferIndex], NULL);
pCmdList->OMSetRenderTargets(1, &pMainRenderTargets[bufferIndex], FALSE, NULL);
pCmdList->ResourceBarrier(1, &barrier);
pCmdList->OMSetRenderTargets(1, &mainRenderTargets[bufferIndex], FALSE, NULL);
pCmdList->SetDescriptorHeaps(1, &pSrvDescHeap);
ImGui::Render();
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), pCmdList);
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
pCmdList->ResourceBarrier(1, &barrier);
pCmdList->Close();
pCmdQueue->ExecuteCommandLists(1, (ID3D12CommandList**)&pCmdList);
pSwapChain3->Release();
@ -218,6 +235,7 @@ void STDMETHODCALLTYPE DX12_Hook::MyExecuteCommandLists(ID3D12CommandQueue *_thi
{
DX12_Hook* me = DX12_Hook::Inst();
me->pCmdQueue = _this;
(_this->*DX12_Hook::Inst()->ExecuteCommandLists)(NumCommandLists, ppCommandLists);
}
@ -225,7 +243,6 @@ DX12_Hook::DX12_Hook():
initialized(false),
pCmdQueue(nullptr),
bufferCount(0),
pMainRenderTargets(nullptr),
pCmdAlloc(nullptr),
pSrvDescHeap(nullptr),
pCmdList(nullptr),
@ -249,10 +266,13 @@ DX12_Hook::~DX12_Hook()
{
pSrvDescHeap->Release();
for (UINT i = 0; i < bufferCount; ++i)
{
pCmdAlloc[i]->Release();
pBackBuffer[i]->Release();
}
pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc;
delete[]pBackBuffer;
ImGui_ImplDX12_InvalidateDeviceObjects();
ImGui::DestroyContext();

View File

@ -22,11 +22,12 @@ private:
ID3D12CommandQueue* pCmdQueue;
UINT bufferCount;
D3D12_CPU_DESCRIPTOR_HANDLE* pMainRenderTargets;
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> mainRenderTargets;
ID3D12CommandAllocator** pCmdAlloc;
ID3D12DescriptorHeap* pSrvDescHeap;
ID3D12GraphicsCommandList* pCmdList;
ID3D12DescriptorHeap* pRtvDescHeap;
ID3D12Resource** pBackBuffer;
// Functions
DX12_Hook();