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
18#include "GPUSettings.h"
21#include "GPUDisplayInterface.h"
22
23#include "GPUChainTracking.h"
24#include "../utils/vecpod.h"
25#include "../utils/qsem.h"
26
27#include <array>
28#include "HandMadeMath.h"
29
30#include "utils/timer.h"
31
32namespace o2::gpu
33{
34class GPUTPCTracker;
35struct GPUParam;
36class GPUQA;
37
39{
40 public:
41 GPUDisplay(GPUDisplayFrontend* frontend, GPUChainTracking* chain, GPUQA* qa, const GPUParam* param = nullptr, const GPUCalibObjectsConst* calib = nullptr, const GPUSettingsDisplay* config = 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 GPUDisplayFrontend* frontend() { return mFrontend; }
76 bool drawTextInCompatMode() const { return mDrawTextInCompatMode; }
77 int32_t& drawTextFontSize() { return mDrawTextFontSize; }
78
79 private:
80 static constexpr int32_t NSECTORS = GPUChainTracking::NSECTORS;
81 static constexpr float GL_SCALE_FACTOR = (1.f / 100.f);
82
83 static constexpr const int32_t N_POINTS_TYPE = 15;
84 static constexpr const int32_t N_POINTS_TYPE_TPC = 9;
85 static constexpr const int32_t N_POINTS_TYPE_TRD = 2;
86 static constexpr const int32_t N_POINTS_TYPE_TOF = 2;
87 static constexpr const int32_t N_POINTS_TYPE_ITS = 2;
88 static constexpr const int32_t N_LINES_TYPE = 7;
89 static constexpr const int32_t N_FINAL_TYPE = 4;
90 static constexpr int32_t TRACK_TYPE_ID_LIMIT = 100;
91 enum PointTypes { tCLUSTER = 0,
92 tINITLINK = 1,
93 tLINK = 2,
94 tSEED = 3,
95 tTRACKLET = 4,
96 tSECTORTRACK = 5,
97 tEXTRAPOLATEDTRACK = 6,
98 tFINALTRACK = 7,
99 tMARKED = 8,
100 tTRDCLUSTER = 9,
101 tTRDATTACHED = 10,
102 tTOFCLUSTER = 11,
103 tTOFATTACHED = 12,
104 tITSCLUSTER = 13,
105 tITSATTACHED = 14 };
106 enum LineTypes { RESERVED = 0 /*1 -- 6 = INITLINK to GLOBALTRACK*/ };
107
108 using vboList = GPUDisplayBackend::vboList;
109
110 struct threadVertexBuffer {
112 vecpod<int32_t> start[N_FINAL_TYPE];
113 vecpod<uint32_t> count[N_FINAL_TYPE];
114 std::pair<vecpod<int32_t>*, vecpod<uint32_t>*> vBuf[N_FINAL_TYPE];
115 threadVertexBuffer() : buffer()
116 {
117 for (int32_t i = 0; i < N_FINAL_TYPE; i++) {
118 vBuf[i].first = start + i;
119 vBuf[i].second = count + i;
120 }
121 }
122 void clear()
123 {
124 for (int32_t i = 0; i < N_FINAL_TYPE; i++) {
125 start[i].clear();
126 count[i].clear();
127 }
128 }
129 };
130
131 class opengl_spline
132 {
133 public:
134 opengl_spline() : ma(), mb(), mc(), md(), mx() {}
135 void create(const vecpod<float>& x, const vecpod<float>& y);
136 float evaluate(float x);
137 void setVerbose() { mVerbose = true; }
138
139 private:
140 vecpod<float> ma, mb, mc, md, mx;
141 bool mVerbose = false;
142 };
143
144 void DrawGLScene_internal(float animateTime = -1.f, bool renderToMixBuffer = false);
145 void DrawGLScene_updateEventData();
146 void DrawGLScene_cameraAndAnimation(float animateTime, float& mixSlaveImage, hmm_mat4& nextViewMatrix);
147 size_t DrawGLScene_updateVertexList();
148 void DrawGLScene_drawCommands();
149 int32_t InitDisplay_internal();
150 int32_t getNumThreads();
151 void updateOptions();
152 void disableUnsupportedOptions();
153 int32_t buildTrackFilter();
154 const GPUTPCTracker& sectorTracker(int32_t iSector);
155 const GPUTRDGeometry* trdGeometry();
156 const GPUTrackingInOutPointers* mIOPtrs = nullptr;
157 void insertVertexList(std::pair<vecpod<int32_t>*, vecpod<uint32_t>*>& vBuf, size_t first, size_t last);
158 void insertVertexList(int32_t iSector, size_t first, size_t last);
159 template <typename... Args>
160 void SetInfo(Args... args)
161 {
162#pragma GCC diagnostic push
163#pragma GCC diagnostic ignored "-Wformat-security"
164 snprintf(mInfoText2, 1024, args...);
165#pragma GCC diagnostic pop
166 GPUInfo("%s", mInfoText2);
167 mInfoText2Timer.ResetStart();
168 }
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 vboList DrawClusters(int32_t iSector, int32_t select, uint32_t iCol);
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 GPUQA* mQA;
227 qSem mSemLockDisplay;
228
229 bool mDrawTextInCompatMode = false;
230 int32_t mDrawTextFontSize = 0;
231
232 int32_t mNDrawCalls = 0;
233
234 bool mUseMultiVBO = false;
235
236 std::array<float, 4> mDrawColor = {1.f, 1.f, 1.f, 1.f};
237
238 int32_t mTestSetting = 0;
239
240 float mAngleRollOrigin = -1e9;
241 float mMaxClusterZ = -1;
242
243 hmm_mat4 mViewMatrix, mModelMatrix;
244 float* const mViewMatrixP = &mViewMatrix.Elements[0][0];
245 float mXYZ[3];
246 float mAngle[3];
247 float mRPhiTheta[3];
248 float mQuat[4];
249
250 vecpod<std::array<int32_t, 37>> mOverlayTFClusters;
251 int32_t mNCollissions = 1;
252
253 vecpod<vtx> mVertexBuffer[NSECTORS];
254 vecpod<int32_t> mVertexBufferStart[NSECTORS];
255 vecpod<uint32_t> mVertexBufferCount[NSECTORS];
256
257 std::unique_ptr<float4[]> mGlobalPosPtr;
258 std::unique_ptr<float4[]> mGlobalPosPtrTRD;
259 std::unique_ptr<float4[]> mGlobalPosPtrTRD2;
260 std::unique_ptr<float4[]> mGlobalPosPtrITS;
261 std::unique_ptr<float4[]> mGlobalPosPtrTOF;
262 float4* mGlobalPos;
263 float4* mGlobalPosTRD;
264 float4* mGlobalPosTRD2;
265 float4* mGlobalPosITS;
266 float4* mGlobalPosTOF;
267 int32_t mNMaxClusters = 0;
268 int32_t mNMaxSpacePointsTRD = 0;
269 int32_t mNMaxClustersITS = 0;
270 int32_t mNMaxClustersTOF = 0;
271 int32_t mCurrentClusters = 0;
272 int32_t mCurrentSpacePointsTRD = 0;
273 int32_t mCurrentClustersITS = 0;
274 int32_t mCurrentClustersTOF = 0;
275 vecpod<int32_t> mTRDTrackIds;
276 vecpod<bool> mITSStandaloneTracks;
277 std::vector<bool> mTrackFilter;
278 bool mUpdateTrackFilter = false;
279
280 int32_t mUpdateVertexLists = 1;
281 int32_t mUpdateEventData = 0;
282 int32_t mUpdateDrawCommands = 1;
283 int32_t mUpdateRenderPipeline = 0;
284 volatile int32_t mResetScene = 0;
285
286 int32_t mAnimate = 0;
287 HighResTimer mAnimationTimer;
288 int32_t mAnimationFrame = 0;
289 int32_t mAnimationLastBase = 0;
290 int32_t mAnimateScreenshot = 0;
291 int32_t mAnimationExport = 0;
292 bool mAnimationChangeConfig = true;
293 float mAnimationDelay = 2.f;
294 vecpod<float> mAnimateVectors[9];
295 vecpod<GPUSettingsDisplayLight> mAnimateConfig;
296 opengl_spline mAnimationSplines[8];
297
298 int32_t mPrintInfoText = 1;
299 bool mPrintInfoTextAlways = 0;
300 char mInfoText2[1024];
301 HighResTimer mInfoText2Timer, mInfoHelpTimer;
302
303 std::vector<threadVertexBuffer> mThreadBuffers;
304 std::vector<std::vector<std::array<std::array<vecpod<int32_t>, 2>, NSECTORS>>> mThreadTracks;
305 volatile int32_t mInitResult = 0;
306
307 float mFPSScale = 1, mFPSScaleadjust = 0;
308 int32_t mFramesDone = 0, mFramesDoneFPS = 0;
309 HighResTimer mTimerFPS, mTimerDisplay, mTimerDraw;
310 vboList mGlDLLines[NSECTORS][N_LINES_TYPE];
311 vecpod<std::array<vboList, N_FINAL_TYPE>> mGlDLFinal[NSECTORS];
312 vboList mGlDLFinalITS;
313 vecpod<vboList> mGlDLPoints[NSECTORS][N_POINTS_TYPE];
314 vboList mGlDLGrid[NSECTORS];
315 vboList mGlDLGridTRD[NSECTORS / 2];
316
317 bool mRequestScreenshot = false;
318 std::string mScreenshotFile;
319
320 float mYFactor = 1.0f;
321};
322} // namespace o2::gpu
323
324#endif
int32_t i
GPUChain * chain
uint32_t col
Definition RawData.h:4
uint32_t c
Definition RawData.h:2
StringRef key
void ResetStart()
Definition timer.cxx:63
static constexpr int32_t NSECTORS
Definition GPUChain.h:54
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:76
int32_t & drawTextFontSize()
Definition GPUDisplay.h:77
void UpdateParam(const GPUParam *param) override
Definition GPUDisplay.h:50
int32_t updateDrawCommands() const
Definition GPUDisplay.h:64
GPUDisplayFrontend * frontend()
Definition GPUDisplay.h:75
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)
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