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