27#include <X11/Xresource.h>
29#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
30#include <vulkan/vulkan.h>
31#include <vulkan/vulkan_xlib.h>
44int32_t GPUDisplayFrontendX11::GetKey(int32_t
key)
52 if (
key == 65505 ||
key == 65506) {
55 if (
key == 65513 ||
key == 65511) {
83 return (KEY_PAGEDOWN);
101 return (KEY_BACKSPACE);
151void GPUDisplayFrontendX11::GetKey(XEvent&
event, int32_t& keyOut, int32_t& keyPressOut)
153 if (
event.xkey.keycode == 49) {
154 keyOut = keyPressOut =
'^';
159 if (XLookupString(&
event.xkey, tmpString, 8, &sym,
nullptr) == 0) {
162 int32_t specialKey = GetKey(sym);
167 keyOut = keyPressOut = specialKey;
169 keyOut = keyPressOut = localeKey;
170 if (keyPressOut >=
'a' && keyPressOut <=
'z') {
171 keyPressOut +=
'A' -
'a';
176int32_t GPUDisplayFrontendX11::FrontendMain()
178 XSetWindowAttributes windowAttributes;
179 XVisualInfo* visualInfo =
nullptr;
182 GLXContext glxContext =
nullptr;
187 mXDisplay = XOpenDisplay(
nullptr);
189 if (mXDisplay ==
nullptr) {
190 GPUError(
"could not open display");
195 if (
const char* resources = XResourceManagerString(mXDisplay)) {
196 XrmDatabase db = XrmGetStringDatabase(resources);
197 char*
type =
nullptr;
199 if (db && XrmGetResource(db,
"Xft.dpi",
"Xft.Dpi", &
type, &
value) &&
value.addr && atof(
value.addr) > 0) {
200 mScale = atof(
value.addr) / 96.;
203 XrmDestroyDatabase(db);
208 if (!glXQueryExtension(mXDisplay, &errorBase, &eventBase)) {
209 GPUError(
"X server has no OpenGL GLX extension");
213 const char* glxExt = glXQueryExtensionsString(mXDisplay, DefaultScreen(mXDisplay));
214 if (strstr(glxExt,
"GLX_EXT_swap_control") ==
nullptr) {
216 GPUError(
"GLX_EXT_swap_control not available, cannot change VSync");
218 vsync_supported =
false;
220 vsync_supported =
true;
224 int32_t attribs[] = {GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 24, GLX_STENCIL_SIZE, 8, GLX_DOUBLEBUFFER, True,
229 GLXFBConfig fbconfig =
nullptr;
231 GLXFBConfig* fbc = glXChooseFBConfig(mXDisplay, DefaultScreen(mXDisplay), attribs, &fbcount);
232 if (fbc ==
nullptr || fbcount == 0) {
233 GPUError(
"Failed to get MSAA GLXFBConfig");
238 visualInfo = glXGetVisualFromFBConfig(mXDisplay, fbconfig);
240 if (visualInfo ==
nullptr) {
241 GPUError(
"no RGB visual with depth buffer");
248 if (glXCreateContextAttribsARB) {
252 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
254 glxContext = glXCreateContextAttribsARB(mXDisplay, fbconfig,
nullptr,
GL_TRUE, context_attribs);
256 glxContext = glXCreateContext(mXDisplay, visualInfo,
nullptr,
GL_TRUE);
258 if (glxContext ==
nullptr) {
259 GPUError(
"could not create rendering context");
264 Window win = RootWindow(mXDisplay, visualInfo->screen);
265 colorMap = XCreateColormap(mXDisplay, win, visualInfo->visual, AllocNone);
266 windowAttributes.colormap = colorMap;
267 windowAttributes.border_pixel = 0;
268 windowAttributes.event_mask = ExposureMask | VisibilityChangeMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | SubstructureNotifyMask | FocusChangeMask | PropertyChangeMask;
272 0, visualInfo->depth, InputOutput, visualInfo->visual, CWBorderPixel | CWColormap | CWEventMask, &windowAttributes);
274 XSizeHints sizeHints{};
275 sizeHints.flags = PMinSize;
276 sizeHints.min_width =
MIN_WIDTH * mScale;
278 XSetWMNormalHints(mXDisplay, mWindow, &sizeHints);
280 glXMakeCurrent(mXDisplay, mWindow, glxContext);
282 XMapWindow(mXDisplay, mWindow);
285 XPeekIfEvent(mXDisplay, &mapEvent, [](Display*, XEvent* ev, XPointer window) ->
Bool {
return ev->type == MapNotify && ev->xmap.window == *(
Window*)window; }, (XPointer)&mWindow);
289 Atom WM_DELETE_WINDOW = XInternAtom(mXDisplay,
"WM_DELETE_WINDOW", False);
290 XSetWMProtocols(mXDisplay, mWindow, &WM_DELETE_WINDOW, 1);
293 fprintf(stderr,
"Error initializing backend\n");
297 XMapWindow(mXDisplay, mWindow);
302 mGlXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((
const GLubyte*)
"glXSwapIntervalEXT");
303 if (mGlXSwapIntervalEXT ==
nullptr) {
304 GPUError(
"Cannot enable vsync");
307 mGlXSwapIntervalEXT(mXDisplay, glXGetCurrentDrawable(),
vsyncEnabled());
319 if (!XPending(mXDisplay)) {
322 XNextEvent(mXDisplay, &
event);
324 switch (
event.type) {
326 if (
event.xbutton.button == 4) {
328 }
else if (
event.xbutton.button == 5) {
331 if (
event.xbutton.button == 1) {
333 }
else if (
event.xbutton.button == 2) {
344 case ButtonRelease: {
345 if (
event.xbutton.button != 4 &&
event.xbutton.button != 5) {
346 if (
event.xbutton.button == 1) {
348 }
else if (
event.xbutton.button == 2) {
358 int32_t handleKey = 0, keyPress = 0;
359 GetKey(
event, handleKey, keyPress);
366 int32_t handleKey = 0, keyPress = 0;
367 GetKey(
event, handleKey, keyPress);
368 mKeys[keyPress] =
false;
383 case PropertyNotify: {
384 if (
event.xproperty.atom == XInternAtom(mXDisplay,
"_NET_WM_STATE", False)) {
394 case ConfigureNotify: {
399 case ClientMessage: {
400 if (
event.xclient.message_type == XInternAtom(mXDisplay,
"_NET_WM_STATE", False)) {
408 }
while (XPending(mXDisplay));
415 glXSwapBuffers(mXDisplay, mWindow);
422 glXDestroyContext(mXDisplay, glxContext);
425 XDestroyWindow(mXDisplay, mWindow);
426 XCloseDisplay(mXDisplay);
437void GPUDisplayFrontendX11::updateWindowState()
441 unsigned long nItems, bytesAfter;
442 unsigned char*
data =
nullptr;
443 if (XGetWindowProperty(mXDisplay, mWindow, XInternAtom(mXDisplay,
"_NET_WM_STATE", False), 0, 1024, False, XA_ATOM, &
type, &
format, &nItems, &bytesAfter, &
data) != Success ||
data ==
nullptr) {
446 const Atom fullScreen = XInternAtom(mXDisplay,
"_NET_WM_STATE_FULLSCREEN", False), maxHorz = XInternAtom(mXDisplay,
"_NET_WM_STATE_MAXIMIZED_HORZ", False), maxVert = XInternAtom(mXDisplay,
"_NET_WM_STATE_MAXIMIZED_VERT", False);
447 bool isFullScreen =
false, isMaxHorz =
false, isMaxVert =
false;
448 for (
unsigned long i = 0;
i < nItems;
i++) {
449 const Atom
a = ((Atom*)
data)[
i];
450 isFullScreen |=
a == fullScreen;
451 isMaxHorz |=
a == maxHorz;
452 isMaxVert |=
a == maxVert;
461 memset(&xev, 0,
sizeof(xev));
462 xev.type = ClientMessage;
463 xev.xclient.window = mWindow;
464 xev.xclient.message_type = XInternAtom(mXDisplay,
"_NET_WM_STATE", False);
465 xev.xclient.format = 32;
466 xev.xclient.data.l[0] = set ? 1 : 0;
467 xev.xclient.data.l[1] = XInternAtom(mXDisplay,
"_NET_WM_STATE_FULLSCREEN", False);
468 xev.xclient.data.l[2] = 0;
469 XSendEvent(mXDisplay, DefaultRootWindow(mXDisplay), False, SubstructureNotifyMask, &xev);
475 memset(&xev, 0,
sizeof(xev));
476 xev.type = ClientMessage;
477 xev.xclient.window = mWindow;
478 xev.xclient.message_type = XInternAtom(mXDisplay,
"_NET_WM_STATE", False);
479 xev.xclient.format = 32;
480 xev.xclient.data.l[0] = set ? 1 : 0;
481 xev.xclient.data.l[1] = XInternAtom(mXDisplay,
"_NET_WM_STATE_MAXIMIZED_HORZ", False);
482 xev.xclient.data.l[2] = XInternAtom(mXDisplay,
"_NET_WM_STATE_MAXIMIZED_VERT", False);
483 XSendEvent(mXDisplay, DefaultRootWindow(mXDisplay), False, SubstructureNotifyMask, &xev);
489 mGlXSwapIntervalEXT(mXDisplay, glXGetCurrentDrawable(), (
int32_t)
enable);
497 uint32_t width_return, height_return, border_width_return, depth_return;
498 if (XGetGeometry(mXDisplay, mWindow, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return) == 0) {
499 throw std::runtime_error(
"Cannot query X11 window geometry");
501 width = width_return;
507#ifdef GPUCA_BUILD_EVENT_DISPLAY_VULKAN
508 VkXlibSurfaceCreateInfoKHR info{};
509 info.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
511 info.dpy = mXDisplay;
512 info.window = mWindow;
513 return vkCreateXlibSurfaceKHR(*(VkInstance*)instance, &info,
nullptr, (VkSurfaceKHR*)
surface) != VK_SUCCESS;
521 static const char* exts[] = {
"VK_KHR_surface",
"VK_KHR_xlib_surface"};
GLXContext(* glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const int32_t *)
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
const Acts::Surface * surface
virtual int32_t ExtInit()
void getSize(int32_t &width, int32_t &height) override
int32_t getVulkanSurface(void *instance, void *surface) override
void ToggleMaximized(bool set) override
uint32_t getReqVulkanExtensions(const char **&p) override
void SwitchFullscreen(bool set) override
void SetVSync(bool enable) override
const char * mFrontendName
void HandleKey(uint8_t key)
int32_t getDisplayControl() const override
void setDisplayControl(int32_t v) override
std::mutex mExitStateMutex
int32_t HandleUpdatesAndDrawGLScene(bool suspended=false)
void ResizeScene(int32_t width, int32_t height)
std::condition_variable mDisplayStoppedCV
static constexpr const char * DISPLAY_WINDOW_NAME
static constexpr int32_t INIT_WIDTH
static constexpr int32_t GL_MIN_VERSION_MAJOR
frontendTypes mFrontendType
void setWindowState(bool fullScreen, bool maximized)
GPUDisplayBackend * mBackend
static constexpr int32_t GL_MIN_VERSION_MINOR
int32_t InitDisplay(bool initFailure=false)
bool vsyncEnabled() const
GPUDisplayBackend * backend()
void applyInitialWindowState()
static constexpr int32_t MIN_WIDTH
static constexpr int32_t INIT_HEIGHT
bool consoleShown() const
static constexpr int32_t MIN_HEIGHT
std::atomic< bool > mDisplayRunning
GLint GLsizei GLsizei height
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum GLenum type
GLboolean GLboolean GLboolean GLboolean a
GLint GLint GLsizei GLint GLenum format
Marks an empty item in the context.