Try to find device by also checking device id

Use glXQueryCurrentRendererIntegerMESA for OpenGL, if supported.
mtsdf
jackun 3 years ago
parent 31e879215a
commit 14507c402d
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -21,6 +21,14 @@
#include <glad/glad.h>
#ifndef PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC
typedef int ( *PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC) (int attribute, unsigned int *value);
#define GLX_RENDERER_VENDOR_ID_MESA 0x8183
#define GLX_RENDERER_DEVICE_ID_MESA 0x8184
#endif
extern void* get_glx_proc_address(const char* name);
namespace MangoHud { namespace GL {
struct GLVec
@ -66,6 +74,16 @@ overlay_params params {};
static std::unique_ptr<notify_thread, std::function<void(notify_thread *)>>
stop_it(&notifier, [](notify_thread *n){ stop_notifier(*n); });
static bool mesa_queryInteger(int attrib, unsigned int *value)
{
static PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC queryInteger =
reinterpret_cast<decltype(queryInteger)>(get_glx_proc_address(
"glXQueryCurrentRendererIntegerMESA"));
if (queryInteger)
return !!queryInteger(attrib, value);
return false;
}
void imgui_init()
{
if (cfg_inited)
@ -111,7 +129,7 @@ void imgui_init()
}
//static
void imgui_create(void *ctx)
void imgui_create(void* ctx, const gl_platform plat)
{
if (inited)
return;
@ -137,7 +155,12 @@ void imgui_create(void *ctx)
} else {
vendorID = 0x10de;
}
init_gpu_stats(vendorID, params);
uint32_t device_id = 0;
if (plat == gl_platform::GLX)
mesa_queryInteger(GLX_RENDERER_DEVICE_ID_MESA, &device_id);
init_gpu_stats(vendorID, device_id, params);
get_device_name(vendorID, deviceID, sw_stats);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
@ -178,13 +201,6 @@ void imgui_shutdown()
inited = false;
}
void imgui_set_context(void *ctx)
{
if (!ctx)
return;
imgui_create(ctx);
}
void imgui_render(unsigned int width, unsigned int height)
{
if (!state.imgui_ctx)

@ -7,13 +7,18 @@
namespace MangoHud { namespace GL {
enum gl_platform
{
GLX,
EGL,
};
extern overlay_params params;
void imgui_init();
void imgui_create(void *ctx);
void imgui_create(void* ctx, const gl_platform plat);
void imgui_shutdown();
void imgui_set_context(void *ctx);
void imgui_render(unsigned int width, unsigned int height);
}} // namespace
#endif //MANGOHUD_GL_IMGUI_HUD_H
#endif //MANGOHUD_GL_IMGUI_HUD_H

@ -59,7 +59,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_egl_proc_address("eglQuerySurface"));
imgui_create(surf);
imgui_create(surf, gl_platform::EGL);
int width=0, height=0;
if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) &&

@ -101,7 +101,8 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) {
if (!is_blacklisted()) {
if (ret) {
imgui_set_context(ctx);
if (ctx)
imgui_create(ctx, gl_platform::GLX);
SPDLOG_DEBUG("GL ref count: {}", refcnt);
}
@ -125,7 +126,7 @@ static void do_imgui_swap(void *dpy, void *drawable)
{
GLint vp[4];
if (!is_blacklisted()) {
imgui_create(glx.GetCurrentContext());
imgui_create(glx.GetCurrentContext(), gl_platform::GLX);
unsigned int width = -1, height = -1;

@ -30,7 +30,7 @@ float g_overflow = 50.f /* 3333ms * 0.5 / 16.6667 / 2 (to edge and back) */;
#endif
string gpuString,wineVersion,wineProcess;
int32_t deviceID;
uint32_t deviceID;
bool gui_open = false;
struct benchmark_stats benchmark;
struct fps_limit fps_limit_stats {};
@ -493,7 +493,7 @@ struct pci_bus {
int func;
};
void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
void init_gpu_stats(uint32_t& vendorID, uint32_t target_device_id, overlay_params& params)
{
//if (!params.enabled[OVERLAY_PARAM_ENABLED_gpu_stats])
// return;

@ -99,7 +99,7 @@ struct LOAD_DATA {
};
extern struct fps_limit fps_limit_stats;
extern int32_t deviceID;
extern uint32_t deviceID;
extern struct benchmark_stats benchmark;
extern ImVec2 real_font_size;
@ -110,7 +110,7 @@ void position_layer(struct swapchain_stats& data, struct overlay_params& params,
void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& window_size, bool is_vulkan);
void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void init_gpu_stats(uint32_t& vendorID, overlay_params& params);
void init_gpu_stats(uint32_t& vendorID, uint32_t target_device_id, overlay_params& params);
void init_cpu_stats(overlay_params& params);
void check_keybinds(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID);
void init_system_info(void);

@ -1847,7 +1847,7 @@ static VkResult overlay_CreateDevice(
if (!is_blacklisted()) {
device_map_queues(device_data, pCreateInfo);
init_gpu_stats(device_data->properties.vendorID, device_data->instance->params);
init_gpu_stats(device_data->properties.vendorID, device_data->properties.deviceID, device_data->instance->params);
}
return result;

Loading…
Cancel
Save