From 50970df6450cb4d68e4edd831fccb9f4b5d88392 Mon Sep 17 00:00:00 2001 From: Jeffrey Crowell Date: Fri, 6 Mar 2026 22:22:28 -0800 Subject: [PATCH] Fix build on main for mac/linux (#40) * fix builds, removing COMPOUND_LITERAL around GXColor use aurora's aurora_get_stats add aurora::gd to libraries linked to fixup linkage/symbol hiding on mac/linux squashed * aurora stat changes * fix --------- Co-authored-by: Jasper St. Pierre Co-authored-by: TakaRikka --- CMakeLists.txt | 19 ++++++++- hide_new_delete.lds | 8 ++++ libs/JSystem/src/J3DU/J3DUClipper.cpp | 1 + libs/JSystem/src/JFramework/JFWDisplay.cpp | 20 ++++++++++ libs/JSystem/src/JGadget/binary.cpp | 1 + libs/JSystem/src/JStage/JSGAmbientLight.cpp | 2 +- libs/JSystem/src/JStage/JSGFog.cpp | 2 +- libs/JSystem/src/JStage/JSGLight.cpp | 2 +- libs/JSystem/src/JUtility/JUTAssert.cpp | 1 + src/dusk/imgui/debug_overlay.cpp | 43 ++++++++++----------- src/dusk/stubs.cpp | 4 +- 11 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 hide_new_delete.lds diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bcf65d88a..6041b48622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,10 +67,27 @@ target_include_directories(game_debug PUBLIC extern/aurora/include/dolphin ${CMAKE_SOURCE_DIR}/build/${DUSK_TP_VERSION}/include build/${DUSK_TP_VERSION}/include) -target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::si aurora::vi aurora::pad aurora::mtx aurora::os) +target_link_libraries(game_debug PUBLIC aurora::core aurora::gx aurora::gd aurora::si aurora::vi aurora::pad aurora::mtx aurora::os) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) add_library(game SHARED ${DOLZEL_FILES} ${Z2AUDIOLIB_FILES} ${SSYSTEM_FILES} ${JSYSTEM_FILES} ${REL_FILES} ${DUSK_FILES}) + +# Hide global operator new/delete overrides from the dynamic symbol table. +# Without this, other dylibs (e.g. Apple's AGX GPU driver) resolve these symbols +# from libgame and crash when they encounter JKRHeap-managed memory. +if (APPLE) + target_link_options(game PRIVATE + "LINKER:-unexported_symbol,__ZdlPv" # operator delete(void*) + "LINKER:-unexported_symbol,__ZdaPv" # operator delete[](void*) + "LINKER:-unexported_symbol,__Znwm" # operator new(size_t) + "LINKER:-unexported_symbol,__Znam" # operator new[](size_t) + ) +elseif (CMAKE_SYSTEM_NAME STREQUAL Linux) + target_link_options(game PRIVATE + "LINKER:--version-script,${CMAKE_SOURCE_DIR}/hide_new_delete.lds" + ) +endif () + target_link_libraries(game PRIVATE game_debug) target_compile_definitions(game PRIVATE TARGET_PC VERSION=0 NDEBUG=1 NDEBUG_DEFINED=1 DEBUG_DEFINED=0) diff --git a/hide_new_delete.lds b/hide_new_delete.lds new file mode 100644 index 0000000000..cb8db907ee --- /dev/null +++ b/hide_new_delete.lds @@ -0,0 +1,8 @@ +{ + global: *; + local: + _ZdlPv; + _ZdaPv; + _Znwm; + _Znam; +}; diff --git a/libs/JSystem/src/J3DU/J3DUClipper.cpp b/libs/JSystem/src/J3DU/J3DUClipper.cpp index 38a27dd8ff..56803c50ff 100644 --- a/libs/JSystem/src/J3DU/J3DUClipper.cpp +++ b/libs/JSystem/src/J3DU/J3DUClipper.cpp @@ -2,6 +2,7 @@ #include "JSystem/J3DU/J3DUClipper.h" #include +#include "global.h" void J3DUClipper::init() { mNear = 1.0f; diff --git a/libs/JSystem/src/JFramework/JFWDisplay.cpp b/libs/JSystem/src/JFramework/JFWDisplay.cpp index 4041009ee7..67da53658c 100644 --- a/libs/JSystem/src/JFramework/JFWDisplay.cpp +++ b/libs/JSystem/src/JFramework/JFWDisplay.cpp @@ -5,6 +5,7 @@ #include #include "JSystem/J2DGraph/J2DOrthoGraph.h" #include "JSystem/JFramework/JFWDisplay.h" +#include "JSystem/JKernel/JKRHeap.h" #include "JSystem/JUtility/JUTAssert.h" #include "JSystem/JUtility/JUTConsole.h" #include "JSystem/JUtility/JUTDbPrint.h" @@ -224,7 +225,17 @@ void JFWDisplay::endGX() { } void JFWDisplay::beginRender() { +#if TARGET_PC + // Temporarily clear the current JKRHeap so that Aurora/Dawn/ImGui allocations + // use malloc instead of JKRHeap. Without this, Dawn's internal std::string + // allocations would go through JKRHeap and then crash when freed via standard delete. + JKRHeap* savedHeap = JKRHeap::getCurrentHeap(); + JKRHeap::setCurrentHeap(nullptr); +#endif aurora_begin_frame(); +#if TARGET_PC + JKRHeap::setCurrentHeap(savedHeap); +#endif if (field_0x40) { JUTProcBar::getManager()->wholeLoopEnd(); } @@ -302,7 +313,16 @@ void JFWDisplay::endRender() { JUTProcBar::getManager()->cpuStart(); calcCombinationRatio(); +#if TARGET_PC + { + JKRHeap* savedHeap = JKRHeap::getCurrentHeap(); + JKRHeap::setCurrentHeap(nullptr); + aurora_end_frame(); + JKRHeap::setCurrentHeap(savedHeap); + } +#else aurora_end_frame(); +#endif } void JFWDisplay::endFrame() { diff --git a/libs/JSystem/src/JGadget/binary.cpp b/libs/JSystem/src/JGadget/binary.cpp index cde00093f2..c16c72a29f 100644 --- a/libs/JSystem/src/JGadget/binary.cpp +++ b/libs/JSystem/src/JGadget/binary.cpp @@ -2,6 +2,7 @@ #include "JSystem/JGadget/binary.h" #include "JSystem/JGadget/define.h" +#include "global.h" #include #if DEBUG diff --git a/libs/JSystem/src/JStage/JSGAmbientLight.cpp b/libs/JSystem/src/JStage/JSGAmbientLight.cpp index acffa59621..b886209bd1 100644 --- a/libs/JSystem/src/JStage/JSGAmbientLight.cpp +++ b/libs/JSystem/src/JStage/JSGAmbientLight.cpp @@ -9,7 +9,7 @@ s32 JStage::TAmbientLight::JSGFGetType() const { } GXColor JStage::TAmbientLight::JSGGetColor() const { - return COMPOUND_LITERAL(GXColor){255, 255, 255, 255}; + return GXColor{255, 255, 255, 255}; } void JStage::TAmbientLight::JSGSetColor(GXColor) {} diff --git a/libs/JSystem/src/JStage/JSGFog.cpp b/libs/JSystem/src/JStage/JSGFog.cpp index cb9c28f463..213fa0dd37 100644 --- a/libs/JSystem/src/JStage/JSGFog.cpp +++ b/libs/JSystem/src/JStage/JSGFog.cpp @@ -28,7 +28,7 @@ f32 JStage::TFog::JSGGetEndZ() const { void JStage::TFog::JSGSetEndZ(f32) {} GXColor JStage::TFog::JSGGetColor() const { - return COMPOUND_LITERAL(GXColor){255, 255, 255, 255}; + return GXColor{255, 255, 255, 255}; } void JStage::TFog::JSGSetColor(GXColor) {} diff --git a/libs/JSystem/src/JStage/JSGLight.cpp b/libs/JSystem/src/JStage/JSGLight.cpp index c8b7432987..af9c1e11ee 100644 --- a/libs/JSystem/src/JStage/JSGLight.cpp +++ b/libs/JSystem/src/JStage/JSGLight.cpp @@ -15,7 +15,7 @@ bool JStage::TLight::JSGGetLightType() const { void JStage::TLight::JSGSetLightType(JStage::TELight) {} GXColor JStage::TLight::JSGGetColor() const { - return COMPOUND_LITERAL(GXColor){255, 255, 255, 255}; + return GXColor{255, 255, 255, 255}; } void JStage::TLight::JSGSetColor(GXColor) {} diff --git a/libs/JSystem/src/JUtility/JUTAssert.cpp b/libs/JSystem/src/JUtility/JUTAssert.cpp index 3f54bf511d..89799cebf4 100644 --- a/libs/JSystem/src/JUtility/JUTAssert.cpp +++ b/libs/JSystem/src/JUtility/JUTAssert.cpp @@ -6,6 +6,7 @@ #include "JSystem/JUtility/JUTDirectPrint.h" #include #include +#include "global.h" namespace JUTAssertion { diff --git a/src/dusk/imgui/debug_overlay.cpp b/src/dusk/imgui/debug_overlay.cpp index ae97dbd0a8..e453d5bd26 100644 --- a/src/dusk/imgui/debug_overlay.cpp +++ b/src/dusk/imgui/debug_overlay.cpp @@ -4,7 +4,9 @@ #include "fmt/format.h" #include "imgui.h" +#include "aurora/gfx.h" +#include "aurora/gfx.h" #include "imgui.hpp" static bool m_frameRate = true; @@ -12,19 +14,6 @@ static bool m_pipelineInfo = true; static bool m_graphicsBackend = true; static int m_debugOverlayCorner = 0; // top-left -namespace aurora::gfx -{ - extern std::atomic_uint32_t queuedPipelines; - extern std::atomic_uint32_t createdPipelines; - - extern size_t g_drawCallCount; - extern size_t g_mergedDrawCallCount; - extern size_t g_lastVertSize; - extern size_t g_lastUniformSize; - extern size_t g_lastIndexSize; - extern size_t g_lastStorageSize; -} // namespace aurora::gfx - using namespace std::string_literals; using namespace std::string_view_literals; @@ -117,6 +106,12 @@ void DuskImguiDebugOverlay(const AuroraInfo *info) { std::string_view backendString = "Unknown"sv; switch (info->backend) { + case BACKEND_AUTO: + backendString = "Auto"sv; + break; + case BACKEND_D3D11: + backendString = "D3D11"sv; + break; case BACKEND_D3D12: backendString = "D3D12"sv; break; @@ -149,26 +144,28 @@ void DuskImguiDebugOverlay(const AuroraInfo *info) { } hasPrevious = true; + AuroraStats const* stats = aurora_get_stats(); + ImGuiStringViewText( - fmt::format(FMT_STRING("Queued pipelines: {}\n"), aurora::gfx::queuedPipelines.load())); + fmt::format(FMT_STRING("Queued pipelines: {}\n"), stats->queuedPipelines)); ImGuiStringViewText( - fmt::format(FMT_STRING("Done pipelines: {}\n"), aurora::gfx::createdPipelines.load())); + fmt::format(FMT_STRING("Done pipelines: {}\n"), stats->createdPipelines)); ImGuiStringViewText( - fmt::format(FMT_STRING("Draw call count: {}\n"), aurora::gfx::g_drawCallCount)); + fmt::format(FMT_STRING("Draw call count: {}\n"), stats->drawCallCount)); ImGuiStringViewText(fmt::format(FMT_STRING("Merged draw calls: {}\n"), - aurora::gfx::g_mergedDrawCallCount)); + stats->mergedDrawCallCount)); ImGuiStringViewText(fmt::format(FMT_STRING("Vertex size: {}\n"), - BytesToString(aurora::gfx::g_lastVertSize))); + BytesToString(stats->lastVertSize))); ImGuiStringViewText(fmt::format(FMT_STRING("Uniform size: {}\n"), - BytesToString(aurora::gfx::g_lastUniformSize))); + BytesToString(stats->lastUniformSize))); ImGuiStringViewText(fmt::format(FMT_STRING("Index size: {}\n"), - BytesToString(aurora::gfx::g_lastIndexSize))); + BytesToString(stats->lastIndexSize))); ImGuiStringViewText(fmt::format(FMT_STRING("Storage size: {}\n"), - BytesToString(aurora::gfx::g_lastStorageSize))); + BytesToString(stats->lastStorageSize))); ImGuiStringViewText(fmt::format( FMT_STRING("Total: {}\n"), - BytesToString(aurora::gfx::g_lastVertSize + aurora::gfx::g_lastUniformSize + - aurora::gfx::g_lastIndexSize + aurora::gfx::g_lastStorageSize))); + BytesToString(stats->lastVertSize + stats->lastUniformSize + + stats->lastIndexSize + stats->lastStorageSize))); } } ImGui::End(); diff --git a/src/dusk/stubs.cpp b/src/dusk/stubs.cpp index 867a1e1a7d..cff00b03bd 100644 --- a/src/dusk/stubs.cpp +++ b/src/dusk/stubs.cpp @@ -1402,9 +1402,7 @@ u16 GXGetNumXfbLines(u16 efbHeight, f32 yScale) { STUB_LOG("GXGetNumXfbLines is a stub"); return 0; } -void GXGetViewportv(f32* vp) { - STUB_LOG("GXGetViewportv is a stub"); -} + void GXGetScissor(u32* left, u32* top, u32* wd, u32* ht) { STUB_LOG("GXGetScissor is a stub"); }