Skip to content
2 changes: 1 addition & 1 deletion GPU/GPUTracking/Definitions/GPUSettingsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ EndConfig()

// Vulkan Display Settings
BeginSubConfig(GPUSettingsDisplayVulkan, vulkan, configStandalone.display, "GLV", 0, "Vulkan display settings", display_vulkan)
AddOption(nFramesInFlight, int32_t, 0, "", 0, "Max number of render frames in flight (0 = as many as swapchain images)")
AddOption(nFramesInFlight, uint32_t, 3, "", 0, "Max number of render frames in flight")
AddOption(uniformBuffersInDeviceMemory, bool, 1, "", 0, "Have uniform buffers in host-accessible device memory")
AddOption(forceDevice, int32_t, -1, "", 0, "Force Vulkan device number to use")
AddHelp("help", 'h')
Expand Down
9 changes: 7 additions & 2 deletions GPU/GPUTracking/Global/GPUChainTracking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ GPUChainTracking::GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits,
mFlatObjectsDevice.mChainTracking = this;
}

GPUChainTracking::~GPUChainTracking() = default;
GPUChainTracking::~GPUChainTracking()
{
if (mDisplayRunning) {
GetProcessingSettings().eventDisplay->StopDisplay();
}
}

void GPUChainTracking::RegisterPermanentMemoryAndProcessors()
{
Expand Down Expand Up @@ -867,7 +872,7 @@ int32_t GPUChainTracking::RunChainFinalize()
} while (GetProcessingSettings().eventDisplay->getDisplayControl() == 0);
if (GetProcessingSettings().eventDisplay->getDisplayControl() == 2) {
mDisplayRunning = false;
GetProcessingSettings().eventDisplay->DisplayExit();
GetProcessingSettings().eventDisplay->StopDisplay();
const_cast<GPUSettingsProcessing&>(GetProcessingSettings()).eventDisplay = nullptr; // TODO: fixme - eventDisplay should probably not be put into ProcessingSettings in the first place
return GPUReconstruction::retValValue::retDoExit;
}
Expand Down
9 changes: 3 additions & 6 deletions GPU/GPUTracking/Interface/GPUO2InterfaceDisplay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GPUO2InterfaceDisplay::GPUO2InterfaceDisplay(const GPUO2InterfaceConfiguration*

GPUO2InterfaceDisplay::~GPUO2InterfaceDisplay() = default;

int32_t GPUO2InterfaceDisplay::startDisplay()
int32_t GPUO2InterfaceDisplay::StartUnmanagedDisplay()
{
int32_t retVal = mDisplay->StartDisplay();
if (retVal) {
Expand Down Expand Up @@ -71,12 +71,9 @@ int32_t GPUO2InterfaceDisplay::show(const GPUTrackingInOutPointers* ptrs)
return 0;
}

int32_t GPUO2InterfaceDisplay::endDisplay()
int32_t GPUO2InterfaceDisplay::StopUnmanagedDisplay()
{
mFrontend->DisplayExit();
while (mFrontend->IsRunning()) {
usleep(10000);
}
mFrontend->StopDisplay();
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions GPU/GPUTracking/Interface/GPUO2InterfaceDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class GPUO2InterfaceDisplay

void UpdateCalib(const GPUCalibObjectsConst* calib);
void UpdateGRP(const GPUSettingsGRP* grp);
int32_t startDisplay();
int32_t StartUnmanagedDisplay();
int32_t show(const GPUTrackingInOutPointers* ptrs);
int32_t endDisplay();
int32_t StopUnmanagedDisplay();

private:
std::unique_ptr<GPUDisplayInterface> mDisplay;
Expand Down
6 changes: 6 additions & 0 deletions GPU/GPUTracking/display/GPUDisplay.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,12 @@ void GPUDisplay::ShowNextEvent(const GPUTrackingInOutPointers* ptrs)

void GPUDisplay::BlockTillNextEvent() { mSemLockDisplay.Lock(); }

void GPUDisplay::UnblockDisplay()
{
mSemLockDisplay.Trylock();
mSemLockDisplay.Unlock();
}

void GPUDisplay::WaitTillEventShown()
{
std::unique_lock<std::mutex> lock(mMutexLoadAndShowEvent);
Expand Down
3 changes: 2 additions & 1 deletion GPU/GPUTracking/display/GPUDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class GPUDisplay : public GPUDisplayInterface
~GPUDisplay() override = default;

int32_t StartDisplay() override;
void ExitDisplay();
void ShowNextEvent(const GPUTrackingInOutPointers* ptrs = nullptr) override;
void BlockTillNextEvent() override;
void UnblockDisplay();
void WaitTillEventShown() override;
void SetCollisionFirstCluster(uint32_t collision, int32_t sector, int32_t cluster) override;
void UpdateCalib(const GPUCalibObjectsConst* calib) override { mCalib = calib; }
Expand All @@ -60,7 +62,6 @@ class GPUDisplay : public GPUDisplayInterface
int32_t DrawGLScene();
void HandleSendKey(int32_t key);
int32_t InitDisplay(bool initFailure = false);
void ExitDisplay();
void ResizeScene(int32_t width, int32_t height, bool init = false);

const GPUSettingsDisplayRenderer& cfgR() const { return mCfgR; }
Expand Down
3 changes: 1 addition & 2 deletions GPU/GPUTracking/display/GPUDisplayInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ class GPUDisplayFrontendInterface
public:
virtual ~GPUDisplayFrontendInterface();
static GPUDisplayFrontendInterface* getFrontend(const char* type);
virtual void DisplayExit() = 0;
virtual void StopDisplay() = 0;
virtual bool EnableSendKey() = 0;
virtual int32_t getDisplayControl() const = 0;
virtual void setDisplayControl(int32_t v) = 0;
virtual bool IsRunning() const = 0;
virtual void sendKey(int32_t v) = 0;
virtual const char* frontendName() const = 0;

Expand Down
265 changes: 110 additions & 155 deletions GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.cxx

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions GPU/GPUTracking/display/backend/GPUDisplayBackendVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,11 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
std::vector<vk::Framebuffer> mFramebuffersTexture;
vk::CommandPool mCommandPool;

bool mCommandBufferPerImage = false;
bool mCommandInfrastructureCreated = false;
uint32_t mImageCount = 0;
uint32_t mFramesInFlight = 0;
int32_t mCurrentFrame = 0;
uint32_t mCurrentImageIndex = 0;
int32_t mCurrentBufferSet = 0;
vk::CommandBuffer mCurrentCommandBuffer;
int32_t mCurrentCommandBufferLastPipeline = -1;

Expand All @@ -177,13 +175,12 @@ class GPUDisplayBackendVulkan : public GPUDisplayBackend
std::vector<vk::CommandBuffer> mCommandBuffersText;
std::vector<vk::CommandBuffer> mCommandBuffersTexture;
std::vector<vk::CommandBuffer> mCommandBuffersMix;
std::vector<vk::CommandBuffer> mFrameCommandBuffers; // All command buffers of the current frame, submitted as one batch, ordered by render pass dependencies and barriers
std::vector<bool> mCommandBufferUpToDate;
std::vector<vk::Semaphore> mImageAvailableSemaphore;
std::vector<vk::Semaphore> mRenderFinishedSemaphore;
std::vector<vk::Semaphore> mTextFinishedSemaphore;
std::vector<vk::Semaphore> mMixFinishedSemaphore;
std::vector<vk::Semaphore> mDownsampleFinishedSemaphore;
std::vector<vk::Semaphore> mPresentSemaphore;
std::vector<vk::Fence> mInFlightFence;
std::vector<vk::Fence> mImageFence;
std::vector<VulkanBuffer> mUniformBuffersMat[3];
std::vector<VulkanBuffer> mUniformBuffersCol[3];
std::vector<vk::DescriptorSet> mDescriptorSets[3];
Expand Down
17 changes: 17 additions & 0 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,20 @@ int32_t GPUDisplayFrontend::StartDisplay()
#endif
return (0);
}

void GPUDisplayFrontend::StopDisplay()
{
{
std::lock_guard lock(mExitStateMutex);
if (mDisplayRunning) {
mDisplayControl = 2;
StopDisplayA();
mDisplay->UnblockDisplay();
}
}
while (mDisplayRunning) {
std::this_thread::sleep_for(std::chrono::microseconds(10000)); // TODO: Signal by semaphore
}
}

void GPUDisplayFrontend::StopDisplayA() {}
5 changes: 3 additions & 2 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
static constexpr int32_t GL_MIN_VERSION_MINOR = 5;

int32_t StartDisplay(); // Start the display. This function returns, and should spawn a thread that runs the display, and calls InitDisplay
void DisplayExit() override = 0; // Stop the display. Display thread should call ExitDisplay and then wait that IsRunning() returns false
bool IsRunning() const override { return mDisplayRunning; }
void StopDisplay() override; // Stop the display. Display thread should call ExitDisplay. Functions waits for display thread to terminate
virtual void SwitchFullscreen(bool set) = 0; // Toggle full-screen mode
virtual void ToggleMaximized(bool set) = 0; // Maximize window
virtual void SetVSync(bool enable) = 0; // Enable / disable vsync
Expand All @@ -79,6 +78,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface

protected:
virtual int32_t FrontendMain() = 0;
virtual void StopDisplayA();
static void* FrontendThreadWrapper(void*);
void waitForFPSLimit(); // Sleep until the next frame is due according to fpsRate (no sleep with maxFPSRate or fpsRate <= 0)

Expand Down Expand Up @@ -121,6 +121,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
volatile int32_t mNeedUpdate = 0; // flag that backend shall update the GL window, and call DrawGLScene
std::mutex mSendKeyMutex;
std::vector<int32_t> mSendKeys; // Keys sent by external entity (usually console), may be ignored by backend.
std::mutex mExitStateMutex;

// Keyboard / Mouse actions
bool mMouseDn = false; // Mouse button down
Expand Down
28 changes: 13 additions & 15 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlfw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,10 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()
glfwSwapInterval(1);
}

pthread_mutex_lock(&mSemLockExit);
mDisplayRunning = true;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayRunning = true;
}

if (mBackend->ExtInit()) {
fprintf(stderr, "Error initializing GL extension wrapper\n");
Expand Down Expand Up @@ -362,23 +363,20 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()
}

ExitDisplay();
mDisplayControl = 2;
pthread_mutex_lock(&mSemLockExit);
glfwDestroyWindow(mWindow);
glfwTerminate();
mDisplayRunning = false;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayControl = 2;
glfwDestroyWindow(mWindow);
glfwTerminate();
mDisplayRunning = false;
}

return 0;
}

void GPUDisplayFrontendGlfw::DisplayExit()
void GPUDisplayFrontendGlfw::StopDisplayA()
{
pthread_mutex_lock(&mSemLockExit);
if (mDisplayRunning) {
glfwSetWindowShouldClose(mWindow, true);
}
pthread_mutex_unlock(&mSemLockExit);
glfwSetWindowShouldClose(mWindow, true);
}

void GPUDisplayFrontendGlfw::OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton)
Expand Down
4 changes: 1 addition & 3 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlfw.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define GPUDISPLAYFRONTENDGLFW_H

#include "GPUDisplayFrontend.h"
#include <pthread.h>

struct GLFWwindow;

Expand All @@ -28,7 +27,7 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
GPUDisplayFrontendGlfw();
~GPUDisplayFrontendGlfw() override = default;

void DisplayExit() override;
void StopDisplayA() override;
void SwitchFullscreen(bool set) override;
void ToggleMaximized(bool set) override;
void SetVSync(bool enable) override;
Expand Down Expand Up @@ -63,7 +62,6 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
bool mRestoreWindowedSize = false;
double mPixelRatio = 1.; // Framebuffer pixels per window coordinate (1 on X11 / Win32, scale on Wayland / macOS)

pthread_mutex_t mSemLockExit = PTHREAD_MUTEX_INITIALIZER;
int32_t mWindowX = 0;
int32_t mWindowY = 0;
int32_t mWindowWidth = INIT_WIDTH;
Expand Down
24 changes: 11 additions & 13 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlut.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -265,26 +265,24 @@ int32_t GPUDisplayFrontendGlut::FrontendMain()
glutMouseWheelFunc(mMouseWheelFunc);
applyInitialWindowState();

pthread_mutex_lock(&mSemLockExit);
mDisplayRunning = true;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayRunning = true;
}
glutMainLoop();
mDisplayControl = 2;
pthread_mutex_lock(&mSemLockExit);
mDisplayRunning = false;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayControl = 2;
mDisplayRunning = false;
}

ExitDisplay();
return 0;
}

void GPUDisplayFrontendGlut::DisplayExit()
void GPUDisplayFrontendGlut::StopDisplayA()
{
pthread_mutex_lock(&mSemLockExit);
if (mDisplayRunning) {
glutLeaveMainLoop();
}
pthread_mutex_unlock(&mSemLockExit);
glutLeaveMainLoop();
}

void GPUDisplayFrontendGlut::OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton)
Expand Down
5 changes: 1 addition & 4 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlut.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#define GPUDISPLAYFRONTENDGLUT_H

#include "GPUDisplayFrontend.h"
#include <pthread.h>

namespace o2::gpu
{
Expand All @@ -26,7 +25,7 @@ class GPUDisplayFrontendGlut : public GPUDisplayFrontend
GPUDisplayFrontendGlut();
~GPUDisplayFrontendGlut() override = default;

void DisplayExit() override;
void StopDisplayA() override;
void SwitchFullscreen(bool set) override;
void ToggleMaximized(bool set) override;
void SetVSync(bool enable) override;
Expand All @@ -48,8 +47,6 @@ class GPUDisplayFrontendGlut : public GPUDisplayFrontend
static int32_t GetKey(int32_t key);
static void GetKey(int32_t keyin, int32_t& keyOut, int32_t& keyPressOut, bool special);

pthread_mutex_t mSemLockExit = PTHREAD_MUTEX_INITIALIZER;

int32_t mWidth = INIT_WIDTH;
int32_t mHeight = INIT_HEIGHT;
bool mFullScreen = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class GPUDisplayFrontendNone : public GPUDisplayFrontend
GPUDisplayFrontendNone();
~GPUDisplayFrontendNone() override = default;

void DisplayExit() override {}
void SwitchFullscreen(bool set) override {}
void ToggleMaximized(bool set) override {}
void SetVSync(bool enable) override {}
Expand Down
23 changes: 8 additions & 15 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,10 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
return (1);
}

pthread_mutex_lock(&mSemLockExit);
mDisplayRunning = true;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayRunning = true;
}

while (mDisplayControl != 2) {
bool error = false;
Expand Down Expand Up @@ -606,9 +607,10 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
}
xkb_context_unref(mXKBcontext);

pthread_mutex_lock(&mSemLockExit);
mDisplayRunning = false;
pthread_mutex_unlock(&mSemLockExit);
{
std::lock_guard lock(mExitStateMutex);
mDisplayRunning = false;
}

if (mCursorShapeDevice) {
wp_cursor_shape_device_v1_destroy(mCursorShapeDevice);
Expand Down Expand Up @@ -678,15 +680,6 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
return (0);
}

void GPUDisplayFrontendWayland::DisplayExit()
{
pthread_mutex_lock(&mSemLockExit);
if (mDisplayRunning) {
mDisplayControl = 2;
}
pthread_mutex_unlock(&mSemLockExit);
}

void GPUDisplayFrontendWayland::SwitchFullscreen(bool set)
{
if (!mCanFullscreen) {
Expand Down
Loading
Loading