diff --git a/src/kiero/d3d11_impl.cpp b/src/kiero/d3d11_impl.cpp index 4dbfabf5..03ee39f1 100644 --- a/src/kiero/d3d11_impl.cpp +++ b/src/kiero/d3d11_impl.cpp @@ -18,6 +18,7 @@ static Present oPresent = NULL; long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) { static bool init = false; + auto prev_ctx = ImGui::GetCurrentContext(); if (!init) { @@ -30,12 +31,15 @@ long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F ID3D11DeviceContext* context; device->GetImmediateContext(&context); - ImGui::CreateContext(); + imgui_create(context, device); + ImGui::SetCurrentContext(state.imgui_ctx); ImGui_ImplWin32_Init(desc.OutputWindow); ImGui_ImplDX11_Init(device, context); - imgui_create(context); init = true; } + + ImGui::SetCurrentContext(state.imgui_ctx); + update_hud_info(sw_stats, params, vendorID); ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); @@ -47,6 +51,8 @@ long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + ImGui::SetCurrentContext(prev_ctx); + return oPresent(pSwapChain, SyncInterval, Flags); } diff --git a/src/kiero/d3d9_impl.cpp b/src/kiero/d3d9_impl.cpp index f5623439..2c52e24a 100644 --- a/src/kiero/d3d9_impl.cpp +++ b/src/kiero/d3d9_impl.cpp @@ -31,18 +31,22 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) { static bool init = false; + auto prev_ctx = ImGui::GetCurrentContext(); + if (!init) { D3DDEVICE_CREATION_PARAMETERS params; pDevice->GetCreationParameters(¶ms); - auto context = ImGui::CreateContext(); + imgui_create(pDevice, nullptr); + ImGui::SetCurrentContext(state.imgui_ctx); ImGui_ImplWin32_Init(params.hFocusWindow); ImGui_ImplDX9_Init(pDevice); - imgui_create(context); - init = true; } + + ImGui::SetCurrentContext(state.imgui_ctx); + update_hud_info(sw_stats, params, vendorID); ImGui_ImplDX9_NewFrame(); ImGui_ImplWin32_NewFrame(); @@ -53,6 +57,8 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) ImGui::Render(); ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); + ImGui::SetCurrentContext(prev_ctx); + return oEndScene(pDevice); } diff --git a/src/kiero/dx_shared.cpp b/src/kiero/dx_shared.cpp index 7c9ac3c3..134b9e51 100644 --- a/src/kiero/dx_shared.cpp +++ b/src/kiero/dx_shared.cpp @@ -1,4 +1,5 @@ #include "dx_shared.h" +#include bool cfg_inited = false; ImVec2 window_size; @@ -19,20 +20,34 @@ void imgui_init() init_cpu_stats(params); } -void imgui_create(void *ctx) +void imgui_create(void *ctx, void *device) { if (inited) return; inited = true; imgui_init(); - deviceName = "something"; - if (deviceName.find("Radeon") != std::string::npos - || deviceName.find("AMD") != std::string::npos){ - vendorID = 0x1002; - } else { - vendorID = 0x10de; + + // DX10+ + if (device) { + IUnknown* pUnknown = reinterpret_cast(device); + IDXGIDevice* pDXGIDevice; + HRESULT hr = pUnknown->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDXGIDevice); + if (S_OK == hr) { + IDXGIAdapter* pDXGIAdapter; + pDXGIDevice->GetAdapter(&pDXGIAdapter); + DXGI_ADAPTER_DESC adapterDesc; + hr = pDXGIAdapter->GetDesc(&adapterDesc); + + if (S_OK == hr) { + vendorID = adapterDesc.VendorId; + char buf[256]{}; + wcstombs_s(nullptr, buf, adapterDesc.Description, sizeof(adapterDesc.Description)); + deviceName = buf; + } + } } + init_gpu_stats(vendorID, params); // Setup Dear ImGui context IMGUI_CHECKVERSION(); diff --git a/src/kiero/dx_shared.h b/src/kiero/dx_shared.h index 6dd6ef1d..bc91b54f 100644 --- a/src/kiero/dx_shared.h +++ b/src/kiero/dx_shared.h @@ -19,5 +19,5 @@ extern uint32_t vendorID; extern std::string deviceName; extern bool inited; -void imgui_create(void *ctx); +void imgui_create(void *ctx, void *device); void imgui_init(void); \ No newline at end of file