tracy
tracy copied to clipboard
Build and run on pure wayland env
It can not be built on pure wayland env without X11. I don't expect this can be merged into master, but it can be a workaround for guys interested on running on wayland.
The primary problem comes from:
-
imgui_impl_opengl3_loader.h
is not portable on all platforms, and should not be included. Instead, however, we could directly linklibGL
, or linkglesv2
for wayland. And because you need to use GL types, you also need to include types from headers manually likeimgui_impl_opengl3.cpp
. - Pure wayland use EGL and GLES2 exclusively, and glfw/cmake needs to be tweaked accordingly.
I have a dirty patch to build and run tracy:
diff --git a/profiler/build/unix/build.mk b/profiler/build/unix/build.mk
index 1e87b632..9e57335e 100644
--- a/profiler/build/unix/build.mk
+++ b/profiler/build/unix/build.mk
@@ -8,7 +8,8 @@ DISPLAY_SERVER := X11
ifdef TRACY_USE_WAYLAND
DISPLAY_SERVER := WAYLAND
- LIBS += $(shell pkg-config --libs wayland-client)
+ LIBS += $(shell pkg-config --libs wayland-client glesv2)
+ DEFINES += -DIMGUI_IMPL_OPENGL_ES2
endif
CXXFLAGS += -D"DISPLAY_SERVER_$(DISPLAY_SERVER)"
diff --git a/profiler/src/imgui_impl_opengl3.h b/profiler/src/imgui_impl_opengl3.h
index 84d9135b..2942a663 100644
--- a/profiler/src/imgui_impl_opengl3.h
+++ b/profiler/src/imgui_impl_opengl3.h
@@ -21,6 +21,15 @@
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
+#include <GLES2/gl2.h>
+#if defined(__EMSCRIPTEN__)
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+#endif
+#include <GLES2/gl2ext.h>
+#endif
+
+
// Backend API
IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL);
IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp
index 0f885883..79ecd45b 100644
--- a/profiler/src/main.cpp
+++ b/profiler/src/main.cpp
@@ -6,7 +6,6 @@
#include <imgui.h>
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
-#include "imgui_impl_opengl3_loader.h"
#include <mutex>
#include <stdint.h>
#include <stdio.h>
@@ -292,12 +291,15 @@ int main( int argc, char** argv )
if( !glfwInit() ) return 1;
#ifdef DISPLAY_SERVER_WAYLAND
glfwWindowHint(GLFW_ALPHA_BITS, 0);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
+ glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
#else
glfwWindowHint(GLFW_VISIBLE, 0);
-#endif
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+#endif
#if __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
diff --git a/server/TracyTexture.cpp b/server/TracyTexture.cpp
index cdc2e489..6872d2d6 100644
--- a/server/TracyTexture.cpp
+++ b/server/TracyTexture.cpp
@@ -1,6 +1,6 @@
#include <inttypes.h>
-#include "../profiler/src/imgui_impl_opengl3_loader.h"
+#include "../profiler/src/imgui_impl_opengl3.h"
#include "TracyTexture.hpp"
#ifndef COMPRESSED_RGB_S3TC_DXT1_EXT
Except the includes of GLES
headers in imgui_impl_opengl3_loader.h
, this patch is actually portable.
By the way, it looks like 7dbfed9aeaa5a706f15fa5b74b5dbb509ce74b26 broke compilation on wayland-only systems. I fixed it by adding back in LIBS += $(shell pkg-config --libs wayland-client)
.
Edit: Even though that did fix the build, the resulting Tracy failed to run with the following error message:
xdg_wm_base@9: error 3: xdg_surface must not have a buffer at creation
v0.8.2.1 works just fine though!
At this point only X11 is supported.
There is a number of issues when Wayland backend is used. For example, the GLFW library does not support changing window position or setting the window icon with Wayland implementation. This is a serious WTF moment, considering what the tasks of GLFW are. Yet here we are. Moreover, with GLFW on Wayland the Hi-DPI scaling is broken, which is suprising, as generally Hi-DPI support is what Wayland is much better at than X11.
Then there are compositors, where you have the myriad of questionably maintained one-trick-ponies, the still-in-alpha-state KDE, or GNOME, which will make your life harder because fuck you, that's why! Like, for example, how you get the ugly white border with no controls in stead of something looking like the rest of the desktop environment, when you launch Tracy with Wayland backend under GNOME.
It's a shitshow.
Recently I have extracted all the GLFW-related functionality to BackendGlfw.cpp
, which in turn implements a generic Backend.hpp
interface. I could see Wayland support going forward with a separate Wayland-native backend, in order to get things like 1:1 mapping of trackpad-to-on-screen motion, etc. With some effort it could event implement client-side decorations using parts of the existing UI, as apparently that's what cool kids do nowadays.
Understandable.
From my perspective though, I use linux with a tiling window manager only, no desktop environment. This means that most of the issues you mentioned are not actually issues for me. Changing window position? That wouldn't matter since the wm would change it back anyway. Window icon? I don't have a tray where that would be displayed anyway, none of my applications have icons. Decorations? None of my windows have decorations, I just use a keyboard shortcut to close windows, and multiple workspaces makes minimizing windows unnecessary.
I'm not certain, but perhaps many wayland users are like me, considering that the de facto-standard wayland toolkit (wlroots) was originally developed for the tiling wm I use, sway, and the lead developer of sway is also one of the leads of the wayland project.
I solved tihs by running it in a systemd-nspawn container, and giving the container access to the X socket ensuring that it uses X through the container, while I'm running wayland and sway on the desktop.
sudo systemd-nspawn -D/var/lib/machines/tracy \
--setenv=DISPLAY=:0.0 \
--link-journal=host \
--bind=/dev/dri \
--bind=/tmp/X11-unix \
sudo -u \
/home/noname/tracy/profiler/build/unix/Tracy-release
It fails to start with surface errors when run natively outside of the container, no matter what environment variables are set trying to force X. But it works fine in a container.
On current master you can build a wayland-native application with the following changes:
--- a/profiler/build/unix/build.mk
+++ b/profiler/build/unix/build.mk
@@ -1,15 +1,18 @@
CFLAGS +=
CXXFLAGS := $(CFLAGS) -std=c++17
DEFINES += -DIMGUI_ENABLE_FREETYPE
-INCLUDES := $(shell pkg-config --cflags glfw3 freetype2 capstone) -I../../../imgui
-LIBS := $(shell pkg-config --libs glfw3 freetype2 capstone) -lpthread -ldl
+INCLUDES := $(shell pkg-config --cflags freetype2 capstone wayland-egl egl wayland-cursor) -I../../../imgui
+LIBS := $(shell pkg-config --libs freetype2 capstone wayland-egl egl wayland-cursor) -lpthread -ldl
PROJECT := Tracy
IMAGE := $(PROJECT)-$(BUILD)
-FILTER := ../../../nfd/nfd_win.cpp
+FILTER := ../../../nfd/nfd_win.cpp ../../src/BackendGlfw.cpp ../../src/imgui/imgui_impl_glfw.cpp
include ../../../common/src-from-vcxproj.mk
+SRC += ../../src/BackendWayland.cpp
+SRC2 += ../../src/wayland/xdg-shell.c ../../src/wayland/xdg-activation.c ../../src/wayland/xdg-decoration.c
+
ifdef TRACY_NO_FILESELECTOR
CXXFLAGS += -DTRACY_NO_FILESELECTOR
else
Note that it does not have keyboard support implemented yet. Otherwise it should be feature complete.
Wayland is now the default target and does not require the patch above.
Keyboard support is now implemented.