Project
Loading...
Searching...
No Matches
GPUDisplay.h
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#ifndef GPUDISPLAY_H
16#define GPUDISPLAY_H
17
20#include "GPUDisplayInterface.h"
21#include "GPUSettings.h"
23
24#include <array>
25#include <mutex>
26#include <condition_variable>
27
28union hmm_mat4; // From HandMadeMath
29
30#include "utils/timer.h"
31#include "utils/vecpod.h"
32#include "utils/qsem.h"
33
34namespace o2::gpu
35{
36class GPUTPCTracker;
37struct GPUParam;
38class GPUQA;
39class GPUTRDGeometry;
40class GPUTPCGMPropagator;
41
43{
44 friend class GPUDisplayFrontend;
45
46 public:
47 GPUDisplay(GPUDisplayFrontend* frontend, GPUChainTracking* chain, GPUQA* qa, const GPUParam* param = nullptr, const GPUCalibObjectsConst* calib = nullptr, const GPUSettingsDisplay* config = nullptr, const GPUSettingsProcessing* proc = nullptr);
48 GPUDisplay(const GPUDisplay&) = delete;
49 ~GPUDisplay() override = default;
50
51 int32_t StartDisplay() override;
52 void ExitDisplay();
53 void ShowNextEvent(const GPUTrackingInOutPointers* ptrs = nullptr) override;
54 void BlockTillNextEvent() override;
55 void UnblockDisplay();
56 void WaitTillEventShown() override;
57 void SetCollisionFirstCluster(uint32_t collision, int32_t sector, int32_t cluster) override;
58 void UpdateCalib(const GPUCalibObjectsConst* calib) override { mCalib = calib; }
59 void UpdateParam(const GPUParam* param) override { mParam = param; }
60
61 void HandleKey(uint8_t key, bool doNotHandleConfigChanges = false); // With doNotHandleConfigChanges, the caller must call checkAndApplyConfigChanges
62 int32_t DrawGLScene();
63 void HandleExternalGUIKey(int32_t key); // Does not handle config changes, see HandleKey
64 int32_t InitDisplay(bool initFailure = false);
65 void ResizeScene(int32_t width, int32_t height, bool init = false);
66 void checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy& oldCfgH, const GPUSettingsDisplayLight& oldCfgL, const GPUSettingsDisplayRenderer& oldCfgR); // Set update flags / apply the settings that changed compared to the old copies
67
68 const GPUSettingsDisplayRenderer& cfgR() const { return mCfgR; }
69 const GPUSettingsDisplayLight& cfgL() const { return mCfgL; }
70 const GPUSettingsDisplayHeavy& cfgH() const { return mCfgH; }
71 const GPUSettingsDisplay& cfg() const { return mConfig; }
72 bool useMultiVBO() const { return mUseMultiVBO; }
73 int32_t updateDrawCommands() const { return mUpdateDrawCommands; }
74 int32_t updateRenderPipeline() const { return mUpdateRenderPipeline; }
75 GPUDisplayBackend* backend() const { return mBackend.get(); }
76 vecpod<int32_t>* vertexBufferStart() { return mVertexBufferStart; }
77 const vecpod<uint32_t>* vertexBufferCount() const { return mVertexBufferCount; }
78 struct vtx {
79 float x, y, z;
80 vtx(float a, float b, float c) : x(a), y(b), z(c) {}
81 };
82 vecpod<vtx>* vertexBuffer() { return mVertexBuffer; }
83 const GPUParam* param() { return mParam; }
84 const GPUSettingsProcessing& GetProcessingSettings() const { return mProcessingSettings; }
85 GPUDisplayFrontend* frontend() { return mFrontend; }
86 bool drawTextInCompatMode() const { return mDrawTextInCompatMode; }
87 int32_t& drawTextFontSize() { return mDrawTextFontSize; }
88
89 private:
90 static constexpr int32_t NSECTORS = o2::tpc::constants::MAXSECTOR;
91 static constexpr float GL_SCALE_FACTOR = (1.f / 100.f);
92
93 static constexpr const int32_t N_POINTS_TYPE = 15;
94 static constexpr const int32_t N_POINTS_TYPE_TPC = 9;
95 static constexpr const int32_t N_POINTS_TYPE_TRD = 2;
96 static constexpr const int32_t N_POINTS_TYPE_TOF = 2;
97 static constexpr const int32_t N_POINTS_TYPE_ITS = 2;
98 static constexpr const int32_t N_LINES_TYPE = 7;
99 static constexpr const int32_t N_FINAL_TYPE = 4;
100 static constexpr int32_t TRACK_TYPE_ID_LIMIT = 100;
101 enum PointTypes { tCLUSTER = 0,
102 tINITLINK = 1,
103 tLINK = 2,
104 tSEED = 3,
105 tTRACKLET = 4,
106 tSECTORTRACK = 5,
107 tEXTRAPOLATEDTRACK = 6,
108 tFINALTRACK = 7,
109 tMARKED = 8,
110 tTRDCLUSTER = 9,
111 tTRDATTACHED = 10,
112 tTOFCLUSTER = 11,
113 tTOFATTACHED = 12,
114 tITSCLUSTER = 13,
115 tITSATTACHED = 14 };
116 enum LineTypes { RESERVED = 0 /*1 -- 6 = INITLINK to GLOBALTRACK*/ };
117
118 using vboList = GPUDisplayBackend::vboList;
119
120 struct threadVertexBuffer {
122 vecpod<int32_t> start[N_FINAL_TYPE];
123 vecpod<uint32_t> count[N_FINAL_TYPE];
124 std::pair<vecpod<int32_t>*, vecpod<uint32_t>*> vBuf[N_FINAL_TYPE];
125 threadVertexBuffer() : buffer()
126 {
127 for (int32_t i = 0; i < N_FINAL_TYPE; i++) {
128 vBuf[i].first = start + i;
129 vBuf[i].second = count + i;
130 }
131 }
132 void clear()
133 {
134 for (int32_t i = 0; i < N_FINAL_TYPE; i++) {
135 start[i].clear();
136 count[i].clear();
137 }
138 }
139 };
140
141 class opengl_spline
142 {
143 public:
144 opengl_spline() : ma(), mb(), mc(), md(), mx() {}
145 void create(const vecpod<float>& x, const vecpod<float>& y);
146 float evaluate(float x);
147 void setVerbose() { mVerbose = true; }
148
149 private:
150 vecpod<float> ma, mb, mc, md, mx;
151 bool mVerbose = false;
152 };
153
154 static const GPUSettingsDisplay& GetConfig(GPUChainTracking* chain);
155 static const GPUSettingsProcessing& GetProcessingConfig(GPUChainTracking* chain);
156
157 void DrawGLScene_internal(float animateTime = -1.f, bool renderToMixBuffer = false);
158 void DrawGLScene_updateEventData();
159 void DrawGLScene_cameraAndAnimation(float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
160 size_t DrawGLScene_updateVertexList();
161 void DrawGLScene_drawCommands();
162 int32_t InitDisplay_internal();
163 int32_t getNumThreads();
164 void updateOptions();
165 void disableUnsupportedOptions();
166 int32_t buildTrackFilter();
167 const GPUTPCTracker& sectorTracker(int32_t iSector);
168 const GPUTRDGeometry* trdGeometry();
169 const GPUTrackingInOutPointers* mIOPtrs = nullptr;
170 void insertVertexList(std::pair<vecpod<int32_t>*, vecpod<uint32_t>*>& vBuf, size_t first, size_t last);
171 void insertVertexList(int32_t iSector, size_t first, size_t last);
172 template <typename... Args>
173 void SetInfo(Args... args);
174 void PrintGLHelpText(float colorValue);
175 void calcXYZ(const float*);
176 void mAnimationCloseAngle(float& newangle, float lastAngle);
177 void mAnimateCloseQuaternion(float* v, float lastx, float lasty, float lastz, float lastw);
178 void setAnimationPoint();
179 void resetAnimation();
180 void removeAnimationPoint();
181 void startAnimation();
182 int32_t animateCamera(float& animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
183 void showInfo(const char* info);
184 void ActivateColor();
185 void SetColorTRD();
186 void SetColorTOF();
187 void SetColorITS();
188 void SetColorClusters();
189 void SetColorInitLinks();
190 void SetColorLinks();
191 void SetColorSeeds();
192 void SetColorTracklets();
193 void SetColorTracks();
194 void SetColorExtrapolatedTracks();
195 void SetColorFinal();
196 void SetColorGrid();
197 void SetColorGridTRD();
198 void SetColorMarked();
199 void SetCollisionColor(int32_t col);
200 void updateConfig();
201 void drawPointLinestrip(int32_t iSector, int32_t cid, int32_t id, int32_t id_limit = TRACK_TYPE_ID_LIMIT);
202 void DrawClusters(int32_t iSector);
203 vboList DrawSpacePointsTRD(int32_t iSector, int32_t select, int32_t iCol);
204 vboList DrawSpacePointsTOF(int32_t iSector, int32_t select, int32_t iCol);
205 vboList DrawSpacePointsITS(int32_t iSector, int32_t select, int32_t iCol);
206 vboList DrawLinks(const GPUTPCTracker& tracker, int32_t id, bool dodown = false);
207 vboList DrawSeeds(const GPUTPCTracker& tracker);
208 vboList DrawTracklets(const GPUTPCTracker& tracker);
209 vboList DrawTracks(const GPUTPCTracker& tracker, int32_t global);
210 void DrawTrackITS(int32_t trackId, int32_t iSector);
211 GPUDisplay::vboList DrawFinalITS();
212 template <class T>
213 void DrawFinal(int32_t iSector, int32_t /*iCol*/, const GPUTPCGMPropagator* prop, std::array<vecpod<int32_t>, 2>& trackList, threadVertexBuffer& threadBuffer);
214 vboList DrawGrid(const GPUTPCTracker& tracker);
215 vboList DrawGridTRD(int32_t sector);
216 void DoScreenshot(const char* filename, std::vector<char>& pixels, float animateTime = -1.f);
217 void PrintHelp();
218 void createQuaternionFromMatrix(float* v, const float* mat);
219 void drawVertices(const vboList& v, const GPUDisplayBackend::drawType t);
220 void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true);
221
222 GPUDisplayFrontend* mFrontend = nullptr;
223 std::unique_ptr<GPUDisplayBackend> mBackend;
224 GPUChainTracking* mChain = nullptr;
225 const GPUParam* mParam = nullptr;
226 const GPUCalibObjectsConst* mCalib = nullptr;
227 const GPUSettingsDisplay& mConfig;
228 GPUSettingsDisplayLight mCfgL;
229 GPUSettingsDisplayHeavy mCfgH;
230 GPUSettingsDisplayRenderer mCfgR;
231 const GPUSettingsProcessing& mProcessingSettings;
232 GPUQA* mQA;
233
234 qSem mSemLockDisplay;
235 std::mutex mMutexLoadAndShowEvent;
236 std::condition_variable mCVLoadAndShowEvent;
237
238 bool mDrawTextInCompatMode = false;
239 int32_t mDrawTextFontSize = 0;
240
241 int32_t mNDrawCalls = 0;
242
243 bool mUseMultiVBO = false;
244
245 std::array<float, 4> mDrawColor = {1.f, 1.f, 1.f, 1.f};
246
247 int32_t mTestSetting = 0;
248
249 float mAngleRollOrigin = -1e9;
250 float mMaxClusterZ = -1;
251
252 std::unique_ptr<hmm_mat4> mViewMatrix, mModelMatrix;
253 float mXYZ[3];
254 float mAngle[3];
255 float mRPhiTheta[3];
256 float mQuat[4];
257
258 vecpod<std::array<int32_t, 37>> mOverlayTFClusters;
259 int32_t mNCollissions = 1;
260
261 vecpod<vtx> mVertexBuffer[NSECTORS];
262 vecpod<int32_t> mVertexBufferStart[NSECTORS];
263 vecpod<uint32_t> mVertexBufferCount[NSECTORS];
264 std::vector<std::array<uint32_t, N_POINTS_TYPE_TPC>> mClusterBufferSizeCache[NSECTORS];
265
266 std::unique_ptr<float4[]> mGlobalPosPtr;
267 std::unique_ptr<float4[]> mGlobalPosPtrTRD;
268 std::unique_ptr<float4[]> mGlobalPosPtrTRD2;
269 std::unique_ptr<float4[]> mGlobalPosPtrITS;
270 std::unique_ptr<float4[]> mGlobalPosPtrTOF;
271 float4* mGlobalPos;
272 float4* mGlobalPosTRD;
273 float4* mGlobalPosTRD2;
274 float4* mGlobalPosITS;
275 float4* mGlobalPosTOF;
276 int32_t mNMaxClusters = 0;
277 int32_t mNMaxSpacePointsTRD = 0;
278 int32_t mNMaxClustersITS = 0;
279 int32_t mNMaxClustersTOF = 0;
280 int32_t mCurrentClusters = 0;
281 int32_t mCurrentSpacePointsTRD = 0;
282 int32_t mCurrentClustersITS = 0;
283 int32_t mCurrentClustersTOF = 0;
284 vecpod<int32_t> mTRDTrackIds;
285 vecpod<bool> mITSStandaloneTracks;
286 std::vector<bool> mTrackFilter;
287
288 volatile bool mUpdateTrackFilter = false;
289 volatile bool mUpdateVertexLists = true;
290 volatile bool mUpdateEventData = false;
291 volatile bool mUpdateDrawCommands = true;
292 volatile bool mUpdateRenderPipeline = false;
293 volatile bool mResetScene = false;
294 volatile bool mLoadAndShowEvent = false;
295 bool mTracksArePropagated = false;
296
297 int32_t mAnimate = 0;
298 HighResTimer mAnimationTimer;
299 int32_t mAnimationFrame = 0;
300 int32_t mAnimationLastBase = 0;
301 int32_t mAnimationMixBase = -1; // Target keyframe of the current config blend (mixing), -1 = none
302 int32_t mAnimateScreenshot = 0;
303 int32_t mAnimationExport = 0;
304 bool mAnimationChangeConfig = true;
305 float mAnimationDelay = 2.f;
306 vecpod<float> mAnimateVectors[9];
307 vecpod<GPUSettingsDisplayLight> mAnimateConfig;
308 opengl_spline mAnimationSplines[8];
309
310 int32_t mPrintInfoText = 1;
311 bool mPrintInfoTextAlways = 0;
312 char mInfoText2[1024];
313 HighResTimer mInfoText2Timer, mInfoHelpTimer;
314
315 std::vector<threadVertexBuffer> mThreadBuffers;
316 std::vector<std::vector<std::array<std::array<vecpod<int32_t>, 2>, NSECTORS>>> mThreadTracks;
317 volatile int32_t mInitResult = 0;
318
319 float mFPSScale = 1, mFPSScaleadjust = 0;
320 int32_t mFramesDone = 0, mFramesDoneFPS = 0;
321 HighResTimer mTimerFPS;
322 vboList mGlDLLines[NSECTORS][N_LINES_TYPE];
323 vecpod<std::array<vboList, N_FINAL_TYPE>> mGlDLFinal[NSECTORS];
324 vboList mGlDLFinalITS;
325 vecpod<vboList> mGlDLPoints[NSECTORS][N_POINTS_TYPE];
326 vboList mGlDLGrid[NSECTORS];
327 vboList mGlDLGridTRD[NSECTORS / 2];
328
329 bool mRequestScreenshot = false;
330 std::string mScreenshotFile;
331
332 float mYFactor = 1.0f;
333};
334} // namespace o2::gpu
335
336#endif
int32_t i
uint32_t iSector
GPUChain * chain
uint32_t col
Definition RawData.h:4
uint32_t c
Definition RawData.h:2
StringRef key
std::tuple< uint32_t, uint32_t, int32_t > vboList
const GPUSettingsDisplayLight & cfgL() const
Definition GPUDisplay.h:69
void SetCollisionFirstCluster(uint32_t collision, int32_t sector, int32_t cluster) override
const GPUParam * param()
Definition GPUDisplay.h:83
void checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy &oldCfgH, const GPUSettingsDisplayLight &oldCfgL, const GPUSettingsDisplayRenderer &oldCfgR)
const GPUSettingsDisplayHeavy & cfgH() const
Definition GPUDisplay.h:70
~GPUDisplay() override=default
int32_t updateRenderPipeline() const
Definition GPUDisplay.h:74
void UpdateCalib(const GPUCalibObjectsConst *calib) override
Definition GPUDisplay.h:58
const GPUSettingsDisplayRenderer & cfgR() const
Definition GPUDisplay.h:68
friend class GPUDisplayFrontend
Definition GPUDisplay.h:44
vecpod< vtx > * vertexBuffer()
Definition GPUDisplay.h:82
GPUDisplay(const GPUDisplay &)=delete
int32_t StartDisplay() override
bool drawTextInCompatMode() const
Definition GPUDisplay.h:86
int32_t & drawTextFontSize()
Definition GPUDisplay.h:87
void UpdateParam(const GPUParam *param) override
Definition GPUDisplay.h:59
int32_t updateDrawCommands() const
Definition GPUDisplay.h:73
GPUDisplayFrontend * frontend()
Definition GPUDisplay.h:85
void HandleExternalGUIKey(int32_t key)
const vecpod< uint32_t > * vertexBufferCount() const
Definition GPUDisplay.h:77
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:71
void BlockTillNextEvent() override
void HandleKey(uint8_t key, bool doNotHandleConfigChanges=false)
int32_t InitDisplay(bool initFailure=false)
bool useMultiVBO() const
Definition GPUDisplay.h:72
void ShowNextEvent(const GPUTrackingInOutPointers *ptrs=nullptr) override
vecpod< int32_t > * vertexBufferStart()
Definition GPUDisplay.h:76
GPUDisplayBackend * backend() const
Definition GPUDisplay.h:75
void WaitTillEventShown() override
void ResizeScene(int32_t width, int32_t height, bool init=false)
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUDisplay.h:84
Definition qsem.h:25
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLsizei count
Definition glcorearb.h:399
GLuint buffer
Definition glcorearb.h:655
const GLdouble * v
Definition glcorearb.h:832
GLint GLsizei GLsizei height
Definition glcorearb.h:270
GLint first
Definition glcorearb.h:399
GLint GLsizei width
Definition glcorearb.h:270
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLboolean GLboolean g
Definition glcorearb.h:1233
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
GLboolean r
Definition glcorearb.h:1233
GLuint start
Definition glcorearb.h:469
GLenum GLfloat param
Definition glcorearb.h:271
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
ConcreteParserVariants< PageSize, BOUNDS_CHECKS > create(T const *buffer, size_t size)
create a raw parser depending on version of RAWDataHeader found at beginning of data
Definition RawParser.h:378
std::vector< InputSpec > select(char const *matcher="")
GPUCalibObjectsTemplate< ConstPtr > GPUCalibObjectsConst
std::string filename()
vtx(float a, float b, float c)
Definition GPUDisplay.h:80
vec clear()
typename std::vector< T, vecpod_allocator< T > > vecpod
Definition vecpod.h:31