Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-small-memory-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
coco875 committed Jan 13, 2025
2 parents 65253fc + 31df12c commit e0fe67a
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 106 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build-cmake --config Release --parallel 10
env:
CC: gcc-10
CXX: g++-10
CC: gcc-12
CXX: g++-12
- name: Upload build
uses: actions/upload-artifact@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions cmake/dependencies/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ if (CMAKE_GENERATOR MATCHES "Visual Studio")
endif()

#=================== ImGui ===================
set(sdl_gamepad_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/sdl-gamepad-fix.patch)
set(imgui_fixes_and_config_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/imgui-fixes-and-config.patch)

# Applies the patch or checks if it has already been applied successfully previously. Will error otherwise.
set(sdl_apply_patch_if_needed git apply ${sdl_gamepad_patch_file} ${git_hide_output} || git apply --reverse --check ${sdl_gamepad_patch_file})
set(imgui_apply_patch_if_needed git apply ${imgui_fixes_and_config_patch_file} ${git_hide_output} || git apply --reverse --check ${imgui_fixes_and_config_patch_file})
FetchContent_Declare(
ImGui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90.6-docking
PATCH_COMMAND ${sdl_apply_patch_if_needed}
GIT_TAG v1.91.6-docking
PATCH_COMMAND ${imgui_apply_patch_if_needed}
)
FetchContent_MakeAvailable(ImGui)
list(APPEND ADDITIONAL_LIB_INCLUDES ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends)
Expand Down
59 changes: 59 additions & 0 deletions cmake/dependencies/patches/imgui-fixes-and-config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From 7cd9b89560b66b992db9fd0e620c2d28ad9a9645 Mon Sep 17 00:00:00 2001
From: briaguya <[email protected]>
Date: Fri, 10 Jan 2025 04:48:50 -0500
Subject: [PATCH 1/2] sdl gamepad fix

---
backends/imgui_impl_sdl2.cpp | 3 ---
1 file changed, 3 deletions(-)

diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp
index 23f12796..a7fef045 100644
--- a/backends/imgui_impl_sdl2.cpp
+++ b/backends/imgui_impl_sdl2.cpp
@@ -816,9 +816,6 @@ static void ImGui_ImplSDL2_UpdateGamepads()
bd->WantUpdateGamepadsList = false;
}

- // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
- if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
- return;
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
if (bd->Gamepads.Size == 0)
return;
--
2.47.1


From 635226a311071e80c22e0c58c9cb5c9d950d2e17 Mon Sep 17 00:00:00 2001
From: briaguya <[email protected]>
Date: Fri, 10 Jan 2025 04:52:36 -0500
Subject: [PATCH 2/2] add config stuff

---
imconfig.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/imconfig.h b/imconfig.h
index 8f8bc3b9..cc578e3f 100644
--- a/imconfig.h
+++ b/imconfig.h
@@ -111,7 +111,7 @@
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- ...Or use Dear ImGui's own very basic math operators.
-//#define IMGUI_DEFINE_MATH_OPERATORS
+#define IMGUI_DEFINE_MATH_OPERATORS

//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
@@ -140,3 +140,6 @@ namespace ImGui
void MyFunction(const char* name, MyMatrix44* mtx);
}
*/
+
+// handle https://github.com/ocornut/imgui/issues/1641 the old way
+#define ImTextureID void*
--
2.47.1

17 changes: 0 additions & 17 deletions cmake/dependencies/patches/sdl-gamepad-fix.patch

This file was deleted.

3 changes: 0 additions & 3 deletions src/controller/controldeck/ControlDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include "controller/controldevice/controller/Controller.h"
#include "utils/StringHelper.h"
#include "public/bridge/consolevariablebridge.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui.h>
#include "controller/deviceindex/ShipDeviceIndexMappingManager.h"
#include "controller/controldevice/controller/mapping/mouse/WheelHandler.h"
Expand Down
3 changes: 0 additions & 3 deletions src/controller/deviceindex/ControllerDisconnectedWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

#include "stdint.h"
#include "window/gui/GuiWindow.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui.h>
#include <unordered_map>
#include <string>
Expand Down
3 changes: 0 additions & 3 deletions src/controller/deviceindex/ControllerReorderingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

#include "stdint.h"
#include "window/gui/GuiWindow.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui.h>
#include <unordered_map>
#include <string>
Expand Down
3 changes: 0 additions & 3 deletions src/debug/Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <vector>
#include <functional>
#include <map>
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui.h>

namespace Ship {
Expand Down
32 changes: 32 additions & 0 deletions src/graphic/Fast3D/Fast3dWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,38 @@ void Fast3dWindow::StartFrame() {
}

void Fast3dWindow::EndFrame() {
gfx_end_frame();
}

bool Fast3dWindow::IsFrameReady() {
return mWindowManagerApi->is_frame_ready();
}

bool Fast3dWindow::DrawAndRunGraphicsCommands(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtxReplacements) {
std::shared_ptr<Window> wnd = Ship::Context::GetInstance()->GetWindow();

// Skip dropped frames
if (!wnd->IsFrameReady()) {
return false;
}

auto gui = wnd->GetGui();
// Setup of the backend frames and draw initial Window and GUI menus
gui->StartDraw();
// Setup game framebuffers to match available window space
gfx_start_frame();
// Execute the games gfx commands
gfx_run(commands, mtxReplacements);
// Renders the game frame buffer to the final window and finishes the GUI
gui->EndDraw();
// Finalize swap buffers
gfx_end_frame();

return true;
}

void Fast3dWindow::HandleEvents() {
mWindowManagerApi->handle_events();
}

void Fast3dWindow::SetCursorVisibility(bool visible) {
Expand Down
5 changes: 5 additions & 0 deletions src/graphic/Fast3D/Fast3dWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "public/bridge/gfxbridge.h"
#include "controller/controldevice/controller/mapping/keyboard/KeyboardScancodes.h"

union Gfx;

namespace Fast {
class Fast3dWindow : public Ship::Window {
public:
Expand All @@ -16,6 +18,8 @@ class Fast3dWindow : public Ship::Window {
void Close() override;
void StartFrame() override;
void EndFrame() override;
bool IsFrameReady() override;
void HandleEvents() override;
void SetCursorVisibility(bool visible) override;
uint32_t GetWidth() override;
uint32_t GetHeight() override;
Expand Down Expand Up @@ -46,6 +50,7 @@ class Fast3dWindow : public Ship::Window {
void SetTextureFilter(FilteringMode filteringMode);
void SetRendererUCode(UcodeHandlers ucode);
void EnableSRGBMode();
bool DrawAndRunGraphicsCommands(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtxReplacements);

protected:
static bool KeyDown(int32_t scancode);
Expand Down
3 changes: 0 additions & 3 deletions src/graphic/Fast3D/gfx_direct3d11.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#define GFX_DIRECT3D11_H

#include "gfx_rendering_api.h"
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui.h>

extern struct GfxRenderingAPI gfx_direct3d11_api;
Expand Down
4 changes: 2 additions & 2 deletions src/graphic/Fast3D/gfx_dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static uint64_t qpc_to_100ns(uint64_t qpc) {
qpc % dxgi.qpc_freq * _100NANOSECONDS_IN_SECOND / dxgi.qpc_freq;
}

static bool gfx_dxgi_start_frame() {
static bool gfx_dxgi_is_frame_ready() {
DXGI_FRAME_STATISTICS stats;
if (dxgi.swap_chain->GetFrameStatistics(&stats) == S_OK &&
(stats.SyncRefreshCount != 0 || stats.SyncQPCTime.QuadPart != 0ULL)) {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = { gfx_dxgi_init,
gfx_dxgi_is_mouse_captured,
gfx_dxgi_get_dimensions,
gfx_dxgi_handle_events,
gfx_dxgi_start_frame,
gfx_dxgi_is_frame_ready,
gfx_dxgi_swap_buffers_begin,
gfx_dxgi_swap_buffers_end,
gfx_dxgi_get_time,
Expand Down
4 changes: 1 addition & 3 deletions src/graphic/Fast3D/gfx_metal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,11 @@ bool Metal_Init(SDL_Renderer* renderer) {

static void gfx_metal_setup_screen_framebuffer(uint32_t width, uint32_t height);

void Metal_SetupFrame(SDL_Renderer* renderer) {
void Metal_NewFrame(SDL_Renderer* renderer) {
int width, height;
SDL_GetRendererOutputSize(renderer, &width, &height);
gfx_metal_setup_screen_framebuffer(width, height);
}

void Metal_NewFrame(SDL_Renderer* renderer) {
MTL::RenderPassDescriptor* current_render_pass = mctx.framebuffers[0].render_pass_descriptor;
ImGui_ImplMetal_NewFrame(current_render_pass);
}
Expand Down
1 change: 0 additions & 1 deletion src/graphic/Fast3D/gfx_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ImTextureID gfx_metal_get_texture_by_id(int id);
bool Metal_IsSupported();

bool Metal_Init(SDL_Renderer* renderer);
void Metal_SetupFrame(SDL_Renderer* renderer);
void Metal_NewFrame(SDL_Renderer* renderer);
void Metal_SetupFloatingFrame();
void Metal_RenderDrawData(ImDrawData* draw_data);
Expand Down
31 changes: 12 additions & 19 deletions src/graphic/Fast3D/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ static int game_framebuffer_msaa_resolved;

uint32_t gfx_msaa_level = 1;

static bool dropped_frame;

static const std::unordered_map<Mtx*, MtxF>* current_mtx_replacements;

static float buf_vbo[MAX_BUFFERED * (32 * 3)]; // 3 vertices in a triangle and 32 floats per vtx
Expand Down Expand Up @@ -4123,8 +4121,15 @@ struct GfxRenderingAPI* gfx_get_current_rendering_api() {
return gfx_rapi;
}

void gfx_start_frame() {
void gfx_handle_window_events() {
gfx_wapi->handle_events();
}

bool gfx_is_frame_ready() {
return gfx_wapi->is_frame_ready();
}

void gfx_start_frame() {
gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height,
&gfx_current_window_position_x, &gfx_current_window_position_y);
if (gfx_current_dimensions.height == 0) {
Expand Down Expand Up @@ -4184,20 +4189,11 @@ void gfx_start_frame() {
GfxExecStack g_exec_stack = {};

void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacements) {
Ship::Context::GetInstance()->GetWindow()->GetGui()->SetupRendererFrame();

gfx_sp_reset();

get_pixel_depth_pending.clear();
get_pixel_depth_cached.clear();

if (!gfx_wapi->start_frame()) {
dropped_frame = true;
Ship::Context::GetInstance()->GetWindow()->GetGui()->Draw();
return;
}
dropped_frame = false;

current_mtx_replacements = &mtx_replacements;

gfx_rapi->update_framebuffer_parameters(0, gfx_current_window_dimensions.width,
Expand Down Expand Up @@ -4261,16 +4257,13 @@ void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacemen

assert(0 && "active framebuffer was never reset back to original");
}
Ship::Context::GetInstance()->GetWindow()->GetGui()->Draw();
gfx_rapi->end_frame();
gfx_wapi->swap_buffers_begin();
}

void gfx_end_frame() {
if (!dropped_frame) {
gfx_rapi->finish_render();
gfx_wapi->swap_buffers_end();
}
gfx_rapi->end_frame();
gfx_wapi->swap_buffers_begin();
gfx_rapi->finish_render();
gfx_wapi->swap_buffers_end();
}

void gfx_set_target_ucode(UcodeHandlers ucode) {
Expand Down
2 changes: 2 additions & 0 deletions src/graphic/Fast3D/gfx_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ void gfx_start_frame();

// Since this function is "exposted" to the games, it needs to take a normal Gfx
void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacements);
void gfx_handle_window_events();
bool gfx_is_frame_ready();
void gfx_end_frame();
void gfx_set_target_ucode(UcodeHandlers ucode);
void gfx_set_target_fps(int);
Expand Down
4 changes: 2 additions & 2 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ static void gfx_sdl_handle_events() {
}
}

static bool gfx_sdl_start_frame() {
static bool gfx_sdl_is_frame_ready() {
return true;
}

Expand Down Expand Up @@ -709,7 +709,7 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init,
gfx_sdl_is_mouse_captured,
gfx_sdl_get_dimensions,
gfx_sdl_handle_events,
gfx_sdl_start_frame,
gfx_sdl_is_frame_ready,
gfx_sdl_swap_buffers_begin,
gfx_sdl_swap_buffers_end,
gfx_sdl_get_time,
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/Fast3D/gfx_window_manager_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct GfxWindowManagerAPI {
bool (*is_mouse_captured)();
void (*get_dimensions)(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY);
void (*handle_events)();
bool (*start_frame)();
bool (*is_frame_ready)();
void (*swap_buffers_begin)();
void (*swap_buffers_end)();
double (*get_time)(); // For debug
Expand Down
2 changes: 1 addition & 1 deletion src/resource/type/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ size_t Texture::GetPointerSize() {

Texture::~Texture() {
if (ImageData != nullptr) {
delete ImageData;
delete[] ImageData;
}
}
} // namespace Fast
2 changes: 2 additions & 0 deletions src/window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Window {
virtual void Close() = 0;
virtual void StartFrame() = 0;
virtual void EndFrame() = 0;
virtual bool IsFrameReady() = 0;
virtual void HandleEvents() = 0;
virtual void SetCursorVisibility(bool visible) = 0;
virtual uint32_t GetWidth() = 0;
virtual uint32_t GetHeight() = 0;
Expand Down
Loading

0 comments on commit e0fe67a

Please sign in to comment.