compiles but bgfx still has that vulkan regression

This commit is contained in:
lachrymaLF 2024-06-24 11:25:25 -04:00
parent 49b92b83bd
commit b43765b2c7
5 changed files with 45 additions and 40 deletions

View file

@ -1,7 +1,7 @@
# CMakeList.txt : CMake project for Keishiki, include source and define # CMakeList.txt : CMake project for Keishiki, include source and define
# project specific logic here. # project specific logic here.
# #
cmake_minimum_required (VERSION 3.12) cmake_minimum_required (VERSION 3.16)
project("Main") project("Main")
@ -10,7 +10,7 @@ file(GLOB IMGUI_SRC ${PROJECT_SOURCE_DIR}/ext/imgui/*.cpp)
file(GLOB IMPLOT_SRC ${PROJECT_SOURCE_DIR}/ext/implot/*.cpp) file(GLOB IMPLOT_SRC ${PROJECT_SOURCE_DIR}/ext/implot/*.cpp)
add_executable (Keishiki ${IMGUI_SRC} ${IMPLOT_SRC} add_executable (Keishiki ${IMGUI_SRC} ${IMPLOT_SRC}
"ext/imgui_impl_bgfx.cpp" "ext/imgui/backends/imgui_impl_sdl2.cpp" "ext/imgui/misc/cpp/imgui_stdlib.cpp" "ext/imgui_impl_bgfx.cpp" "ext/imgui/backends/imgui_impl_sdl3.cpp" "ext/imgui/misc/cpp/imgui_stdlib.cpp"
${SRC_FILES}) ${SRC_FILES})
@ -19,6 +19,8 @@ set_property(TARGET Keishiki PROPERTY CXX_STANDARD 23)
include_directories ("include" "include/ext" "ext/imgui" "ext/implot" "ext/plf_colony") include_directories ("include" "include/ext" "ext/imgui" "ext/implot" "ext/plf_colony")
add_subdirectory("ext/freetype") add_subdirectory("ext/freetype")
add_compile_definitions(WL_EGL_PLATFORM)
add_subdirectory("ext/bgfx") add_subdirectory("ext/bgfx")
add_compile_definitions(IMGUI_DEFINE_MATH_OPERATORS) add_compile_definitions(IMGUI_DEFINE_MATH_OPERATORS)
@ -40,6 +42,9 @@ elseif (APPLE)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL2::SDL2) target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL2::SDL2)
else () else ()
find_package(SDL2 REQUIRED) find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared)
target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL2::SDL2 SDL2::SDL2main) find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR})
find_package(Wayland REQUIRED Egl)
target_link_libraries (Keishiki PRIVATE freetype bgfx bx SDL3::SDL3 ${Wayland_LIBRARIES})
endif () endif ()

View file

@ -2,14 +2,14 @@
#include "Graphics.h" #include "Graphics.h"
#include "UI.h" #include "UI.h"
#include <SDL.h> #include <wayland-egl.h>
#include <SDL_main.h> #include <SDL3/SDL.h>
#include <SDL_timer.h> #include <SDL3/SDL_timer.h>
#include <SDL_syswm.h>
#include <bgfx/bgfx.h> #include <bgfx/bgfx.h>
#include <bgfx/platform.h> #include <bgfx/platform.h>
#include "backends/imgui_impl_sdl2.h" #include "backends/imgui_impl_sdl3.h"
#include <imgui.h> #include <imgui.h>
namespace { namespace {
@ -27,10 +27,8 @@ namespace K {
} }
app_state.window = SDL_CreateWindow("Keishiki", app_state.window = SDL_CreateWindow("Keishiki",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
app_state.window_width, app_state.window_height, app_state.window_width, app_state.window_height,
SDL_WINDOW_SHOWN); 0);
if (app_state.window == nullptr) { if (app_state.window == nullptr) {
LogError(SDL_GetError()); LogError(SDL_GetError());
@ -43,22 +41,25 @@ namespace K {
bgfxInit.resolution.height = app_state.window_height; bgfxInit.resolution.height = app_state.window_height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC; bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
#if !BX_PLATFORM_EMSCRIPTEN
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo(app_state.window, &wmi)) {
LogError(SDL_GetError());
}
#endif
#if BX_PLATFORM_WINDOWS #if BX_PLATFORM_WINDOWS
bgfxInit.platformData.nwh = wmi.info.win.window; bgfxInit.platformData.nwh = SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
#elif BX_PLATFORM_OSX #elif BX_PLATFORM_OSX
bgfxInit.platformData.nwh = wmi.info.cocoa.window; bgfxInit.platformData.nwh = SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
bgfx::renderFrame(); bgfx::renderFrame();
#elif BX_PLATFORM_LINUX #elif BX_PLATFORM_LINUX
bgfxInit.platformData.ndt = wmi.info.x11.display; if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
bgfxInit.platformData.nwh = (void*)(uintptr_t)wmi.info.x11.window; bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
bgfxInit.platformData.nwh = (void*)SDL_GetNumberProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
}
else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
bgfxInit.platformData.type = bgfx::NativeWindowHandleType::Wayland;
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
bgfxInit.platformData.nwh = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER, NULL);
if (!bgfxInit.platformData.nwh) {
bgfxInit.platformData.nwh = wl_egl_window_create((struct wl_surface *)SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL), app_state.window_width, app_state.window_height);
SDL_SetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER, (void*)(uintptr_t)bgfxInit.platformData.nwh);
}
}
#elif BX_PLATFORM_EMSCRIPTEN #elif BX_PLATFORM_EMSCRIPTEN
bgfxInit.platformData.nwh = (void*)"#canvas"; bgfxInit.platformData.nwh = (void*)"#canvas";
#endif #endif
@ -91,8 +92,7 @@ namespace K {
state.current_frame = 0; state.current_frame = 0;
state.fps = 30.0f; state.fps = 30.0f;
state.frame_max = 200; state.frame_max = 200;
// state.plugboard.in = Plugboard::K_P_CompositionIn{};
// state.plugboard.out = Plugboard::K_P_CompositionOut{};
K::UI::SetupViewport(state); K::UI::SetupViewport(state);
return true; return true;
@ -114,23 +114,23 @@ namespace K {
stat->cpuTimerFreq / stat->cpuTimeFrame); stat->cpuTimerFreq / stat->cpuTimeFrame);
bgfx::dbgTextPrintf(0, app_state.window_height/16 - 7, 0xf8, bgfx::dbgTextPrintf(0, app_state.window_height/16 - 7, 0xf8,
" Project Keishiki :: %s :: Build %s %s :: SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s", " Project Keishiki :: %s :: Build %s %s :: SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s",
BX_COMPILER_NAME, __DATE__, __TIME__, SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BX_COMPILER_NAME, __DATE__, __TIME__, SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION,
BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType())); BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
app_state.bgfx_frame = bgfx::frame(); app_state.bgfx_frame = bgfx::frame();
} }
void Run() { void Run() {
app_state.init_time = SDL_GetTicks64(); app_state.init_time = SDL_GetTicks();
app_state.last_time = app_state.init_time; app_state.last_time = app_state.init_time;
while (app_state.running.load()) { while (app_state.running.load()) {
app_state.current_time = SDL_GetTicks64(); app_state.current_time = SDL_GetTicks();
app_state.delta_t = app_state.current_time - app_state.last_time; app_state.delta_t = app_state.current_time - app_state.last_time;
for (SDL_Event current_event; SDL_PollEvent(&current_event) != 0;) { for (SDL_Event current_event; SDL_PollEvent(&current_event) != 0;) {
ImGui_ImplSDL2_ProcessEvent(&current_event); ImGui_ImplSDL3_ProcessEvent(&current_event);
if (current_event.type == SDL_QUIT) { if (current_event.type == SDL_EVENT_QUIT) {
app_state.running.store(false); app_state.running.store(false);
break; break;
} }

View file

@ -353,7 +353,7 @@ namespace K::Plugboard {
} }
T_Map<T_Count>::type FetchCompositionInAppTicks(const CompState& s, const CompositionIn& n) { T_Map<T_Count>::type FetchCompositionInAppTicks(const CompState& s, const CompositionIn& n) {
return T_Map<T_Count>::type{ static_cast<f32>(SDL_GetTicks64()) }; return T_Map<T_Count>::type{ static_cast<f32>(SDL_GetTicks()) };
} }
void Plugboard::RecollectChains() { void Plugboard::RecollectChains() {

View file

@ -6,7 +6,7 @@
#include <imgui_internal.h> #include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h> #include <misc/cpp/imgui_stdlib.h>
#include "backends/imgui_impl_sdl2.h" #include "backends/imgui_impl_sdl3.h"
#include "imgui_impl_bgfx.h" #include "imgui_impl_bgfx.h"
#include <implot.h> #include <implot.h>
@ -1804,7 +1804,7 @@ namespace K::UI {
} }
void Draw(u32 frame, CompState& s) { void Draw(u32 frame, CompState& s) {
ImGui_ImplSDL2_NewFrame(); ImGui_ImplSDL3_NewFrame();
ImGui_Implbgfx_NewFrame(); ImGui_Implbgfx_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
@ -1840,16 +1840,16 @@ namespace K::UI {
case bgfx::RendererType::Noop: case bgfx::RendererType::Noop:
case bgfx::RendererType::Direct3D11: case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12: case bgfx::RendererType::Direct3D12:
ImGui_ImplSDL2_InitForD3D(window); ImGui_ImplSDL3_InitForD3D(window);
break; break;
case bgfx::RendererType::Metal: case bgfx::RendererType::Metal:
ImGui_ImplSDL2_InitForMetal(window); ImGui_ImplSDL3_InitForMetal(window);
break; break;
case bgfx::RendererType::OpenGL: case bgfx::RendererType::OpenGL:
ImGui_ImplSDL2_InitForOpenGL(window, nullptr); ImGui_ImplSDL3_InitForOpenGL(window, nullptr);
break; break;
case bgfx::RendererType::Vulkan: case bgfx::RendererType::Vulkan:
ImGui_ImplSDL2_InitForVulkan(window); ImGui_ImplSDL3_InitForVulkan(window);
break; break;
default: default:
LogError("Unsupported Renderer"); LogError("Unsupported Renderer");
@ -1865,7 +1865,7 @@ namespace K::UI {
DestroyViewport(s); DestroyViewport(s);
ImGui_Implbgfx_Shutdown(); ImGui_Implbgfx_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL3_Shutdown();
ImPlot::DestroyContext(); ImPlot::DestroyContext();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }

View file

@ -2,7 +2,7 @@
#include "Common.h" #include "Common.h"
#include <Resource.h> #include <Resource.h>
#include <SDL.h> #include <SDL3/SDL.h>
#include <numbers> #include <numbers>
#include <cmath> #include <cmath>