Skip to content

Commit

Permalink
Merge pull request #439 from Mattiwatti/v110-win7
Browse files Browse the repository at this point in the history
Fixes for v1.10 on Windows 7
  • Loading branch information
Yamashi authored Jan 24, 2021
2 parents e53926c + 0acd690 commit b035c38
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ Options::Options(Paths& aPaths)
throw std::runtime_error("Not Cyberpunk2077.exe");

set_default_logger(CreateLogger(m_paths.CETRoot() / "cyber_engine_tweaks.log", "main"));
spdlog::flush_every(std::chrono::seconds(3));

spdlog::info("Cyber Engine Tweaks is starting...");

Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/D3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct D3D12
D3D12_CPU_DESCRIPTOR_HANDLE MainRenderTargetDescriptor{ 0 };
};

bool ResetState();
bool ResetState(bool aClearDownlevelBackbuffers = true);
bool Initialize(IDXGISwapChain* apSwapChain);
bool InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow);
bool InitializeImGui(size_t aBuffersCounts);
Expand Down
9 changes: 5 additions & 4 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <window/Window.h>
#include "Options.h"

bool D3D12::ResetState()
bool D3D12::ResetState(bool aClearDownlevelBackbuffers)
{
if (m_initialized)
{
Expand All @@ -18,7 +18,8 @@ bool D3D12::ResetState()
ImGui_ImplWin32_Shutdown();
}
m_frameContexts.clear();
m_downlevelBackbuffers.clear();
if (aClearDownlevelBackbuffers)
m_downlevelBackbuffers.clear();
m_pdxgiSwapChain = nullptr;
m_pd3d12Device = nullptr;
m_pd3dRtvDescHeap = nullptr;
Expand Down Expand Up @@ -375,7 +376,7 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)
return false;
}

if (!ImGui_ImplDX12_CreateDeviceObjects())
if (!ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue))
{
spdlog::error("D3D12::InitializeImGui() - ImGui_ImplDX12_CreateDeviceObjects call failed!");
ImGui_ImplDX12_Shutdown();
Expand All @@ -388,7 +389,7 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)

void D3D12::Update()
{
ImGui_ImplDX12_NewFrame();
ImGui_ImplDX12_NewFrame(m_pCommandQueue);
ImGui_ImplWin32_NewFrame(m_outSize);
ImGui::NewFrame();

Expand Down
15 changes: 10 additions & 5 deletions src/d3d12/D3D12_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ HRESULT D3D12::PresentDownlevel(ID3D12CommandQueueDownlevel* apCommandQueueDownl
auto& d3d12 = CET::Get().GetD3D12();

// On Windows 7 there is no swap chain to query the current backbuffer index. Instead do a reverse lookup in the known backbuffer list
auto it = std::find(d3d12.m_downlevelBackbuffers.cbegin(), d3d12.m_downlevelBackbuffers.cend(), apSourceTex2D);
const auto cbegin = d3d12.m_downlevelBackbuffers.size() >= g_numDownlevelBackbuffersRequired
? d3d12.m_downlevelBackbuffers.cend() - g_numDownlevelBackbuffersRequired
: d3d12.m_downlevelBackbuffers.cbegin();
auto it = std::find(cbegin, d3d12.m_downlevelBackbuffers.cend(), apSourceTex2D);
if (it == d3d12.m_downlevelBackbuffers.cend())
{
if (d3d12.m_initialized)
Expand Down Expand Up @@ -87,11 +90,13 @@ HRESULT D3D12::CreateCommittedResource(ID3D12Device* apDevice, const D3D12_HEAP_
// Store the returned resource
d3d12.m_downlevelBackbuffers.emplace_back(static_cast<ID3D12Resource*>(*appvResource));
spdlog::debug("D3D12::CreateCommittedResourceD3D12() - found valid backbuffer target at {0}.", *appvResource);
}

// If D3D12 has been initialized, there is no need to continue hooking this function since the backbuffers are only created once.
if (d3d12.m_initialized)
kiero::unbind(27);
if (d3d12.m_initialized)
{
// Reset state (a resize may have happened), but don't touch the backbuffer list. The downlevel Present hook will take care of this
d3d12.ResetState(false);
}
}

return result;
}
Expand Down
24 changes: 7 additions & 17 deletions src/imgui_impl/dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* apDrawData, ID3D12GraphicsCommand
}
}

static void ImGui_ImplDX12_CreateFontsTexture()
static void ImGui_ImplDX12_CreateFontsTexture(ID3D12CommandQueue* apCommandQueue)
{
// Build texture atlas
ImGuiIO& io = ImGui::GetIO();
Expand Down Expand Up @@ -340,15 +340,6 @@ static void ImGui_ImplDX12_CreateFontsTexture()
HANDLE event = CreateEvent(0, 0, 0, 0);
IM_ASSERT(event != NULL);

D3D12_COMMAND_QUEUE_DESC queueDesc = {};
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.NodeMask = 1;

ID3D12CommandQueue* cmdQueue = NULL;
hr = g_pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
IM_ASSERT(SUCCEEDED(hr));

ID3D12CommandAllocator* cmdAlloc = NULL;
hr = g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
IM_ASSERT(SUCCEEDED(hr));
Expand All @@ -363,16 +354,15 @@ static void ImGui_ImplDX12_CreateFontsTexture()
hr = cmdList->Close();
IM_ASSERT(SUCCEEDED(hr));

cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
hr = cmdQueue->Signal(fence, 1);
apCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
hr = apCommandQueue->Signal(fence, 1);
IM_ASSERT(SUCCEEDED(hr));

fence->SetEventOnCompletion(1, event);
WaitForSingleObject(event, INFINITE);

cmdList->Release();
cmdAlloc->Release();
cmdQueue->Release();
CloseHandle(event);
fence->Release();
uploadBuffer->Release();
Expand All @@ -395,7 +385,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
io.Fonts->TexID = (ImTextureID)g_hFontSrvGpuDescHandle.ptr;
}

bool ImGui_ImplDX12_CreateDeviceObjects()
bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue)
{
if (!g_pd3dDevice)
return false;
Expand Down Expand Up @@ -628,7 +618,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
if (result_pipeline_state != S_OK)
return false;

ImGui_ImplDX12_CreateFontsTexture();
ImGui_ImplDX12_CreateFontsTexture(apCommandQueue);

return true;
}
Expand Down Expand Up @@ -695,8 +685,8 @@ void ImGui_ImplDX12_Shutdown()
g_frameIndex = UINT_MAX;
}

void ImGui_ImplDX12_NewFrame()
void ImGui_ImplDX12_NewFrame(ID3D12CommandQueue* apCommandQueue)
{
if (!g_pPipelineState)
ImGui_ImplDX12_CreateDeviceObjects();
ImGui_ImplDX12_CreateDeviceObjects(apCommandQueue);
}
4 changes: 2 additions & 2 deletions src/imgui_impl/dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE;
// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture.
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* apDevice, int aNumFramesInFlight, DXGI_FORMAT aRTVFormat, ID3D12DescriptorHeap* apSRVHeapDesc, D3D12_CPU_DESCRIPTOR_HANDLE aFontSRVDescCPU, D3D12_GPU_DESCRIPTOR_HANDLE aFontSRVDescGPU);
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(ID3D12CommandQueue* apCommandQueue);
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* apDrawData, ID3D12GraphicsCommandList* apCommandLists);

// Use if you want to reset your rendering device without losing Dear ImGui state.
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue);

0 comments on commit b035c38

Please sign in to comment.