Skip to content

Commit

Permalink
Remove kiero
Browse files Browse the repository at this point in the history
Game does not support Windows 7 anymore, we don't have to also
  • Loading branch information
WSSDude committed Jan 11, 2025
1 parent 175dfa6 commit 77cf288
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 696 deletions.
2 changes: 1 addition & 1 deletion src/d3d12/D3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ D3D12::D3D12(Window& aWindow, Paths& aPaths, Options& aOptions)
, m_window(aWindow)
, m_options(aOptions)
{
HookGame();
Hook();

// add repeated task which prepares next ImGui frame for update
GameMainThread::Get().AddGenericTask(
Expand Down
21 changes: 1 addition & 20 deletions src/d3d12/D3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include "common/D3D12Downlevel.h"
#include "window/Window.h"

using TPresentD3D12Downlevel = HRESULT(ID3D12CommandQueueDownlevel*, ID3D12GraphicsCommandList*, ID3D12Resource*, HWND, D3D12_DOWNLEVEL_PRESENT_FLAGS);
using TCreateCommittedResource =
HRESULT(ID3D12Device*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES, const D3D12_CLEAR_VALUE*, const IID*, void**);
using TExecuteCommandLists = void(ID3D12CommandQueue*, UINT, ID3D12CommandList* const*);
using TCRenderNode_Present_InternalPresent = void*(int32_t*, uint8_t, UINT);
using TCRenderGlobal_Resize = void*(uint32_t a1, uint32_t a2, uint32_t a3, uint8_t a4, int32_t* a5);
using TCRenderGlobal_Shutdown = void*(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
Expand Down Expand Up @@ -35,7 +31,6 @@ struct D3D12

protected:
void Hook();
void HookGame();

struct FrameContext
{
Expand All @@ -44,39 +39,25 @@ struct D3D12
D3D12_CPU_DESCRIPTOR_HANDLE MainRenderTargetDescriptor{0};
};

bool ResetState(const bool acClearDownlevelBackbuffers = true, const bool acDestroyContext = false);
bool ResetState(const bool acDestroyContext = false);
bool Initialize();
bool InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow);
bool InitializeImGui(size_t aBuffersCounts);

void PrepareUpdate();
void Update();

static HRESULT PresentDownlevel(
ID3D12CommandQueueDownlevel* apCommandQueueDownlevel, ID3D12GraphicsCommandList* apOpenCommandList, ID3D12Resource* apSourceTex2D, HWND ahWindow,
D3D12_DOWNLEVEL_PRESENT_FLAGS aFlags);
static HRESULT CreateCommittedResource(
ID3D12Device* apDevice, const D3D12_HEAP_PROPERTIES* acpHeapProperties, D3D12_HEAP_FLAGS aHeapFlags, const D3D12_RESOURCE_DESC* acpDesc,
D3D12_RESOURCE_STATES aInitialResourceState, const D3D12_CLEAR_VALUE* acpOptimizedClearValue, const IID* acpRIID, void** appvResource);
static void ExecuteCommandLists(ID3D12CommandQueue* apCommandQueue, UINT aNumCommandLists, ID3D12CommandList* const* apcpCommandLists);

static void* CRenderNode_Present_InternalPresent(int32_t* apSomeInt, uint8_t aSomeSync, UINT aSyncInterval);
static void* CRenderGlobal_Resize(uint32_t a1, uint32_t a2, uint32_t a3, uint8_t a4, int32_t* a5);
static void* CRenderGlobal_Shutdown(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);

private:
TPresentD3D12Downlevel* m_realPresentD3D12Downlevel{nullptr};
TCreateCommittedResource* m_realCreateCommittedResource{nullptr};
TExecuteCommandLists* m_realExecuteCommandLists{nullptr};
TCRenderNode_Present_InternalPresent* m_realInternalPresent{nullptr};
TCRenderGlobal_Resize* m_realInternalResize{nullptr};
TCRenderGlobal_Shutdown* m_realInternalShutdown{nullptr};

bool m_initialized{false};

TiltedPhoques::Vector<FrameContext> m_frameContexts;
TiltedPhoques::Vector<Microsoft::WRL::ComPtr<ID3D12Resource>> m_downlevelBackbuffers;
uint32_t m_downlevelBufferIndex{0};

Microsoft::WRL::ComPtr<ID3D12Device> m_pd3d12Device{};
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> m_pd3dRtvDescHeap{};
Expand Down
141 changes: 3 additions & 138 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <imgui_impl/win32.h>
#include <window/window.h>

bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDestroyContext)
bool D3D12::ResetState(const bool acDestroyContext)
{
if (m_initialized)
{
Expand All @@ -32,10 +32,6 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
m_frameContexts.clear();
m_outSize = {0, 0};

if (acClearDownlevelBackbuffers)
m_downlevelBackbuffers.clear();
m_downlevelBufferIndex = 0;

m_pd3d12Device.Reset();
m_pd3dRtvDescHeap.Reset();
m_pd3dSrvDescHeap.Reset();
Expand Down Expand Up @@ -144,137 +140,6 @@ bool D3D12::Initialize()
return true;
}

bool D3D12::InitializeDownlevel(ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow)
{
if (!apCommandQueue || !apSourceTex2D)
return false;

const HWND hWnd = m_window.GetWindow();
if (!hWnd)
{
Log::Warn("D3D12::InitializeDownlevel() - window not yet hooked!");
return false;
}

if (m_initialized)
{
if (hWnd != ahWindow)
Log::Warn(
"D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked "
"to {} while current output window is {}.",
reinterpret_cast<void*>(hWnd), reinterpret_cast<void*>(ahWindow));

return true;
}

const auto cmdQueueDesc = apCommandQueue->GetDesc();
if (cmdQueueDesc.Type != D3D12_COMMAND_LIST_TYPE_DIRECT)
{
Log::Warn("D3D12::InitializeDownlevel() - ignoring command queue - invalid type of command list!");
return false;
}

m_pCommandQueue = apCommandQueue;

const auto st2DDesc = apSourceTex2D->GetDesc();
m_outSize = {static_cast<LONG>(st2DDesc.Width), static_cast<LONG>(st2DDesc.Height)};

if (hWnd != ahWindow)
Log::Warn(
"D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked to {} "
"while current output window is {}.",
reinterpret_cast<void*>(hWnd), reinterpret_cast<void*>(ahWindow));

if (FAILED(apSourceTex2D->GetDevice(IID_PPV_ARGS(&m_pd3d12Device))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to get device!");
return ResetState();
}

const size_t buffersCounts = m_downlevelBackbuffers.size();
m_frameContexts.resize(buffersCounts);
if (buffersCounts == 0)
{
Log::Error("D3D12::InitializeDownlevel() - no backbuffers were found!");
return ResetState();
}
if (buffersCounts < g_numDownlevelBackbuffersRequired)
{
Log::Info("D3D12::InitializeDownlevel() - backbuffer list is not complete yet; assuming window was resized");
return false;
}

D3D12_DESCRIPTOR_HEAP_DESC rtvdesc;
rtvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtvdesc.NumDescriptors = static_cast<UINT>(buffersCounts);
rtvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
rtvdesc.NodeMask = 1;
if (FAILED(m_pd3d12Device->CreateDescriptorHeap(&rtvdesc, IID_PPV_ARGS(&m_pd3dRtvDescHeap))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create RTV descriptor heap!");
return ResetState();
}

const SIZE_T rtvDescriptorSize = m_pd3d12Device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = m_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
for (auto& context : m_frameContexts)
{
context.MainRenderTargetDescriptor = rtvHandle;
rtvHandle.ptr += rtvDescriptorSize;
}

D3D12_DESCRIPTOR_HEAP_DESC srvdesc = {};
srvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
srvdesc.NumDescriptors = 2;
srvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
if (FAILED(m_pd3d12Device->CreateDescriptorHeap(&srvdesc, IID_PPV_ARGS(&m_pd3dSrvDescHeap))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create SRV descriptor heap!");
return ResetState();
}

for (auto& context : m_frameContexts)
{
if (FAILED(m_pd3d12Device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&context.CommandAllocator))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create command allocator!");
return ResetState();
}
}

if (FAILED(m_pd3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_frameContexts[0].CommandAllocator.Get(), nullptr, IID_PPV_ARGS(&m_pd3dCommandList))))
{
Log::Error("D3D12::InitializeDownlevel() - failed to create command list!");
return ResetState();
}

if (FAILED(m_pd3dCommandList->Close()))
{
Log::Error("D3D12::InitializeDownlevel() - failed to close command list!");
return ResetState();
}

for (size_t i = 0; i < buffersCounts; i++)
{
auto& context = m_frameContexts[i];
context.BackBuffer = m_downlevelBackbuffers[i];
m_pd3d12Device->CreateRenderTargetView(context.BackBuffer.Get(), nullptr, context.MainRenderTargetDescriptor);
}

if (!InitializeImGui(buffersCounts))
{
Log::Error("D3D12::InitializeDownlevel() - failed to initialize ImGui!");
return ResetState();
}

Log::Info("D3D12::InitializeDownlevel() - initialization successful!");
m_initialized = true;

OnInitialized.Emit();

return true;
}

void D3D12::ReloadFonts()
{
std::lock_guard _(m_imguiLock);
Expand Down Expand Up @@ -525,8 +390,8 @@ void D3D12::Update()
if (!m_imguiDrawDataBuffers[0].Valid)
return;

const auto bufferIndex = m_pdxgiSwapChain != nullptr ? m_pdxgiSwapChain->GetCurrentBackBufferIndex() : m_downlevelBufferIndex;
auto& frameContext = m_frameContexts[bufferIndex];
assert(m_pdxgiSwapChain);
auto& frameContext = m_frameContexts[m_pdxgiSwapChain->GetCurrentBackBufferIndex()];
frameContext.CommandAllocator->Reset();

D3D12_RESOURCE_BARRIER barrier;
Expand Down
Loading

0 comments on commit 77cf288

Please sign in to comment.