Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GPU/GPUTracking/Base/GPUParam.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace o2::gpu;
#include <cstring>
#include <tuple>

#include "utils/qconfigrtc.h"
#include "utils/qconfig_rtc.h"

void GPUParam::SetDefaults(float solenoidBz, bool assumeConstantBz)
{
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUTracking/DataTypes/GPUConfigDump.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace
GPUSettingsStandalone configStandalone;
std::vector<std::function<void()>> qprint_global;
#define QCONFIG_PRINT
#include "utils/qconfig.h"
#include "utils/qconfig_internal.h"
#undef QCONFIG_PRINT
} // namespace

Expand Down
3 changes: 3 additions & 0 deletions GPU/GPUTracking/Definitions/GPUSettingsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ AddOption(debugOnFailureMaxSize, uint32_t, 0, "", 0, "Max size of existing dumps
AddOption(debugOnFailureDirectory, std::string, ".", "", 0, "Target folder for debug / dump")
AddOption(ROOTDumpFile, std::string, "gpudebug.root", "", 0, "File name for ROOT dump (default gpudebug.root)")
AddOption(memoryStat, bool, false, "", 0, "Print memory statistics")
AddVariable(runsStandalone, bool, false)
AddVariable(eventDisplay, o2::gpu::GPUDisplayFrontendInterface*, nullptr)
AddSubConfig(GPUSettingsProcessingRTC, rtc)
AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech)
Expand Down Expand Up @@ -531,6 +532,8 @@ AddOption(noFreetype, bool, false, "", 0, "Do not use Freetype for font renderin
AddOption(displayRenderer, std::string, "auto", "renderer", 0, "Renderer for event display: opengl | vulkan | auto")
AddOption(displayFrontend, std::string, "auto", "displayFrontend", 0, "Frontend to use for event display: auto | win32 | x11 | glut | glfw | wayland")
AddOptionVec(filterMacros, std::string, "", 0, "ROOT macros used as track filter")
AddOption(guiReplyTimeout, uint32_t, 100, "", 0, "Time in ms the Qt GUI waits at most for the display to process its update")
AddOption(guiMaxUpdatesAhead, uint32_t, 3, "", 0, "Number of updates the Qt GUI may send ahead of the last one the display has processed, before it waits for the display")
AddSubConfig(GPUSettingsDisplayLight, light)
AddSubConfig(GPUSettingsDisplayHeavy, heavy)
AddSubConfig(GPUSettingsDisplayRenderer, renderer)
Expand Down
7 changes: 3 additions & 4 deletions GPU/GPUTracking/Global/GPUChainTracking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -849,24 +849,23 @@ int32_t GPUChainTracking::RunChainFinalize()

mEventDisplay->WaitTillEventShown();

if (GetProcessingSettings().eventDisplay->EnableSendKey()) {
if (GetProcessingSettings().runsStandalone) {
while (kbhit()) {
getch();
}
GPUInfo("Press key for next event!");
}

int32_t iKey;
do {
usleep(10000);
if (GetProcessingSettings().eventDisplay->EnableSendKey()) {
if (GetProcessingSettings().runsStandalone) {
iKey = kbhit() ? getch() : 0;
if (iKey == 27) {
GetProcessingSettings().eventDisplay->setDisplayControl(2);
} else if (iKey == 'n') {
break;
} else if (iKey) {
GetProcessingSettings().eventDisplay->sendKey(iKey);
GetProcessingSettings().eventDisplay->sendExternalGUIKey(iKey);
}
}
} while (GetProcessingSettings().eventDisplay->getDisplayControl() == 0);
Expand Down
7 changes: 4 additions & 3 deletions GPU/GPUTracking/Standalone/Benchmark/standalone.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::vector<GPUChainTracking::InOutMemory> ioMemEvents;

int32_t ReadConfiguration(int argc, char** argv)
{
int32_t qcRet = qConfigParse(argc, (const char**)argv);
int32_t qcRet = qConfig::qConfigParse(argc, (const char**)argv);
if (qcRet) {
if (qcRet != qConfig::qcrHelp) {
printf("Error parsing command line parameters\n");
Expand All @@ -107,7 +107,7 @@ int32_t ReadConfiguration(int argc, char** argv)
}
if (configStandalone.printSettings > 1) {
printf("Config Dump before ReadConfiguration\n");
qConfigPrint();
qConfig::qConfigPrint();
}
if (configStandalone.proc.debugLevel == -1) {
configStandalone.proc.debugLevel = 0;
Expand Down Expand Up @@ -295,7 +295,7 @@ int32_t ReadConfiguration(int argc, char** argv)
}
if (configStandalone.printSettings > 1) {
printf("Config Dump after ReadConfiguration\n");
qConfigPrint();
qConfig::qConfigPrint();
}

return (0);
Expand Down Expand Up @@ -760,6 +760,7 @@ int32_t main(int argc, char** argv)
if (ReadConfiguration(argc, argv)) {
return 1;
}
configStandalone.proc.runsStandalone = true;
eventsDir = std::string(configStandalone.absoluteEventsDir ? "" : "events/") + configStandalone.eventsDir + "/";

GPUSettingsDeviceBackend deviceSet;
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUTracking/display/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ if(GPUCA_EVENT_DISPLAY_QT)

set(SRCS ${SRCS} frontend/GPUDisplayGUI.cxx frontend/GPUDisplayGUIWrapper.cxx)
set(SRCS_NO_H ${SRCS_NO_H} ${GPUCA_QT_MOC_SRCS} ${GPUCA_QT_UI_HDRS})
set(HDRS_INSTALL ${HDRS_INSTALL} frontend/GPUDisplayGUIChannel.h)
endif()

string(REPLACE ".cxx" ".h" HDRS "${SRCS}")
Expand Down
5 changes: 3 additions & 2 deletions GPU/GPUTracking/display/GPUDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ class GPUDisplay : public GPUDisplayInterface
void UpdateCalib(const GPUCalibObjectsConst* calib) override { mCalib = calib; }
void UpdateParam(const GPUParam* param) override { mParam = param; }

void HandleKey(uint8_t key);
void HandleKey(uint8_t key, bool doNotHandleConfigChanges = false); // With doNotHandleConfigChanges, the caller must call checkAndApplyConfigChanges
int32_t DrawGLScene();
void HandleSendKey(int32_t key);
void HandleExternalGUIKey(int32_t key); // Does not handle config changes, see HandleKey
int32_t InitDisplay(bool initFailure = false);
void ResizeScene(int32_t width, int32_t height, bool init = false);
void checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy& oldCfgH, const GPUSettingsDisplayLight& oldCfgL, const GPUSettingsDisplayRenderer& oldCfgR); // Set update flags / apply the settings that changed compared to the old copies

const GPUSettingsDisplayRenderer& cfgR() const { return mCfgR; }
const GPUSettingsDisplayLight& cfgL() const { return mCfgL; }
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 @@ -57,10 +57,9 @@ class GPUDisplayFrontendInterface
virtual ~GPUDisplayFrontendInterface();
static GPUDisplayFrontendInterface* getFrontend(const char* type);
virtual void StopDisplay() = 0;
virtual bool EnableSendKey() = 0;
virtual int32_t getDisplayControl() const = 0;
virtual void setDisplayControl(int32_t v) = 0;
virtual void sendKey(int32_t v) = 0;
virtual void sendExternalGUIKey(int32_t v) = 0;
virtual const char* frontendName() const = 0;

protected:
Expand Down
80 changes: 69 additions & 11 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ GPUDisplayFrontend* createGPUDisplayFrontendWayland();
#endif
#include "GPUDisplayFrontendNone.h"

#include "GPUDisplayGUIChannel.h"
#include "GPULogging.h"
#include <cstring>
#include <exception>
#include <algorithm>
#include <iterator>
#include <thread>
#include <utility>

#ifdef GPUCA_BUILD_EVENT_DISPLAY_QT
#include "GPUDisplayGUIWrapper.h"
Expand All @@ -58,6 +60,7 @@ class GPUDisplayGUIWrapper

using namespace o2::gpu;

GPUDisplayFrontend::GPUDisplayFrontend() = default;
GPUDisplayFrontend::~GPUDisplayFrontend() = default;

void* GPUDisplayFrontend::FrontendThreadWrapper(void* ptr)
Expand Down Expand Up @@ -85,27 +88,73 @@ void GPUDisplayFrontend::waitForFPSLimit()
mNextFrameTime = now;
return;
}
const auto period = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1. / cfg.fpsRate));
const auto period = std::chrono::duration_cast<std::chrono::steady_clock::duration>(std::chrono::duration<double>(1. / cfg.fpsRate)); // TODO: wake up on HasExternalGUISignals
mNextFrameTime += period;
if (mNextFrameTime < now - period) { // More than one frame behind (slow rendering, first frame), do not try to catch up
mNextFrameTime = now;
}
std::this_thread::sleep_until(mNextFrameTime);
}

void GPUDisplayFrontend::HandleSendKeys()
void GPUDisplayFrontend::HandleExternalGUISignals()
{
std::lock_guard lock(mSendKeyMutex);
for (auto key : mSendKeys) {
mDisplay->HandleSendKey(key);
const GPUSettingsDisplayHeavy oldCfgH = mDisplay->mCfgH;
const GPUSettingsDisplayLight oldCfgL = mDisplay->mCfgL;
const GPUSettingsDisplayRenderer oldCfgR = mDisplay->mCfgR;
bool changes = HandleExternalGUIKeys();

const bool gui = isGUIRunning();
std::optional<GPUDisplayGUIChannel::Update> update;
if (gui) {
std::lock_guard lock(mGUIChannel->mutex);
update = std::exchange(mGUIChannel->update, std::nullopt);
mGUIChannel->displayProcessingCurrentUpdate = update && mGUIChannel->guiSleeping; // GUI waits for the reply when it wakes up
}
if (update) {
for (int32_t key : update->keys) {
mDisplay->HandleExternalGUIKey(key);
}
if (update->lineWidth) {
mDisplay->mCfgL.lineWidth = *update->lineWidth;
}
changes = true;
}

if (changes) {
mDisplay->checkAndApplyConfigChanges(oldCfgH, oldCfgL, oldCfgR);
}
if (gui) {
{
std::lock_guard lock(mGUIChannel->mutex);
mGUIChannel->state.cfg = {mDisplay->mCfgH, mDisplay->mCfgL, mDisplay->mCfgR};
if (update) {
mGUIChannel->state.appliedUpdate = update->id;
}
mGUIChannel->state.counter++;
mGUIChannel->displayProcessingCurrentUpdate = false;
}
mGUIChannel->stateUpdated.notify_all();
}
mSendKeys.clear();
}

void GPUDisplayFrontend::sendKey(int32_t v)
bool GPUDisplayFrontend::HasExternalGUISignals() const
{
std::lock_guard lock(mSendKeyMutex);
mSendKeys.emplace_back(v);
return mExternalGUIKeys.size();
}

bool GPUDisplayFrontend::HandleExternalGUIKeys()
{
std::lock_guard lock(mExternalGUIKeyMutex);
for (auto key : mExternalGUIKeys) {
mDisplay->HandleExternalGUIKey(key);
}
return !std::exchange(mExternalGUIKeys, {}).empty();
}

void GPUDisplayFrontend::sendExternalGUIKey(int32_t v)
{
std::lock_guard lock(mExternalGUIKeyMutex);
mExternalGUIKeys.emplace_back(v);
}

void GPUDisplayFrontend::HandleKey(uint8_t key) { mDisplay->HandleKey(key); }
Expand All @@ -124,7 +173,6 @@ void GPUDisplayFrontend::ExitDisplay()
stopGUI();
mGUI.reset(nullptr);
}
bool GPUDisplayFrontend::EnableSendKey() { return true; }

void GPUDisplayFrontend::stopGUI()
{
Expand All @@ -140,9 +188,19 @@ int32_t GPUDisplayFrontend::startGUI()
int32_t retVal = 1;
#ifdef GPUCA_BUILD_EVENT_DISPLAY_QT
if (!mGUI) {
mGUI.reset(new GPUDisplayGUIWrapper);
mGUIChannel = std::make_unique<GPUDisplayGUIChannel>();
mGUI = std::make_unique<GPUDisplayGUIWrapper>(*mGUIChannel);
}
if (!mGUI->isRunning()) {
{
std::lock_guard lock(mGUIChannel->mutex);
mGUIChannel->update.reset();
mGUIChannel->state = {};
mGUIChannel->guiSleeping = mGUIChannel->displayProcessingCurrentUpdate = mGUIChannel->stop = false;
mGUIChannel->replyTimeout = std::chrono::milliseconds(mDisplay->cfg().guiReplyTimeout);
mGUIChannel->maxUpdatesAhead = std::max<uint32_t>(mDisplay->cfg().guiMaxUpdatesAhead, 1); // 0 would block all updates
mGUIChannel->windowName = DISPLAY_WINDOW_NAME;
}
mGUI->start();
} else {
mGUI->focus();
Expand Down
19 changes: 12 additions & 7 deletions GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class GPUReconstruction;
class GPUDisplay;
class GPUDisplayBackend;
class GPUDisplayGUIWrapper;
struct GPUDisplayGUIChannel;

class GPUDisplayFrontend : public GPUDisplayFrontendInterface
{
friend class GPUDisplay;
friend class GPUDisplayGUI; // Key codes

public:
GPUDisplayFrontend() = default;
GPUDisplayFrontend();
~GPUDisplayFrontend() override;

enum frontendTypes {
Expand All @@ -57,7 +59,6 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
virtual void ToggleMaximized(bool set) = 0; // Maximize window
virtual void SetVSync(bool enable) = 0; // Enable / disable vsync
virtual bool canSetVSync() { return false; } // OpenGL: swap interval can be set
bool EnableSendKey() override; // Request external keys (e.g. from terminal)
virtual void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true) = 0; // Print text on the display (needs the backend to build the font)
GPUDisplayBackend* backend();
static GPUDisplayFrontend* getFrontend(const char* type);
Expand All @@ -69,7 +70,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface

int32_t getDisplayControl() const override { return mDisplayControl; }
void setDisplayControl(int32_t v) override { mDisplayControl = v; }
void sendKey(int32_t v) override;
void sendExternalGUIKey(int32_t v) override;

frontendTypes frontendType() const { return mFrontendType; }
const char* frontendName() const override { return mFrontendName; }
Expand Down Expand Up @@ -102,7 +103,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
static constexpr int32_t KEY_ENTER = 13; // fixed at 13
static constexpr int32_t KEY_F1 = 14;
static constexpr int32_t KEY_F2 = 15;
static constexpr int32_t KEY_F3 = 26;
static constexpr int32_t KEY_F3 = 16;
static constexpr int32_t KEY_F4 = 17;
static constexpr int32_t KEY_F5 = 18;
static constexpr int32_t KEY_F6 = 19;
Expand All @@ -121,8 +122,8 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
// volatile variables to exchange control informations between display and backend
volatile int32_t mDisplayControl = 0; // Control for next event (=1) or quit (=2)
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 mExternalGUIKeyMutex;
std::vector<int32_t> mExternalGUIKeys; // Keys sent by external entity (usually console), may be ignored by backend.
std::mutex mExitStateMutex;

// Keyboard / Mouse actions
Expand All @@ -147,11 +148,13 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
const char* mFrontendName = nullptr;
volatile bool mDisplayRunning = false;

std::unique_ptr<GPUDisplayGUIChannel> mGUIChannel; // Must outlive mGUI
std::unique_ptr<GPUDisplayGUIWrapper> mGUI;

void HandleKey(uint8_t key); // Callback for handling key presses
int32_t DrawGLScene(); // Callback to draw the GL scene
void HandleSendKeys(); // Optional callback to handle key press from external source (e.g. stdin by default)
void HandleExternalGUISignals(); // Callback to handle signals from external GUIs
bool HasExternalGUISignals() const; // Returns whether there are currently pending signals from external GUIs to be handled
void ResizeScene(int32_t width, int32_t height); // Callback when GL window is resized
int32_t InitDisplay(bool initFailure = false); // Callback to initialize the GL Display (to be called in StartDisplay)
void ExitDisplay(); // Callback to clean up the GL Display
Expand All @@ -160,6 +163,8 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings
private:
bool HandleExternalGUIKeys(); // Returns whether keys were handled, config changes are not handled
};
} // namespace o2::gpu

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()

int32_t retVal = 0;
while (!glfwWindowShouldClose(mWindow)) {
HandleSendKeys();
HandleExternalGUISignals();
if (DrawGLScene()) {
fprintf(stderr, "Error drawing GL scene\n");
retVal = 1;
Expand Down Expand Up @@ -398,11 +398,6 @@ void GPUDisplayFrontendGlfw::SetVSync(bool enable)

bool GPUDisplayFrontendGlfw::canSetVSync() { return backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL; }

bool GPUDisplayFrontendGlfw::EnableSendKey()
{
return true;
}

float GPUDisplayFrontendGlfw::getRefreshRate()
{
GLFWmonitor* monitor = glfwGetWindowMonitor(mWindow) ? glfwGetWindowMonitor(mWindow) : glfwGetPrimaryMonitor(); // Monitor of a windowed window is not known, use the primary one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
void ToggleMaximized(bool set) override;
void SetVSync(bool enable) override;
void OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton = true) override;
bool EnableSendKey() override;
void getSize(int32_t& width, int32_t& height) override;
float getDisplayScale() const override { return mScale; }
float getRefreshRate() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void GPUDisplayFrontendGlut::displayFunc() // TODO: Functions should be lambdas,

void GPUDisplayFrontendGlut::glutLoopFunc()
{
me->HandleSendKeys();
me->HandleExternalGUISignals();
displayFunc();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ int32_t GPUDisplayFrontendNone::FrontendMain()
return 1;
}
do {
HandleExternalGUISignals();
DrawGLScene();
waitForFPSLimit();
HandleSendKeys();
} while (mDisplayControl != 2);
return 0;
}
Loading
Loading