From 03f0363ad3b0c227dd2e0fccd01102b5c450be35 Mon Sep 17 00:00:00 2001 From: jackun Date: Sat, 9 Jul 2022 15:44:57 +0300 Subject: [PATCH] [OpenGL] Use MESA_query_renderer if avail; GL WSI enum --- src/gl/gl_hud.cpp | 32 ++++++++++++++++++++++++++++---- src/gl/gl_hud.h | 10 ++++++++-- src/gl/inject_egl.cpp | 2 +- src/gl/inject_glx.cpp | 4 ++-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/gl/gl_hud.cpp b/src/gl/gl_hud.cpp index 706f216..34bba4d 100644 --- a/src/gl/gl_hud.cpp +++ b/src/gl/gl_hud.cpp @@ -22,6 +22,14 @@ namespace fs = ghc::filesystem; +#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 @@ -67,6 +75,17 @@ overlay_params params {}; static std::unique_ptr> stop_it(¬ifier, [](notify_thread *n){ stop_notifier(*n); }); + +static bool mesa_queryInteger(int attrib, unsigned int *value) +{ + static PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC queryInteger = + reinterpret_cast(get_glx_proc_address( + "glXQueryCurrentRendererIntegerMESA")); + if (queryInteger) + return !!queryInteger(attrib, value); + return false; +} + void imgui_init() { if (cfg_inited) @@ -108,7 +127,7 @@ void imgui_init() } //static -void imgui_create(void *ctx) +void imgui_create(void *ctx, const gl_platform plat) { if (inited) return; @@ -137,7 +156,12 @@ 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_platform::GLX) + mesa_queryInteger(GLX_RENDERER_DEVICE_ID_MESA, &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 @@ -179,11 +203,11 @@ void imgui_shutdown() inited = false; } -void imgui_set_context(void *ctx) +void imgui_set_context(void *ctx, const gl_platform 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 99658ef..7303163 100644 --- a/src/gl/gl_hud.h +++ b/src/gl/gl_hud.h @@ -7,11 +7,17 @@ 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_set_context(void *ctx, const gl_platform 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 d12b023..0de3b5c 100644 --- a/src/gl/inject_egl.cpp +++ b/src/gl/inject_egl.cpp @@ -59,7 +59,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_platform::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 55a985d..98e3b4b 100644 --- a/src/gl/inject_glx.cpp +++ b/src/gl/inject_glx.cpp @@ -101,7 +101,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_platform::GLX); SPDLOG_DEBUG("GL ref count: {}", refcnt); } @@ -125,7 +125,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;