CORE: added tracy support

Martin Gerhardy 2019-10-27 18:20:46 +01:00
parent bfdcf3a02c
commit cfc2208ed6
6 changed files with 91 additions and 1 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/modules/core/tracy"]
path = src/modules/core/tracy
url = https://bitbucket.org/wolfpld/tracy.git

View File

@ -67,6 +67,14 @@ set(SRCS
Vector.h
Zip.cpp Zip.h miniz.h miniz.c
)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tracy/TracyClient.cpp)
list(APPEND SRCS tracy/TracyClient.cpp)
message(STATUS "Building with tracy enabled")
else()
message(STATUS "Building with tracy disabled")
endif()
set(LIB core)
if (WINDOWS)
@ -79,6 +87,9 @@ if (NOT MSVC)
list(APPEND LIBS backward)
endif()
engine_add_module(TARGET ${LIB} SRCS ${SRCS} DEPENDENCIES ${LIBS})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tracy/TracyClient.cpp)
target_compile_definitions(${LIB} PUBLIC TRACY_ENABLE TRACY_ON_DEMAND)
endif()
set(TEST_SRCS
tests/AbstractTest.cpp

View File

@ -21,7 +21,42 @@ static thread_local const char* _threadName = "Unknown";
}
#ifdef TRACY_ENABLE
static SDL_malloc_func malloc_func;
static SDL_calloc_func calloc_func;
static SDL_realloc_func realloc_func;
static SDL_free_func free_func;
static void *wrap_malloc_func(size_t size) {
void* mem = malloc_func(size);
TracyAlloc(mem, size);
return mem;
}
static void *wrap_calloc_func(size_t nmemb, size_t size) {
void *mem = calloc_func(nmemb, size);
TracyAlloc(mem, size * nmemb);
return mem;
}
static void *wrap_realloc_func(void *mem, size_t size) {
void *newmem = realloc_func(mem, size);
return newmem;
}
static void wrap_free_func(void *mem) {
TracyFree(mem)
free_func(mem);
}
#endif
Trace::Trace() {
#ifdef TRACY_ENABLE
//core_assert(SDL_GetNumAllocations() == 0);
SDL_GetMemoryFunctions(&malloc_func, &calloc_func, &realloc_func, &free_func);
SDL_SetMemoryFunctions(wrap_malloc_func, wrap_calloc_func, wrap_realloc_func, wrap_free_func);
#endif
#ifdef USE_EMTRACE
emscripten_trace_configure("http://localhost:17000/", "Engine");
#endif

View File

@ -6,6 +6,10 @@
#include <stdint.h>
#ifdef TRACY_ENABLE
#include "tracy/Tracy.hpp"
#endif
namespace core {
// a singleton - available via core::App
@ -50,6 +54,27 @@ extern void traceGLEnd();
extern void traceMessage(const char* name);
extern void traceThread(const char* name);
#ifdef TRACY_ENABLE
#define core_trace_set(x) core::traceSet(x)
#define core_trace_init() core::traceInit()
#define core_trace_gl_init() core::traceGLInit()
#define core_trace_shutdown() core::traceShutdown()
#define core_trace_gl_shutdown() core::traceGLShutdown()
#define core_trace_msg(message) TracyMessageL(message)
#define core_trace_thread(name) tracy::SetThreadName(name)
#define core_trace_mutex(type, name) TracyLockable(type, name)
#define core_trace_begin_frame() FrameMarkNamed("Main")
#define core_trace_end_frame() FrameMark
#define core_trace_begin(name)
#define core_trace_end()
#define core_trace_gl_begin(name)
#define core_trace_gl_begin_dynamic(name)
#define core_trace_gl_end()
#define core_trace_gl_scoped(name)
// TODO: TracyGpuZone(#name)
#define core_trace_scoped(name) ZoneNamedN(__tracy_scoped_##name, #name, true)
#else
#define core_trace_set(x) core::traceSet(x)
#define core_trace_init() core::traceInit()
#define core_trace_gl_init() core::traceGLInit()
@ -68,5 +93,6 @@ extern void traceThread(const char* name);
#define core_trace_gl_end() core::traceGLEnd()
#define core_trace_gl_scoped(name) core::TraceGLScoped __trace__##name(#name)
#define core_trace_scoped(name) core::TraceScoped __trace__##name(#name)
#endif
}

@ -0,0 +1 @@
Subproject commit 865593146ab71d7fb9da30a01c6482fa6ad10b18

View File

@ -16,6 +16,7 @@
#include "video/StencilConfig.h"
#include "image/Image.h"
#include "core/Common.h"
#include "core/Trace.h"
#include "core/Log.h"
#include "core/ArrayLength.h"
#include "core/Var.h"
@ -30,6 +31,10 @@
#include <SDL.h>
#include <algorithm>
#ifdef TRACY_ENABLE
#include "core/tracy/TracyOpenGL.hpp"
#endif
namespace video {
static RenderState s;
@ -1003,6 +1008,9 @@ void flush() {
void finish() {
glFinish();
#ifdef TRACY_ENABLE
TracyGpuCollect;
#endif
checkError();
}
@ -1647,7 +1655,8 @@ void destroyContext(RendererContext& context) {
RendererContext createContext(SDL_Window* window) {
core_assert(window != nullptr);
return SDL_GL_CreateContext(window);
RendererContext ctx = SDL_GL_CreateContext(window);
return ctx;
}
void startFrame(SDL_Window* window, RendererContext& context) {
@ -1797,6 +1806,11 @@ bool init(int windowWidth, int windowHeight, float scaleFactor) {
if (multisampling) {
video::enable(video::State::MultiSample);
}
#ifdef TRACY_ENABLE
TracyGpuContext;
#endif
return true;
}