1
0
Fork 0
mirror of https://gitlab.com/Mr_Goldberg/goldberg_emulator.git synced 2024-11-14 10:50:13 +01:00

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.
This commit is contained in:
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(); pSrvDescHeap->Release();
for (UINT i = 0; i < bufferCount; ++i) for (UINT i = 0; i < bufferCount; ++i)
{
pCmdAlloc[i]->Release(); pCmdAlloc[i]->Release();
pBackBuffer[i]->Release();
}
pRtvDescHeap->Release(); pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc; delete[]pCmdAlloc;
delete[]pBackBuffer;
ImGui_ImplDX12_Shutdown(); ImGui_ImplDX12_Shutdown();
Windows_Hook::Inst()->resetRenderState(); Windows_Hook::Inst()->resetRenderState();
@ -83,6 +86,8 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
bufferCount = sc_desc.BufferCount; bufferCount = sc_desc.BufferCount;
mainRenderTargets.clear();
{ {
D3D12_DESCRIPTOR_HEAP_DESC desc = {}; D3D12_DESCRIPTOR_HEAP_DESC desc = {};
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; 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); SIZE_T rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = pRtvDescHeap->GetCPUDescriptorHandleForHeapStart(); D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = pRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
pMainRenderTargets = new D3D12_CPU_DESCRIPTOR_HANDLE[bufferCount];
pCmdAlloc = new ID3D12CommandAllocator * [bufferCount]; pCmdAlloc = new ID3D12CommandAllocator * [bufferCount];
for (int i = 0; i < bufferCount; ++i) for (int i = 0; i < bufferCount; ++i)
{ {
pMainRenderTargets[i] = rtvHandle; mainRenderTargets.push_back(rtvHandle);
rtvHandle.ptr += rtvDescriptorSize; rtvHandle.ptr += rtvDescriptorSize;
} }
} }
@ -132,7 +136,6 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
pCmdAlloc[j]->Release(); pCmdAlloc[j]->Release();
} }
pRtvDescHeap->Release(); pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc; delete[]pCmdAlloc;
return; return;
} }
@ -147,16 +150,15 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
for (UINT i = 0; i < bufferCount; ++i) for (UINT i = 0; i < bufferCount; ++i)
pCmdAlloc[i]->Release(); pCmdAlloc[i]->Release();
pRtvDescHeap->Release(); pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc; delete[]pCmdAlloc;
return; return;
} }
pBackBuffer = new ID3D12Resource * [bufferCount];
for (UINT i = 0; i < bufferCount; i++) for (UINT i = 0; i < bufferCount; i++)
{ {
ID3D12Resource* pBackBuffer = NULL; pSwapChain3->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer[i]));
pSwapChain3->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer)); pDevice->CreateRenderTargetView(pBackBuffer[i], NULL, mainRenderTargets[i]);
pDevice->CreateRenderTargetView(pBackBuffer, NULL, pMainRenderTargets[i]);
} }
ImGui::CreateContext(); ImGui::CreateContext();
@ -183,13 +185,28 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain)
UINT bufferIndex = pSwapChain3->GetCurrentBackBufferIndex(); 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->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); pCmdList->SetDescriptorHeaps(1, &pSrvDescHeap);
ImGui::Render(); ImGui::Render();
ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), pCmdList); 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(); pCmdList->Close();
pCmdQueue->ExecuteCommandLists(1, (ID3D12CommandList**)&pCmdList); pCmdQueue->ExecuteCommandLists(1, (ID3D12CommandList**)&pCmdList);
pSwapChain3->Release(); pSwapChain3->Release();
@ -218,6 +235,7 @@ void STDMETHODCALLTYPE DX12_Hook::MyExecuteCommandLists(ID3D12CommandQueue *_thi
{ {
DX12_Hook* me = DX12_Hook::Inst(); DX12_Hook* me = DX12_Hook::Inst();
me->pCmdQueue = _this; me->pCmdQueue = _this;
(_this->*DX12_Hook::Inst()->ExecuteCommandLists)(NumCommandLists, ppCommandLists); (_this->*DX12_Hook::Inst()->ExecuteCommandLists)(NumCommandLists, ppCommandLists);
} }
@ -225,7 +243,6 @@ DX12_Hook::DX12_Hook():
initialized(false), initialized(false),
pCmdQueue(nullptr), pCmdQueue(nullptr),
bufferCount(0), bufferCount(0),
pMainRenderTargets(nullptr),
pCmdAlloc(nullptr), pCmdAlloc(nullptr),
pSrvDescHeap(nullptr), pSrvDescHeap(nullptr),
pCmdList(nullptr), pCmdList(nullptr),
@ -249,10 +266,13 @@ DX12_Hook::~DX12_Hook()
{ {
pSrvDescHeap->Release(); pSrvDescHeap->Release();
for (UINT i = 0; i < bufferCount; ++i) for (UINT i = 0; i < bufferCount; ++i)
{
pCmdAlloc[i]->Release(); pCmdAlloc[i]->Release();
pBackBuffer[i]->Release();
}
pRtvDescHeap->Release(); pRtvDescHeap->Release();
delete[]pMainRenderTargets;
delete[]pCmdAlloc; delete[]pCmdAlloc;
delete[]pBackBuffer;
ImGui_ImplDX12_InvalidateDeviceObjects(); ImGui_ImplDX12_InvalidateDeviceObjects();
ImGui::DestroyContext(); ImGui::DestroyContext();

View file

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