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