Skip to content

Commit 3467dde

Browse files
committed
GPU Display: Block until display started and print meaningful info messages to the console
1 parent b8d6494 commit 3467dde

File tree

7 files changed

+61
-28
lines changed

7 files changed

+61
-28
lines changed

GPU/GPUTracking/Global/GPUChainTracking.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ int32_t GPUChainTracking::RunChainFinalize()
824824

825825
if (GetProcessingSettings().eventDisplay) {
826826
if (!mDisplayRunning) {
827+
GPUInfo("Starting Event Display...");
827828
if (mEventDisplay->StartDisplay()) {
828829
return (1);
829830
}
@@ -832,6 +833,8 @@ int32_t GPUChainTracking::RunChainFinalize()
832833
mEventDisplay->ShowNextEvent();
833834
}
834835

836+
mEventDisplay->WaitTillEventShown();
837+
835838
if (GetProcessingSettings().eventDisplay->EnableSendKey()) {
836839
while (kbhit()) {
837840
getch();
@@ -863,9 +866,9 @@ int32_t GPUChainTracking::RunChainFinalize()
863866
return (2);
864867
}
865868
GetProcessingSettings().eventDisplay->setDisplayControl(0);
866-
GPUInfo("Loading next event");
869+
GPUInfo("Loading next event...");
867870

868-
mEventDisplay->WaitForNextEvent();
871+
mEventDisplay->BlockTillNextEvent();
869872
}
870873

871874
return 0;

GPU/GPUTracking/Interface/GPUO2InterfaceDisplay.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ int32_t GPUO2InterfaceDisplay::startDisplay()
4646
if (retVal) {
4747
return retVal;
4848
}
49-
mDisplay->WaitForNextEvent();
49+
mDisplay->WaitTillEventShown();
50+
mDisplay->BlockTillNextEvent();
5051
return 0;
5152
}
5253

@@ -59,14 +60,15 @@ int32_t GPUO2InterfaceDisplay::show(const GPUTrackingInOutPointers* ptrs)
5960
ptrs = tmpPtr.get();
6061
}
6162
mDisplay->ShowNextEvent(ptrs);
63+
mDisplay->WaitTillEventShown();
6264
do {
6365
usleep(10000);
6466
} while (mFrontend->getDisplayControl() == 0);
6567
if (mFrontend->getDisplayControl() == 2) {
6668
return 1;
6769
}
6870
mFrontend->setDisplayControl(0);
69-
mDisplay->WaitForNextEvent();
71+
mDisplay->BlockTillNextEvent();
7072
return 0;
7173
}
7274

GPU/GPUTracking/display/GPUDisplay.cxx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <memory>
2222
#include <cstring>
2323
#include <stdexcept>
24+
#include <mutex>
25+
#include <condition_variable>
2426

2527
#ifndef _WIN32
2628
#include "../utils/linux_helpers.h"
@@ -143,7 +145,7 @@ void GPUDisplay::ResizeScene(int32_t width, int32_t height, bool init)
143145
mBackend->resizeScene(width, height);
144146

145147
if (init) {
146-
mResetScene = 1;
148+
mResetScene = true;
147149
mViewMatrix = MY_HMM_IDENTITY;
148150
mModelMatrix = MY_HMM_IDENTITY;
149151
}
@@ -220,6 +222,14 @@ int32_t GPUDisplay::DrawGLScene()
220222
GPUError("Runtime error %s during display", e.what());
221223
retVal = 1;
222224
}
225+
226+
if (mLoadAndShowEvent) {
227+
{
228+
std::lock_guard<std::mutex> lock(mMutexLoadAndShowEvent);
229+
mLoadAndShowEvent = false;
230+
}
231+
mCVLoadAndShowEvent.notify_one();
232+
}
223233
mSemLockDisplay.Unlock();
224234

225235
return retVal;
@@ -266,9 +276,9 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
266276
mCfgR.camLookOrigin = mCfgR.camYUp = false;
267277
mAngleRollOrigin = -1e9f;
268278
mCfgR.fov = 45.f;
269-
mUpdateDrawCommands = 1;
279+
mUpdateDrawCommands = true;
270280

271-
mResetScene = 0;
281+
mResetScene = false;
272282
} else {
273283
float moveZ = scalefactor * ((float)mMouseWheelTmp / 150 + (float)(mFrontend->mKeys[(uint8_t)'W'] - mFrontend->mKeys[(uint8_t)'S']) * (!mFrontend->mKeys[mFrontend->KEY_SHIFT]) * 0.2f * mFPSScale);
274284
float moveY = scalefactor * ((float)(mFrontend->mKeys[mFrontend->KEY_PAGEDOWN] - mFrontend->mKeys[mFrontend->KEY_PAGEUP]) * 0.2f * mFPSScale);
@@ -386,7 +396,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
386396
}
387397
if (deltaLine) {
388398
SetInfo("%s line width: %f", deltaLine > 0 ? "Increasing" : "Decreasing", mCfgL.lineWidth);
389-
mUpdateDrawCommands = 1;
399+
mUpdateDrawCommands = true;
390400
}
391401
minSize *= 2;
392402
int32_t deltaPoint = mFrontend->mKeys[(uint8_t)'+'] * (!mFrontend->mKeysShift[(uint8_t)'+']) - mFrontend->mKeys[(uint8_t)'-'] * (!mFrontend->mKeysShift[(uint8_t)'-']);
@@ -396,7 +406,7 @@ void GPUDisplay::DrawGLScene_cameraAndAnimation(float animateTime, float& mixSla
396406
}
397407
if (deltaPoint) {
398408
SetInfo("%s point size: %f", deltaPoint > 0 ? "Increasing" : "Decreasing", mCfgL.pointSize);
399-
mUpdateDrawCommands = 1;
409+
mUpdateDrawCommands = true;
400410
}
401411
}
402412

@@ -616,7 +626,7 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
616626
disableUnsupportedOptions();
617627
}
618628
if (mUpdateEventData || mUpdateVertexLists) {
619-
mUpdateDrawCommands = 1;
629+
mUpdateDrawCommands = true;
620630
}
621631

622632
if (animateTime < 0 && (mUpdateEventData || mResetScene) && mIOPtrs) {
@@ -625,8 +635,8 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
625635
mTimerFPS.ResetStart();
626636
mFramesDoneFPS = 0;
627637
mFPSScaleadjust = 0;
628-
mUpdateVertexLists = 1;
629-
mUpdateEventData = 0;
638+
mUpdateVertexLists = true;
639+
mUpdateEventData = false;
630640
}
631641

632642
hmm_mat4 nextViewMatrix = MY_HMM_IDENTITY;
@@ -658,7 +668,7 @@ void GPUDisplay::DrawGLScene_internal(float animateTime, bool renderToMixBuffer)
658668
mBackend->drawField();
659669
}
660670

661-
mUpdateDrawCommands = mUpdateRenderPipeline = 0;
671+
mUpdateDrawCommands = mUpdateRenderPipeline = false;
662672
mBackend->finishDraw(doScreenshot, renderToMixBuffer, mixSlaveImage);
663673

664674
if (animateTime < 0) {
@@ -708,15 +718,25 @@ void GPUDisplay::ShowNextEvent(const GPUTrackingInOutPointers* ptrs)
708718
if (mMaxClusterZ <= 0) {
709719
mResetScene = true;
710720
}
711-
mSemLockDisplay.Unlock();
712721
mFrontend->mNeedUpdate = 1;
713722
mUpdateEventData = true;
723+
mLoadAndShowEvent = true;
724+
mSemLockDisplay.Unlock();
714725
}
715726

716-
void GPUDisplay::WaitForNextEvent() { mSemLockDisplay.Lock(); }
727+
void GPUDisplay::BlockTillNextEvent() { mSemLockDisplay.Lock(); }
728+
729+
void GPUDisplay::WaitTillEventShown()
730+
{
731+
std::unique_lock<std::mutex> lock(mMutexLoadAndShowEvent);
732+
while (mLoadAndShowEvent) {
733+
mCVLoadAndShowEvent.wait(lock);
734+
}
735+
}
717736

718737
int32_t GPUDisplay::StartDisplay()
719738
{
739+
mLoadAndShowEvent = true;
720740
if (mFrontend->StartDisplay()) {
721741
return (1);
722742
}

GPU/GPUTracking/display/GPUDisplay.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
#include "GPUDisplayInterface.h"
2121
#include "GPUSettings.h"
2222

23-
#include "../utils/vecpod.h"
24-
#include "../utils/qsem.h"
25-
2623
#include <array>
24+
#include <mutex>
25+
#include <condition_variable>
26+
2727
#include "HandMadeMath.h"
2828

2929
#include "utils/timer.h"
30+
#include "utils/vecpod.h"
31+
#include "utils/qsem.h"
3032

3133
namespace o2::gpu
3234
{
@@ -44,7 +46,8 @@ class GPUDisplay : public GPUDisplayInterface
4446

4547
int32_t StartDisplay() override;
4648
void ShowNextEvent(const GPUTrackingInOutPointers* ptrs = nullptr) override;
47-
void WaitForNextEvent() override;
49+
void BlockTillNextEvent() override;
50+
void WaitTillEventShown() override;
4851
void SetCollisionFirstCluster(uint32_t collision, int32_t sector, int32_t cluster) override;
4952
void UpdateCalib(const GPUCalibObjectsConst* calib) override { mCalib = calib; }
5053
void UpdateParam(const GPUParam* param) override { mParam = param; }
@@ -221,7 +224,10 @@ class GPUDisplay : public GPUDisplayInterface
221224
GPUSettingsDisplayRenderer mCfgR;
222225
const GPUSettingsProcessing& mProcessingSettings;
223226
GPUQA* mQA;
227+
224228
qSem mSemLockDisplay;
229+
std::mutex mMutexLoadAndShowEvent;
230+
std::condition_variable mCVLoadAndShowEvent;
225231

226232
bool mDrawTextInCompatMode = false;
227233
int32_t mDrawTextFontSize = 0;
@@ -272,13 +278,14 @@ class GPUDisplay : public GPUDisplayInterface
272278
vecpod<int32_t> mTRDTrackIds;
273279
vecpod<bool> mITSStandaloneTracks;
274280
std::vector<bool> mTrackFilter;
275-
bool mUpdateTrackFilter = false;
276281

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+
volatile bool mUpdateTrackFilter = false;
283+
volatile bool mUpdateVertexLists = true;
284+
volatile bool mUpdateEventData = false;
285+
volatile bool mUpdateDrawCommands = true;
286+
volatile bool mUpdateRenderPipeline = false;
287+
volatile bool mResetScene = false;
288+
volatile bool mLoadAndShowEvent = false;
282289

283290
int32_t mAnimate = 0;
284291
HighResTimer mAnimationTimer;

GPU/GPUTracking/display/GPUDisplayInterface.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class GPUDisplayInterface
4040
virtual ~GPUDisplayInterface();
4141
virtual int32_t StartDisplay() = 0;
4242
virtual void ShowNextEvent(const GPUTrackingInOutPointers* ptrs = nullptr) = 0;
43-
virtual void WaitForNextEvent() = 0;
43+
virtual void BlockTillNextEvent() = 0;
44+
virtual void WaitTillEventShown() = 0;
4445
virtual void SetCollisionFirstCluster(uint32_t collision, int32_t sector, int32_t cluster) = 0;
4546
virtual void UpdateCalib(const GPUCalibObjectsConst* calib) = 0;
4647
virtual void UpdateParam(const GPUParam* param) = 0;

GPU/GPUTracking/display/frontend/GPUDisplayKeys.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void GPUDisplay::HandleKey(uint8_t key)
8989
mFrontend->mDisplayControl = 2;
9090
SetInfo("Exiting", 1);
9191
} else if (key == 'r') {
92-
mResetScene = 1;
92+
mResetScene = true;
9393
SetInfo("View reset", 1);
9494
} else if (key == mFrontend->KEY_ALT && mFrontend->mKeysShift[mFrontend->KEY_ALT]) {
9595
mCfgR.camLookOrigin ^= 1;

GPU/GPUTracking/display/render/GPUDisplayDraw.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ size_t GPUDisplay::DrawGLScene_updateVertexList()
941941
break; // TODO: Only sector 0 filled for now
942942
}
943943

944-
mUpdateVertexLists = 0;
944+
mUpdateVertexLists = false;
945945
size_t totalVertizes = 0;
946946
for (int32_t i = 0; i < NSECTORS; i++) {
947947
totalVertizes += mVertexBuffer[i].size();

0 commit comments

Comments
 (0)