Project
Loading...
Searching...
No Matches
GPUDisplayFrontendWindows.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
16#include <cstdio>
17#include <cstdlib>
18#include <cstring>
22#include "GPULogging.h"
23#include <windows.h>
24#include <winbase.h>
25#include <windowsx.h>
26
27using namespace o2::gpu;
28
29HDC hDC = nullptr; // Private GDI Device Context
30HGLRC hRC = nullptr; // Permanent Rendering Context
31HWND hWnd = nullptr; // Holds Our Window Handle
32HINSTANCE hInstance; // Holds The Instance Of The Application
33LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
34
35bool active = TRUE; // Window Active Flag Set To TRUE By Default
36bool fullscreen = TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
37
39
40volatile int32_t mouseReset = false;
41
42void KillGLWindow() // Properly Kill The Window
43{
44 if (fullscreen) // Are We In Fullscreen Mode?
45 {
46 ChangeDisplaySettings(nullptr, 0); // If So Switch Back To The Desktop
47 ShowCursor(TRUE); // Show Mouse Pointer
48 }
49
50 if (hRC) // Do We Have A Rendering Context?
51 {
52 if (!wglMakeCurrent(nullptr, nullptr)) { // Are We Able To Release The DC And RC Contexts?
53 MessageBox(nullptr, "Release Of DC And RC Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
54 }
55
56 if (!wglDeleteContext(hRC)) { // Are We Able To Delete The RC?
57 MessageBox(nullptr, "Release Rendering Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
58 }
59 hRC = nullptr;
60 }
61
62 if (hDC && !ReleaseDC(hWnd, hDC)) // Are We Able To Release The DC
63 {
64 MessageBox(nullptr, "Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
65 hDC = nullptr;
66 }
67
68 if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
69 {
70 MessageBox(nullptr, "Could Not Release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
71 hWnd = nullptr;
72 }
73
74 if (!UnregisterClass("OpenGL", hInstance)) // Are We Able To Unregister Class
75 {
76 MessageBox(nullptr, "Could Not Unregister Class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
77 hInstance = nullptr;
78 }
79}
80
81BOOL CreateGLWindow(char* title, int32_t width, int32_t height, int32_t bits, bool fullscreenflag)
82{
83 GLuint PixelFormat; // Holds The Results After Searching For A Match
84 WNDCLASS wc; // Windows Class Structure
85 DWORD dwExStyle; // Window Extended Style
86 DWORD dwStyle; // Window Style
87 RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
88 WindowRect.left = (int64_t)0; // Set Left Value To 0
89 WindowRect.right = (int64_t)width; // Set Right Value To Requested Width
90 WindowRect.top = (int64_t)0; // Set Top Value To 0
91 WindowRect.bottom = (int64_t)height; // Set Bottom Value To Requested Height
92
93 fullscreen = fullscreenflag; // Set The Global Fullscreen Flag
94
95 hInstance = GetModuleHandle(nullptr); // Grab An Instance For Our Window
96 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
97 wc.lpfnWndProc = (WNDPROC)WndProc; // WndProc Handles Messages
98 wc.cbClsExtra = 0; // No Extra Window Data
99 wc.cbWndExtra = 0; // No Extra Window Data
100 wc.hInstance = hInstance; // Set The Instance
101 wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO); // Load The Default Icon
102 wc.hCursor = LoadCursor(nullptr, IDC_ARROW); // Load The Arrow Pointer
103 wc.hbrBackground = nullptr; // No Background Required For GL
104 wc.lpszMenuName = nullptr; // We Don't Want A Menu
105 wc.lpszClassName = "OpenGL"; // Set The Class Name
106
107 if (!RegisterClass(&wc)) // Attempt To Register The Window Class
108 {
109 MessageBox(nullptr, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
110 return FALSE; // Return FALSE
111 }
112
113 if (fullscreen) // Attempt Fullscreen Mode?
114 {
115 DEVMODE dmScreenSettings; // Device Mode
116 memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
117 dmScreenSettings.dmSize = sizeof(dmScreenSettings); // Size Of The Devmode Structure
118 dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
119 dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
120 dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
121 dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
122
123 if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
124 GPUError("The Requested Fullscreen Mode Is Not Supported By Your Video Card.");
125 return (FALSE);
126 }
127
128 dwExStyle = WS_EX_APPWINDOW;
129 dwStyle = WS_POPUP;
130 ShowCursor(FALSE);
131 } else {
132 dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
133 dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
134 }
135
136 AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);
137
138 // Create The Window
139 if (!(hWnd = CreateWindowEx(dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, nullptr, nullptr, hInstance, nullptr))) {
140 KillGLWindow();
141 MessageBox(nullptr, "Window Creation Error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
142 return FALSE;
143 }
144
145 static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
146 {
147 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
148 1, // Version Number
149 PFD_DRAW_TO_WINDOW | // Format Must Support Window
150 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
151 PFD_DOUBLEBUFFER, // Must Support Double Buffering
152 PFD_TYPE_RGBA, // Request An RGBA Format
153 (uint8_t)bits, // Select Our Color Depth
154 0,
155 0,
156 0,
157 0,
158 0,
159 0, // Color Bits Ignored
160 0, // No Alpha Buffer
161 0, // Shift Bit Ignored
162 0, // No Accumulation Buffer
163 0,
164 0,
165 0,
166 0, // Accumulation Bits Ignored
167 16, // 16Bit Z-Buffer (Depth Buffer)
168 0, // No Stencil Buffer
169 0, // No Auxiliary Buffer
170 PFD_MAIN_PLANE, // Main Drawing Layer
171 0, // Reserved
172 0,
173 0,
174 0 // Layer Masks Ignored
175 };
176
177 if (!(hDC = GetDC(hWnd))) // Did We Get A Device Context?
178 {
179 KillGLWindow();
180 MessageBox(nullptr, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
181 return FALSE;
182 }
183
184 if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) // Did Windows Find A Matching Pixel Format?
185 {
186 KillGLWindow();
187 MessageBox(nullptr, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
188 return FALSE;
189 }
190
191 if (!SetPixelFormat(hDC, PixelFormat, &pfd)) // Are We Able To Set The Pixel Format?
192 {
193 KillGLWindow();
194 MessageBox(nullptr, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
195 return FALSE;
196 }
197
198 if (!(hRC = wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
199 {
200 KillGLWindow();
201 MessageBox(nullptr, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
202 return FALSE;
203 }
204
205 if (!wglMakeCurrent(hDC, hRC)) // Try To Activate The Rendering Context
206 {
207 KillGLWindow();
208 MessageBox(nullptr, "Can't Activate The GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
209 return FALSE;
210 }
211
212 ShowWindow(hWnd, SW_SHOW);
213 SetForegroundWindow(hWnd);
214 SetFocus(hWnd);
215 ResizeScene(width, height);
216
217 return TRUE;
218}
219
221{
222 if (key == VK_BACK) {
223 return (GPUDisplayFrontendKeyVars::KEY_BACKSPACE);
224 }
225 if (key == VK_DELETE) {
226 return (GPUDisplayFrontendKeyVars::KEY_DELETE);
227 }
228 if (key == 107 || key == 187) {
229 return ('+');
230 }
231 if (key == 109 || key == 189) {
232 return ('-');
233 }
234 if (key >= 'a' && key <= 'z') {
235 key += 'A' - 'a';
236 }
237
238 return (key);
239}
240
241LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
242{
243 switch (uMsg) // Check For Windows Messages
244 {
245 case WM_ACTIVATE: // Watch For Window Activate Message, check minimization state
246 if (!HIWORD(wParam)) {
247 active = TRUE;
248 } else {
249 active = FALSE;
250 }
251 return 0;
252
253 case WM_SYSCOMMAND: // Intercept System Commands
254 switch (wParam) // Check System Calls
255 {
256 case SC_SCREENSAVE: // Screensaver Trying To Start?
257 case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
258 return 0; // Prevent From Happening
259 }
260 break; // Exit
261
262 case WM_CLOSE: // Did We Receive A Close Message?
263 PostQuitMessage(0);
264 return 0;
265
266 case WM_KEYDOWN: // Is A Key Being Held Down?
267 wParam = ((lParam >> 16) & 0xFF) == 0x29 ? '^' : GetKey(wParam); // Scan code of the key left of 1: console key, independent of the layout
268 mKeys[wParam] = wParam == KEY_SHIFT || !consoleShown(); // Held keys only without console, SHIFT also with it (scrolling)
269 HandleKey(wParam);
270 return 0;
271
272 case WM_KEYUP:
273 wParam = ((lParam >> 16) & 0xFF) == 0x29 ? '^' : GetKey(wParam);
274 mKeys[wParam] = false;
275 GPUInfo("Key: %d", wParam);
276 return 0;
277
278 case WM_SIZE:
279 ResizeScene(LOWORD(lParam), HIWORD(lParam)); // LoWord=Width, HiWord=Height
280 return 0;
281
282 case WM_LBUTTONDOWN:
283 mMouseDnX = GET_X_LPARAM(lParam);
284 mMouseDnY = GET_Y_LPARAM(lParam);
285 mMouseDn = true;
286 GetCursorPos(&mouseCursorPos);
287 return 0;
288
289 case WM_LBUTTONUP:
290 mMouseDn = false;
291 return 0;
292
293 case WM_RBUTTONDOWN:
294 mMouseDnX = GET_X_LPARAM(lParam);
295 mMouseDnY = GET_Y_LPARAM(lParam);
296 mMouseDnR = true;
297 GetCursorPos(&mouseCursorPos);
298 return 0;
299
300 case WM_RBUTTONUP:
301 mMouseDnR = false;
302 return 0;
303
304 case WM_MBUTTONDOWN:
305 mMouseDnX = GET_X_LPARAM(lParam);
306 mMouseDnY = GET_Y_LPARAM(lParam);
307 mMouseDnM = true;
308 GetCursorPos(&mouseCursorPos);
309 return 0;
310
311 case WM_MBUTTONUP:
312 mMouseDnM = false;
313 return 0;
314
315 case WM_MOUSEMOVE:
316 if (mouseReset) {
317 mMouseDnX = GET_X_LPARAM(lParam);
318 mMouseDnY = GET_Y_LPARAM(lParam);
319 mouseReset = 0;
320 }
321 mMouseMvX = GET_X_LPARAM(lParam);
322 mMouseMvY = GET_Y_LPARAM(lParam);
323 return 0;
324
325 case WM_MOUSEWHEEL:
326 mMouseWheel += GET_WHEEL_DELTA_WPARAM(wParam);
327 return 0;
328 }
329
330 // Pass All Unhandled Messages To DefWindowProc
331 return DefWindowProc(hWnd, uMsg, wParam, lParam);
332}
333
339
340int32_t GPUDisplayFrontendWindows::FrontendMain()
341{
342 MSG msg;
343 BOOL done = FALSE;
344 fullscreen = FALSE;
345
346 if (glewInit()) {
347 return (-1);
348 }
349
351 return -1;
352 }
353
354 if (InitDisplay()) {
355 KillGLWindow();
356 GPUError("Initialization Failed.");
357 return 1;
358 }
359
360 while (!done) {
361 if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) // Is There A Message Waiting?
362 {
363 if (msg.message == WM_QUIT) {
364 done = TRUE;
365 } else {
366 TranslateMessage(&msg); // Translate The Message
367 DispatchMessage(&msg); // Dispatch The Message
368 }
369 } else {
370 if (getDisplayControl() == 2) { // Quit key / StopDisplay
371 done = TRUE;
372 } else {
373 HandleUpdatesAndDrawGLScene(!active); // Only draw if the program is active
374 if (active) {
375 SwapBuffers(hDC); // Swap Buffers (Double Buffering)
377 }
378 }
379 }
380 }
381
382 // Shutdown
383 ExitDisplay();
384 KillGLWindow();
385 return (0);
386}
387
388void SwitchFullscreen(bool set) {}
389void ToggleMaximized(bool set) {}
390void SetVSync(bool enable) {}
BOOL CreateGLWindow(char *title, int32_t width, int32_t height, int32_t bits, bool fullscreenflag)
POINT mouseCursorPos
HINSTANCE hInstance
void SetVSync(bool enable)
volatile int32_t mouseReset
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
void SwitchFullscreen(bool set)
void KillGLWindow()
int32_t GetKey(int32_t key)
void ToggleMaximized(bool set)
bool done
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
int32_t getDisplayControl() const override
int32_t HandleUpdatesAndDrawGLScene(bool suspended=false)
static constexpr const char * DISPLAY_WINDOW_NAME
static constexpr int32_t INIT_WIDTH
int32_t InitDisplay(bool initFailure=false)
static constexpr int32_t INIT_HEIGHT
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint GLsizei width
Definition glcorearb.h:270
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
Definition glcorearb.h:4150
uint64_t const void const *restrict const msg
Definition x9.h:153