diff --git a/src/gl/gl_hud.cpp b/src/gl/gl_hud.cpp index 1b6364cf..f5588537 100644 --- a/src/gl/gl_hud.cpp +++ b/src/gl/gl_hud.cpp @@ -16,6 +16,11 @@ #include +#define GLX_RENDERER_VENDOR_ID_MESA 0x8183 +#define GLX_RENDERER_DEVICE_ID_MESA 0x8184 + +bool glx_mesa_queryInteger(int attrib, unsigned int *value); + namespace MangoHud { namespace GL { struct GLVec @@ -93,7 +98,7 @@ void imgui_init() } //static -void imgui_create(void *ctx) +void imgui_create(void *ctx, const gl_wsi plat) { if (inited) return; @@ -134,7 +139,13 @@ void imgui_create(void *ctx) } if (deviceName.find("zink") != std::string::npos) sw_stats.engine = EngineTypes::ZINK; - init_gpu_stats(vendorID, 0, params); + + uint32_t device_id = 0; + if (plat == gl_wsi::GL_WSI_GLX) + glx_mesa_queryInteger(GLX_RENDERER_DEVICE_ID_MESA, &device_id); + + SPDLOG_DEBUG("GL device id: {:04X}", device_id); + init_gpu_stats(vendorID, device_id, params); sw_stats.gpuName = gpu = get_device_name(vendorID, deviceID); SPDLOG_DEBUG("gpu: {}", gpu); // Setup Dear ImGui context @@ -176,11 +187,11 @@ void imgui_shutdown() inited = false; } -void imgui_set_context(void *ctx) +void imgui_set_context(void *ctx, const gl_wsi plat) { if (!ctx) return; - imgui_create(ctx); + imgui_create(ctx, plat); } void imgui_render(unsigned int width, unsigned int height) diff --git a/src/gl/gl_hud.h b/src/gl/gl_hud.h index 99658ef7..d710555e 100644 --- a/src/gl/gl_hud.h +++ b/src/gl/gl_hud.h @@ -7,11 +7,18 @@ namespace MangoHud { namespace GL { +enum gl_wsi +{ + GL_WSI_UNKNOWN, + GL_WSI_GLX, + GL_WSI_EGL, +}; + extern overlay_params params; void imgui_init(); -void imgui_create(void *ctx); +void imgui_create(void *ctx, const gl_wsi plat); void imgui_shutdown(); -void imgui_set_context(void *ctx); +void imgui_set_context(void *ctx, const gl_wsi plat); void imgui_render(unsigned int width, unsigned int height); }} // namespace diff --git a/src/gl/inject_egl.cpp b/src/gl/inject_egl.cpp index 3e9745a5..9760a103 100644 --- a/src/gl/inject_egl.cpp +++ b/src/gl/inject_egl.cpp @@ -53,7 +53,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf) if (!pfn_eglQuerySurface) pfn_eglQuerySurface = reinterpret_cast(get_egl_proc_address("eglQuerySurface")); - imgui_create(surf); + imgui_create(surf, gl_wsi::GL_WSI_EGL); int width=0, height=0; if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) && diff --git a/src/gl/inject_glx.cpp b/src/gl/inject_glx.cpp index 47dab79c..d9339395 100644 --- a/src/gl/inject_glx.cpp +++ b/src/gl/inject_glx.cpp @@ -51,6 +51,17 @@ static void* get_glx_proc_address(const char* name) { return func; } +bool glx_mesa_queryInteger(int attrib, unsigned int *value); +bool glx_mesa_queryInteger(int attrib, unsigned int *value) +{ + static int (*pfn_queryInteger)(int attribute, unsigned int *value) = + reinterpret_cast(get_glx_proc_address( + "glXQueryCurrentRendererIntegerMESA")); + if (pfn_queryInteger) + return !!pfn_queryInteger(attrib, value); + return false; +} + EXPORT_C_(void *) glXCreateContext(void *dpy, void *vis, void *shareList, int direct) { glx.Load(); @@ -99,7 +110,7 @@ EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) { if (!is_blacklisted()) { if (ret) { - imgui_set_context(ctx); + imgui_set_context(ctx, gl_wsi::GL_WSI_GLX); SPDLOG_DEBUG("GL ref count: {}", refcnt); } @@ -123,7 +134,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_wsi::GL_WSI_GLX); unsigned int width = -1, height = -1;