Skip to content

Commit

Permalink
Tracy;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed Apr 10, 2024
1 parent aef7119 commit bdeee99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
[submodule "deps/jolt-physics-sharp"]
path = deps/jolt-physics-sharp
url = https://github.com/amerkoleci/JoltPhysicsSharp
[submodule "deps/tracy"]
path = deps/tracy
url = https://github.com/wolfpld/tracy
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ option(LOVR_USE_WEBXR "Enable the WebXR backend for the headset module" OFF)
option(LOVR_USE_SIMULATOR "Enable the keyboard/mouse backend for the headset module" ON)
option(LOVR_USE_STEAM_AUDIO "Enable the Steam Audio spatializer (be sure to also set LOVR_STEAM_AUDIO_PATH)" OFF)
option(LOVR_USE_OCULUS_AUDIO "Enable the Oculus Audio spatializer (be sure to also set LOVR_OCULUS_AUDIO_PATH)" OFF)

option(LOVR_SANITIZE "Enable Address Sanitizer" OFF)
option(LOVR_PROFILE "Enable Tracy integration" OFF)

option(LOVR_SYSTEM_GLFW "Use the system-provided glfw" OFF)
option(LOVR_SYSTEM_LUA "Use the system-provided Lua" OFF)
Expand Down Expand Up @@ -361,6 +363,17 @@ if(LOVR_SANITIZE)
target_link_options(lovr PRIVATE ${LOVR_SANITIZE_FLAGS})
endif()

if(LOVR_PROFILE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "You probably want to build in release mode when Tracy is enabled")
endif()
option(TRACY_ENABLE "" ON)
add_subdirectory(deps/tracy)
target_compile_definitions(lovr PRIVATE LOVR_PROFILE)
target_link_libraries(lovr Tracy::TracyClient)
target_include_directories(lovr PRIVATE deps/tracy/public/tracy)
endif()

if(LOVR_ENABLE_AUDIO OR LOVR_ENABLE_DATA)
target_sources(lovr PRIVATE
src/lib/miniaudio/miniaudio.c
Expand Down
1 change: 1 addition & 0 deletions deps/tracy
Submodule tracy added at a9288c
2 changes: 2 additions & 0 deletions src/modules/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@ void lovrGraphicsPresent(void) {
state.shouldPresent = false;
gpu_surface_present();
}

lovrProfileMarkFrame();
}

void lovrGraphicsWait(void) {
Expand Down
12 changes: 12 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ enum { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR };
void lovrSetLogCallback(fn_log* callback, void* userdata);
void lovrLog(int level, const char* tag, const char* format, ...);

// Profiling
#ifdef LOVR_PROFILE
#include <TracyC.h>
#define lovrProfileMarkFrame() TracyCFrameMark
#define lovrProfileStart(id, label) TracyCZoneN(id, label, true)
#define lovrProfileEnd(id) TracyCZoneEnd(id)
#else
#define lovrProfileMarkFrame() ((void) 0)
#define lovrProfileStart(id, label) ((void) 0)
#define lovrProfileEnd(id) ((void) 0)
#endif

// Dynamic Array
#define arr_t(T) struct { T* data; size_t length, capacity; }
#define arr_init(a) (a)->data = NULL, (a)->length = 0, (a)->capacity = 0
Expand Down

0 comments on commit bdeee99

Please sign in to comment.