[win32] Use single ImGui context; get DXGI adapter descriptions

d3d11
jackun 4 years ago
parent 2778618f36
commit 46ed24db80

@ -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);
}

@ -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(&params);
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);
}

@ -1,4 +1,5 @@
#include "dx_shared.h"
#include <dxgi.h>
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<IUnknown*>(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();

@ -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);
Loading…
Cancel
Save