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