Skip to content

Commit c5085c4

Browse files
committed
GPU Display: Vulkan backend seems not to work with imGui, use native glfw instead for Vulkan
1 parent 0be5b84 commit c5085c4

6 files changed

Lines changed: 45 additions & 32 deletions

File tree

GPU/GPUTracking/Definitions/GPULogging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{ \
6262
fprintf(stderr, string "\n", ##__VA_ARGS__); \
6363
}
64-
#define GPUError(...) GPUAlarm(__VA_ARGS__)
64+
#define GPUAlarm(...) GPUWarning(__VA_ARGS__)
6565
#define GPUError(...) GPUWarning(__VA_ARGS__)
6666
#ifdef GPUCA_NOCOMPAT
6767
#define GPUFatal(string, ...) \

GPU/GPUTracking/Standalone/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ endif()
248248

249249
if(BUILD_EVENT_DISPLAY)
250250
if(CONFIG_GL3W)
251-
target_sources(GPUTracking PRIVATE ${GPUTRACKING_DIR}/display/3rdparty/gl3w.c)
251+
target_sources(GPUTrackingDisplay PRIVATE ${GPUTRACKING_DIR}/display/3rdparty/gl3w.c)
252252
endif()
253253
target_sources(GPUTracking PRIVATE ${GPUTRACKING_DIR}/display/3rdparty/HandMadeMath/HandMadeMathImpl.cxx)
254254
target_include_directories(GPUTracking SYSTEM PUBLIC ${GPUTRACKING_DIR}/display/3rdparty)

GPU/GPUTracking/display/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "Standalone")
154154
target_compile_definitions(${targetName} PRIVATE GPUCA_BUILD_EVENT_DISPLAY_GLFW)
155155
endif()
156156
if(CONFIG_GL3W)
157-
target_compile_definitions(GPUTracking PUBLIC GPUCA_DISPLAY_GL3W)
157+
target_compile_definitions(${targetName} PRIVATE GPUCA_DISPLAY_GL3W)
158158
else()
159159
target_link_libraries(${targetName} PRIVATE ${GLEW_LIBRARIES})
160160
endif()

GPU/GPUTracking/display/GPUDisplayBackendVulkan.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void GPUDisplayBackendVulkan::createDevice()
447447
vk::FormatProperties depth32FormatProperties = mPhysicalDevice.getFormatProperties(vk::Format::eD32Sfloat);
448448
vk::FormatProperties depth64FormatProperties = mPhysicalDevice.getFormatProperties(vk::Format::eD32SfloatS8Uint);
449449
vk::FormatProperties formatProperties = mPhysicalDevice.getFormatProperties(mSurfaceFormat.format);
450-
GPUInfo("Using physicak Vulkan device %s", deviceProperties.deviceName.data());
450+
GPUInfo("Using physical Vulkan device %s", deviceProperties.deviceName.data());
451451
mMaxMSAAsupported = getMaxUsableSampleCount(deviceProperties);
452452
mZSupported = (bool)(depth32FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);
453453
mStencilSupported = (bool)(depth64FormatProperties.optimalTilingFeatures & vk::FormatFeatureFlagBits::eDepthStencilAttachment);

GPU/GPUTracking/display/GPUDisplayFrontendGlfw.cxx

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,17 @@ void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window, double x, do
238238

239239
void GPUDisplayFrontendGlfw::resize_callback(GLFWwindow* window, int width, int height) { me->ResizeScene(width, height); }
240240

241+
#ifdef GPUCA_O2_LIB
241242
void GPUDisplayFrontendGlfw::DisplayLoop()
242243
{
243-
#ifdef GPUCA_O2_LIB
244244
ImGui::SetNextWindowPos(ImVec2(0, 0));
245245
ImGui::SetNextWindowSize(ImVec2(me->mDisplayWidth, me->mDisplayHeight));
246246
ImGui::SetNextWindowBgAlpha(0.f);
247247
ImGui::Begin("Console", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
248-
#endif
249248
me->DrawGLScene();
250-
#ifdef GPUCA_O2_LIB
251249
ImGui::End();
252-
#endif
253250
}
251+
#endif
254252

255253
int GPUDisplayFrontendGlfw::FrontendMain()
256254
{
@@ -271,6 +269,9 @@ int GPUDisplayFrontendGlfw::FrontendMain()
271269
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_MIN_VERSION_MINOR);
272270
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 0);
273271
glfwWindowHint(GLFW_OPENGL_PROFILE, mBackend->CoreProfile() ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
272+
#ifdef GPUCA_O2_LIB
273+
mUseIMGui = true;
274+
#endif
274275
}
275276
mWindow = glfwCreateWindow(INIT_WIDTH, INIT_HEIGHT, DISPLAY_WINDOW_NAME, nullptr, nullptr);
276277
if (!mWindow) {
@@ -288,7 +289,9 @@ int GPUDisplayFrontendGlfw::FrontendMain()
288289
glfwSetScrollCallback(mWindow, scroll_callback);
289290
glfwSetCursorPosCallback(mWindow, cursorPos_callback);
290291
glfwSetWindowSizeCallback(mWindow, resize_callback);
291-
glfwSwapInterval(1);
292+
if (backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL) {
293+
glfwSwapInterval(1);
294+
}
292295

293296
pthread_mutex_lock(&mSemLockExit);
294297
mGlfwRunning = true;
@@ -300,16 +303,18 @@ int GPUDisplayFrontendGlfw::FrontendMain()
300303
}
301304

302305
#if defined(GPUCA_O2_LIB) && !defined(GPUCA_DISPLAY_GL3W)
303-
if (gl3wInit()) {
306+
if (mUseIMGui && gl3wInit()) {
304307
fprintf(stderr, "Error initializing gl3w (2)\n");
305308
return (-1); // Hack: We have to initialize gl3w as well, as the DebugGUI uses it.
306309
}
307310
#endif
308311

309312
#ifdef GPUCA_O2_LIB
310-
mCanDrawText = 2;
311-
if (drawTextFontSize() == 0) {
312-
drawTextFontSize() = 12;
313+
if (mUseIMGui) {
314+
mCanDrawText = 2;
315+
if (drawTextFontSize() == 0) {
316+
drawTextFontSize() = 12;
317+
}
313318
}
314319
#endif
315320

@@ -319,28 +324,33 @@ int GPUDisplayFrontendGlfw::FrontendMain()
319324
}
320325

321326
#ifdef GPUCA_O2_LIB
322-
ImGui_ImplGlfwGL3_Init(mWindow, false);
323-
while (o2::framework::pollGUI(mWindow, DisplayLoop)) {
324-
}
325-
#else
326-
while (!glfwWindowShouldClose(mWindow)) {
327-
HandleSendKey();
328-
if (DrawGLScene()) {
329-
fprintf(stderr, "Error drawing GL scene\n");
330-
return (1);
327+
if (mUseIMGui) {
328+
ImGui_ImplGlfwGL3_Init(mWindow, false);
329+
while (o2::framework::pollGUI(mWindow, DisplayLoop)) {
331330
}
332-
if (backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL) {
333-
glfwSwapBuffers(mWindow);
331+
} else
332+
#endif
333+
{
334+
while (!glfwWindowShouldClose(mWindow)) {
335+
HandleSendKey();
336+
if (DrawGLScene()) {
337+
fprintf(stderr, "Error drawing GL scene\n");
338+
return (1);
339+
}
340+
if (backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL) {
341+
glfwSwapBuffers(mWindow);
342+
}
343+
glfwPollEvents();
334344
}
335-
glfwPollEvents();
336345
}
337-
#endif
338346

339347
ExitDisplay();
340348
mDisplayControl = 2;
341349
pthread_mutex_lock(&mSemLockExit);
342350
#ifdef GPUCA_O2_LIB
343-
ImGui_ImplGlfwGL3_Shutdown();
351+
if (mUseIMGui) {
352+
ImGui_ImplGlfwGL3_Shutdown();
353+
}
344354
#endif
345355
glfwDestroyWindow(mWindow);
346356
glfwTerminate();
@@ -365,12 +375,14 @@ void GPUDisplayFrontendGlfw::DisplayExit()
365375
void GPUDisplayFrontendGlfw::OpenGLPrint(const char* s, float x, float y, float r, float g, float b, float a, bool fromBotton)
366376
{
367377
#ifdef GPUCA_O2_LIB
368-
if (fromBotton) {
369-
y = ImGui::GetWindowHeight() - y;
378+
if (mUseIMGui) {
379+
if (fromBotton) {
380+
y = ImGui::GetWindowHeight() - y;
381+
}
382+
y -= 20;
383+
ImGui::SetCursorPos(ImVec2(x, y));
384+
ImGui::TextColored(ImVec4(r, g, b, a), "%s", s);
370385
}
371-
y -= 20;
372-
ImGui::SetCursorPos(ImVec2(x, y));
373-
ImGui::TextColored(ImVec4(r, g, b, a), "%s", s);
374386
#endif
375387
}
376388

GPU/GPUTracking/display/GPUDisplayFrontendGlfw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
6363
int mWindowHeight = INIT_HEIGHT;
6464
char mKeyDownMap[256] = {0};
6565
unsigned char mLastKeyDown = 0;
66+
bool mUseIMGui = false;
6667
};
6768
} // namespace GPUCA_NAMESPACE::gpu
6869

0 commit comments

Comments
 (0)