Project
Loading...
Searching...
No Matches
GPUDisplayFrontendGlut.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15// Now the other headers
19#include "GPULogging.h"
20#include <cstdio>
21#include <chrono>
22#include <cstring>
23#include <GL/freeglut.h>
24#include <GL/freeglut_ucall.h>
25#include <unistd.h>
26#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
27#include <GL/glx.h>
28#include <GL/glxext.h>
29#include <X11/Xatom.h>
30#endif
31
32using namespace o2::gpu;
33
39
40void GPUDisplayFrontendGlut::displayFunc()
41{
42 mRedisplayPending = false;
44 glutSwapBuffers();
46}
47
48void GPUDisplayFrontendGlut::glutLoopFunc()
49{
50 if (mRedisplayPending) { // Last redisplay not served (window not visible): handle updates without drawing
52 std::unique_lock lock(mConfigUpdateMutex); // No swap waiting for VSync: block instead of spinning, woken by GUI updates
53 mConfigUpdateCV.wait_for(lock, std::chrono::milliseconds(100), [this] { return mConfigUpdatePending; });
54 }
55 mRedisplayPending = true;
56 glutPostRedisplay(); // Drawing only in displayFunc, so that expose events do not draw twice
57}
58
59int32_t GPUDisplayFrontendGlut::GetKey(int32_t key)
60{
61 switch (key) {
62 case GLUT_KEY_UP:
63 return KEY_UP;
64 case GLUT_KEY_DOWN:
65 return KEY_DOWN;
66 case GLUT_KEY_LEFT:
67 return KEY_LEFT;
68 case GLUT_KEY_RIGHT:
69 return KEY_RIGHT;
70 case GLUT_KEY_PAGE_UP:
71 return KEY_PAGEUP;
72 case GLUT_KEY_PAGE_DOWN:
73 return KEY_PAGEDOWN;
74 case GLUT_KEY_HOME:
75 return KEY_HOME;
76 case GLUT_KEY_END:
77 return KEY_END;
78 case GLUT_KEY_INSERT:
79 return KEY_INSERT;
80 case GLUT_KEY_F1:
81 return KEY_F1;
82 case GLUT_KEY_F2:
83 return KEY_F2;
84 case GLUT_KEY_F3:
85 return KEY_F3;
86 case GLUT_KEY_F4:
87 return KEY_F4;
88 case GLUT_KEY_F5:
89 return KEY_F5;
90 case GLUT_KEY_F6:
91 return KEY_F6;
92 case GLUT_KEY_F7:
93 return KEY_F7;
94 case GLUT_KEY_F8:
95 return KEY_F8;
96 case GLUT_KEY_F9:
97 return KEY_F9;
98 case GLUT_KEY_F10:
99 return KEY_F10;
100 case GLUT_KEY_F11:
101 return KEY_F11;
102 case GLUT_KEY_F12:
103 return KEY_F12;
104 case GLUT_KEY_SHIFT_L:
105 case GLUT_KEY_SHIFT_R:
106 return KEY_SHIFT;
107 case GLUT_KEY_CTRL_L:
108 return KEY_CTRL;
109 case GLUT_KEY_CTRL_R:
110 return KEY_RCTRL;
111 case GLUT_KEY_ALT_L:
112 return KEY_ALT;
113 case GLUT_KEY_ALT_R:
114 return KEY_RALT;
115 default:
116 return 0;
117 }
118}
119
120void GPUDisplayFrontendGlut::GetKey(int32_t key, int32_t& keyOut, int32_t& keyPressOut, bool special)
121{
122 int32_t specialKey = special ? GetKey(key) : 0;
123 // GPUInfo("Key: key %d (%c) (special %d) -> %d (%c) special %d (%c)", key, (char) key, (int32_t) special, (int32_t) key, key, specialKey, (char) specialKey);
124
125 if (specialKey) {
126 keyOut = keyPressOut = specialKey;
127 } else {
128 keyOut = keyPressOut = key == 8 ? KEY_BACKSPACE : (key == 127 ? KEY_DELETE : key); // Otherwise 8 = KEY_SHIFT
129 if (keyPressOut >= 'a' && keyPressOut <= 'z') {
130 keyPressOut += 'A' - 'a';
131 }
132 }
133}
134
135void GPUDisplayFrontendGlut::keyboardFunc(int32_t key, bool special, bool down)
136{
137 int32_t handleKey = 0, keyPress = 0;
138 GetKey(key, handleKey, keyPress, special);
139 mKeys[keyPress] = down && (keyPress == KEY_SHIFT || !consoleShown()); // Held keys only without console, SHIFT also with it (scrolling)
140 if (down) {
141 HandleKey(handleKey);
142 }
143}
144
145void GPUDisplayFrontendGlut::ResizeSceneWrapper(int32_t width, int32_t height)
146{
147 if (!mFullScreen) {
148 mWidth = width;
149 mHeight = height;
150 }
152#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
153 Display* display = glXGetCurrentDisplay(); // Maximizing / unmaximizing by the window manager changes the size, read the state as freeglut does not report it (fullscreen stays as requested, freeglut tracks it itself)
154 Atom type;
156 unsigned long nItems, bytesAfter;
157 unsigned char* data = nullptr;
158 if (!display || XGetWindowProperty(display, glXGetCurrentDrawable(), XInternAtom(display, "_NET_WM_STATE", False), 0, 1024, False, XA_ATOM, &type, &format, &nItems, &bytesAfter, &data) != Success || data == nullptr) {
159 return;
160 }
161 const Atom maxHorz = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False), maxVert = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
162 bool isMaxHorz = false, isMaxVert = false;
163 for (unsigned long i = 0; i < nItems; i++) {
164 isMaxHorz |= ((Atom*)data)[i] == maxHorz;
165 isMaxVert |= ((Atom*)data)[i] == maxVert;
166 }
167 XFree(data);
168 setWindowState(mFullScreen, isMaxHorz && isMaxVert);
169#endif
170}
171
172void GPUDisplayFrontendGlut::mouseFunc(int32_t button, int32_t state, int32_t x, int32_t y)
173{
174 if (button == 3) {
175 mMouseWheel += 100;
176 } else if (button == 4) {
177 mMouseWheel -= 100;
178 } else if (state == GLUT_DOWN) {
179 if (button == GLUT_LEFT_BUTTON) {
180 mMouseDn = true;
181 } else if (button == GLUT_RIGHT_BUTTON) {
182 mMouseDnR = true;
183 } else if (button == GLUT_MIDDLE_BUTTON) {
184 mMouseDnM = true;
185 }
186 mMouseDnX = x;
187 mMouseDnY = y;
188 } else if (state == GLUT_UP) {
189 if (button == GLUT_LEFT_BUTTON) {
190 mMouseDn = false;
191 } else if (button == GLUT_RIGHT_BUTTON) {
192 mMouseDnR = false;
193 } else if (button == GLUT_MIDDLE_BUTTON) {
194 mMouseDnM = false;
195 }
196 }
197}
198
199void GPUDisplayFrontendGlut::mouseMoveFunc(int32_t x, int32_t y)
200{
201 mMouseMvX = x;
202 mMouseMvY = y;
203}
204
205void GPUDisplayFrontendGlut::mMouseWheelFunc(int32_t button, int32_t dir, int32_t x, int32_t y) { mMouseWheel += dir; }
206
207int32_t GPUDisplayFrontendGlut::FrontendMain()
208{
209 if (backend()->backendType() != GPUDisplayBackend::TYPE_OPENGL) {
210 fprintf(stderr, "Only OpenGL backend supported\n");
211 return 1;
212 }
213 if (drawTextFontSize() == 0) {
214 drawTextFontSize() = 12;
215 }
216
217 int32_t nopts = 2;
218 char opt1[] = "progname";
219 char opt2[] = "-direct";
220 char* opts[] = {opt1, opt2};
221 glutInit(&nopts, opts);
222 glutInitContextVersion(GL_MIN_VERSION_MAJOR, GL_MIN_VERSION_MINOR);
223 glutInitContextProfile(GLUT_CORE_PROFILE);
224 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
225 glutInitWindowSize(INIT_WIDTH, INIT_HEIGHT);
226 glutCreateWindow(DISPLAY_WINDOW_NAME);
227 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
228
229 if (mBackend->ExtInit()) {
230 fprintf(stderr, "Error initializing GL extension wrapper\n");
231 return (-1);
232 }
233 auto mouseMoveFunc = [](int32_t x, int32_t y, void* p) { self(p)->mouseMoveFunc(x, y); };
234 glutDisplayFuncUcall([](void* p) { self(p)->displayFunc(); }, this); // Callbacks with this as user data, freeglut >= 3.2
235 glutIdleFuncUcall([](void* p) { self(p)->glutLoopFunc(); }, this);
236 glutReshapeFuncUcall([](int32_t width, int32_t height, void* p) { self(p)->ResizeSceneWrapper(width, height); }, this);
237 glutKeyboardFuncUcall([](uint8_t key, int32_t x, int32_t y, void* p) { self(p)->keyboardFunc(key, false, true); }, this);
238 glutKeyboardUpFuncUcall([](uint8_t key, int32_t x, int32_t y, void* p) { self(p)->keyboardFunc(key, false, false); }, this);
239 glutSpecialFuncUcall([](int32_t key, int32_t x, int32_t y, void* p) { self(p)->keyboardFunc(key, true, true); }, this);
240 glutSpecialUpFuncUcall([](int32_t key, int32_t x, int32_t y, void* p) { self(p)->keyboardFunc(key, true, false); }, this);
241 glutMouseFuncUcall([](int32_t button, int32_t state, int32_t x, int32_t y, void* p) { self(p)->mouseFunc(button, state, x, y); }, this);
242 glutMotionFuncUcall(mouseMoveFunc, this);
243 glutPassiveMotionFuncUcall(mouseMoveFunc, this);
244 glutMouseWheelFuncUcall([](int32_t button, int32_t dir, int32_t x, int32_t y, void* p) { self(p)->mMouseWheelFunc(button, dir, x, y); }, this);
247
248 if (InitDisplay()) {
249 fprintf(stderr, "Error in OpenGL initialization\n");
250 return (1);
251 }
252 glutMainLoop();
253 {
254 std::lock_guard lock(mExitStateMutex);
256 mDisplayRunning = false;
257 mDisplayStoppedCV.notify_all();
258 }
259
260 ExitDisplay();
261 return 0;
262}
263
265{
266 glutLeaveMainLoop();
267}
268
270{
271 mFullScreen = set;
272 if (set) {
273 glutFullScreen();
274 } else {
275 glutReshapeWindow(mWidth, mHeight);
276 }
277}
278
279void GPUDisplayFrontendGlut::ToggleMaximized(bool set) // GLUT has no API for maximizing, request it from the window manager via GLX / X11 directly (no-op if freeglut does not use GLX)
280{
281#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
282 Display* display = glXGetCurrentDisplay();
283 if (!display) {
284 return;
285 }
286 XEvent xev;
287 memset(&xev, 0, sizeof(xev));
288 xev.type = ClientMessage;
289 xev.xclient.window = glXGetCurrentDrawable(); // freeglut renders directly to the X window
290 xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False);
291 xev.xclient.format = 32;
292 xev.xclient.data.l[0] = set ? 1 : 0; // _NET_WM_STATE_ADD / _NET_WM_STATE_REMOVE
293 xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
294 xev.xclient.data.l[2] = XInternAtom(display, "_NET_WM_STATE_MAXIMIZED_VERT", False);
295 XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
296 XFlush(display);
297#endif
298}
299
300void GPUDisplayFrontendGlut::SetVSync(bool enable) // GLUT has no swap interval API, set it via GLX directly (no-op if freeglut does not use GLX)
301{
302#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
303 if (canSetVSync()) {
304 ((PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT"))(glXGetCurrentDisplay(), glXGetCurrentDrawable(), enable);
305 }
306#endif
307}
308
310{
311#ifdef GPUCA_BUILD_EVENT_DISPLAY_X11
312 return glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT") && glXGetCurrentDisplay();
313#else
314 return false;
315#endif
316}
int32_t i
int32_t GetKey(int32_t key)
configStandalone display
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
StringRef key
void setDisplayControl(int32_t v) override
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
void setWindowState(bool fullScreen, bool maximized)
static constexpr int32_t GL_MIN_VERSION_MINOR
int32_t InitDisplay(bool initFailure=false)
std::condition_variable mConfigUpdateCV
static constexpr int32_t INIT_HEIGHT
std::atomic< bool > mDisplayRunning
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint GLsizei width
Definition glcorearb.h:270
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean enable
Definition glcorearb.h:3991
GLint GLint GLsizei GLint GLenum format
Definition glcorearb.h:275