[OpenGL] Use MESA_query_renderer if avail; GL WSI enum

This commit is contained in:
jackun 2022-07-09 15:44:57 +03:00
parent 421ca3b57b
commit 03f0363ad3
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3
4 changed files with 39 additions and 9 deletions

View File

@ -22,6 +22,14 @@
namespace fs = ghc::filesystem; 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 { namespace MangoHud { namespace GL {
struct GLVec struct GLVec
@ -67,6 +75,17 @@ overlay_params params {};
static std::unique_ptr<notify_thread, std::function<void(notify_thread *)>> static std::unique_ptr<notify_thread, std::function<void(notify_thread *)>>
stop_it(&notifier, [](notify_thread *n){ stop_notifier(*n); }); 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() void imgui_init()
{ {
if (cfg_inited) if (cfg_inited)
@ -108,7 +127,7 @@ void imgui_init()
} }
//static //static
void imgui_create(void *ctx) void imgui_create(void *ctx, const gl_platform plat)
{ {
if (inited) if (inited)
return; return;
@ -137,7 +156,12 @@ void imgui_create(void *ctx)
} }
if (deviceName.find("zink") != std::string::npos) if (deviceName.find("zink") != std::string::npos)
sw_stats.engine = EngineTypes::ZINK; 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); sw_stats.gpuName = gpu = get_device_name(vendorID, deviceID);
SPDLOG_DEBUG("gpu: {}", gpu); SPDLOG_DEBUG("gpu: {}", gpu);
// Setup Dear ImGui context // Setup Dear ImGui context
@ -179,11 +203,11 @@ void imgui_shutdown()
inited = false; inited = false;
} }
void imgui_set_context(void *ctx) void imgui_set_context(void *ctx, const gl_platform plat)
{ {
if (!ctx) if (!ctx)
return; return;
imgui_create(ctx); imgui_create(ctx, plat);
} }
void imgui_render(unsigned int width, unsigned int height) void imgui_render(unsigned int width, unsigned int height)

View File

@ -7,11 +7,17 @@
namespace MangoHud { namespace GL { namespace MangoHud { namespace GL {
enum gl_platform
{
GLX,
EGL,
};
extern overlay_params params; extern overlay_params params;
void imgui_init(); void imgui_init();
void imgui_create(void *ctx); void imgui_create(void *ctx, const gl_platform plat);
void imgui_shutdown(); 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); void imgui_render(unsigned int width, unsigned int height);
}} // namespace }} // namespace

View File

@ -59,7 +59,7 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
if (!pfn_eglQuerySurface) if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_egl_proc_address("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; int width=0, height=0;
if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) && if (pfn_eglQuerySurface(dpy, surf, 0x3056, &height) &&

View File

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