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