Skip to content

Commit

Permalink
feat: implement tracey support
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <[email protected]>
  • Loading branch information
pollend committed Jan 11, 2025
1 parent 27afd1f commit 95a8fc5
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "source/extern/curl"]
path = source/extern/curl
url = https://github.com/TeamForbiddenLLC/curl.git
[submodule "source/extern/tracy"]
path = source/extern/tracy
url = https://github.com/wolfpld/tracy.git
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ OPTION(USE_SYSTEM_OGG "Prefer system OGG instead of the bundled one" OFF)
OPTION(USE_SYSTEM_FREETYPE "Prefer system freetype instead of the bundled one" OFF)
OPTION(USE_SYSTEM_VORBIS "Prefer system vorbis instead of the bundled one" OFF)


option(USE_PACKAGE_ASSETS "package assets" OFF)
# We compile third-party libs from source

Expand Down
3 changes: 1 addition & 2 deletions source/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_custom_command(TARGET ${QFUSION_CLIENT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/warfork-qfusion/steam_appid.txt ${CMAKE_BINARY_DIR}/warfork-qfusion/$(CONFIGURATION)/)
endif()

target_link_libraries(${QFUSION_CLIENT_NAME} PRIVATE CURL::libcurl ${CLIENT_PLATFORM_LIBRARIES} ${DISCORD_LIBRARY} ${STEAMSHIMPARENT_LIBRARY})

target_link_libraries(${QFUSION_CLIENT_NAME} PRIVATE CURL::libcurl ${CLIENT_PLATFORM_LIBRARIES} ${DISCORD_LIBRARY} ${STEAMSHIMPARENT_LIBRARY} Tracy::TracyClient)
qf_set_output_dir(${QFUSION_CLIENT_NAME} "")

if (BUILD_STEAMLIB)
Expand Down
6 changes: 6 additions & 0 deletions source/client/cl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ end of unit intermissions

#include "client.h"
#include "ftlib.h"
#include "tracy/TracyC.h"


float scr_con_current; // aproaches scr_conlines at scr_conspeed
float scr_con_previous;
Expand Down Expand Up @@ -674,6 +676,7 @@ static void SCR_RenderView( float stereo_separation )
*/
void SCR_UpdateScreen( void )
{
TracyCFrameMark
static dynvar_t *updatescreen = NULL;
int numframes;
int i;
Expand Down Expand Up @@ -731,6 +734,8 @@ void SCR_UpdateScreen( void )

for( i = 0; i < numframes; i++ )
{
static const char* const cl_frame = "Render Frame";
TracyCFrameMarkStart(cl_frame);
RF_BeginFrame( separation[i], forceclear, forcevsync );

if( scr_draw_loading == 2 )
Expand Down Expand Up @@ -787,5 +792,6 @@ void SCR_UpdateScreen( void )
Dynvar_CallListeners( updatescreen, NULL );

RF_EndFrame();
TracyCFrameMarkEnd(cl_frame);
}
}
6 changes: 6 additions & 0 deletions source/extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ endif()

endif()

option(TRACY_STATIC "" OFF )
SET(TRACY_ENABLE OFF CACHE BOOL "Enable profiling")
add_compile_definitions(TRACY_IMPORTS)
add_subdirectory(tracy)
qf_set_output_dir(TracyClient libs)

set(STB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stb PARENT_SCOPE)
1 change: 1 addition & 0 deletions source/extern/tracy
Submodule tracy added at e49c25
2 changes: 1 addition & 1 deletion source/ref_nri/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ file(GLOB STB_HEADERS
add_library(ref_nri SHARED ${REF_NRI_HEADERS} ${REF_NRI_COMMON_SOURCES} ${REF_NRI_PLATFORM_SOURCES})
target_include_directories(ref_nri PRIVATE ${STB_INCLUDE_DIR} "../ref_base" "${NRI_DIR}/External/vulkan/include")
target_link_libraries(ref_nri PRIVATE NRI)
target_link_libraries(ref_nri PRIVATE glslang::glslang glslang::glslang-default-resource-limits glslang::SPIRV glslang::SPVRemapper qcore)
target_link_libraries(ref_nri PRIVATE glslang::glslang glslang::glslang-default-resource-limits glslang::SPIRV glslang::SPVRemapper qcore Tracy::TracyClient)
target_include_directories(ref_nri PRIVATE ${NRI_INCLUDE_DIR})
target_include_directories(ref_nri PRIVATE ${MINIZ_INCLUDE_DIR})
qf_set_output_dir(ref_nri libs)
Expand Down
14 changes: 11 additions & 3 deletions source/ref_nri/r_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "stb_ds.h"
#include "r_capture.h"
#include "tracy/TracyC.h"


static ref_frontend_t rrf;

Expand Down Expand Up @@ -200,6 +202,7 @@ rserr_t RF_Init( const char *applicationName, const char *screenshotPrefix, int

rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, bool fullScreen, bool stereo )
{
TracyCZone(ctx, 1);
rsh.nri.helperI.WaitForIdle( rsh.cmdQueue );

if( fullScreen ) {
Expand Down Expand Up @@ -327,6 +330,7 @@ rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, b

RB_Init();

TracyCZoneEnd(ctx);
return rserr_ok;
}

Expand Down Expand Up @@ -404,6 +408,7 @@ void RF_Shutdown( bool verbose )

static void RF_CheckCvars( void )
{
TracyCZone(ctx, 1);
// disallow bogus r_maxfps values, reset to default value instead
if( r_maxfps->modified ) {
if( r_maxfps->integer <= 0 ) {
Expand Down Expand Up @@ -459,10 +464,12 @@ static void RF_CheckCvars( void )
}
r_outlines_scale->modified = false;
}
TracyCZoneEnd(ctx);
}

void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync )
{
TracyCZone(ctx, 1);
RF_CheckCvars();

// run cinematic passes on shaders
Expand Down Expand Up @@ -539,12 +546,10 @@ void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync )

rrf.cameraSeparation = cameraSeparation;


memset( &rf.stats, 0, sizeof( rf.stats ) );

// update fps meter
// copy in changes from R_BeginFrame
// rrf.frame->BeginFrame( rrf.frame, cameraSeparation, forceClear, forceVsync );
const unsigned int time = ri.Sys_Milliseconds();
rf.fps.count++;
rf.fps.time = time;
Expand All @@ -557,7 +562,7 @@ void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync )
rf.width2D = -1;
rf.height2D = -1;
R_Set2DMode(frame, true );

TracyCZoneEnd(ctx);
}

static inline void __R_PolyBlendPostPass(struct frame_cmd_buffer_s* frame) {
Expand Down Expand Up @@ -595,6 +600,7 @@ static inline void __R_ApplyBrightnessBlend(struct frame_cmd_buffer_s* frame) {

void RF_EndFrame( void )
{
TracyCZone(ctx, 1);
const uint32_t bufferedFrameIndex = rsh.swapchainCount % NUMBER_FRAMES_FLIGHT;
struct frame_cmd_buffer_s *frame = &rsh.frameCmds[bufferedFrameIndex];

Expand Down Expand Up @@ -727,6 +733,8 @@ void RF_EndFrame( void )

rsh.swapchainCount++;
rsh.frameCount++;

TracyCZoneEnd(ctx);
}

void RF_BeginRegistration( void )
Expand Down
23 changes: 21 additions & 2 deletions source/ref_nri/r_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "r_ktx_loader.h"
#include <assert.h>

#include <qstr.h>

#include "tracy/TracyC.h"

#define MAX_GLIMAGES 8192
#define IMAGES_HASH_SIZE 64
#define IMAGE_SAMPLER_HASH_SIZE 1024
Expand Down Expand Up @@ -700,6 +701,7 @@ static bool R_IsKTXFormatValid( int format, int type )
//TODO: move ktx loader to a seperate file
static bool __R_LoadKTX( image_t *image, const char *pathname )
{
TracyCZone(ctx, 1);
const uint_fast16_t numFaces = ( ( image->flags & IT_CUBEMAP ) ? 6 : 1 );
if( image->flags & ( IT_FLIPX|IT_FLIPY|IT_FLIPDIAGONAL ) )
return false;
Expand Down Expand Up @@ -867,10 +869,12 @@ static bool __R_LoadKTX( image_t *image, const char *pathname )
R_KTXFreeContext(&ktxContext);
R_FreeFile( buffer );
R_DeferDataSync();
TracyCZoneEnd(ctx);
return true;
error: // must not be reached after actually starting uploading the texture
R_KTXFreeContext(&ktxContext);
R_FreeFile( buffer );
TracyCZoneEnd(ctx);
return false;
}

Expand Down Expand Up @@ -1022,7 +1026,7 @@ static uint16_t __R_calculateMipMapLevel(int flags, int width, int height, uint3

struct image_s *R_LoadImage( const char *name, uint8_t **pic, int width, int height, int flags, int minmipsize, int tags, int samples )
{

TracyCZone(ctx, 1);
struct image_s *image = __R_AllocImage( qCToStrRef(name) );

image->width = width;
Expand Down Expand Up @@ -1105,6 +1109,7 @@ struct image_s *R_LoadImage( const char *name, uint8_t **pic, int width, int hei
}
}
arrfree( tmpBuffer );
TracyCZoneEnd(ctx);
return image;
}

Expand Down Expand Up @@ -1132,6 +1137,7 @@ image_t *R_CreateImage( const char *name, int width, int height, int layers, int

static void __FreeImage( struct frame_cmd_buffer_s *cmd, struct image_s *image )
{
TracyCZone(ctx, 1);
{
__FreeGPUImageData(cmd, image);
// R_ReleaseNriTexture(image);
Expand Down Expand Up @@ -1160,11 +1166,13 @@ static void __FreeImage( struct frame_cmd_buffer_s *cmd, struct image_s *image )
image->prev = NULL;
ri.Mutex_Unlock( r_imagesLock );
}
TracyCZoneEnd(ctx);

}

void R_ReplaceImage( image_t *image, uint8_t **pic, int width, int height, int flags, int minmipsize, int samples )
{
TracyCZone(ctx, 1);
assert( image );
assert( image->texture );
const NriTextureDesc* textureDesc = rsh.nri.coreI.GetTextureDesc(image->texture);
Expand Down Expand Up @@ -1207,13 +1215,15 @@ void R_ReplaceImage( image_t *image, uint8_t **pic, int width, int height, int f
image->minmipsize = minmipsize;

R_ReplaceSubImage(image, 0, 0, 0, pic, width, height);
TracyCZoneEnd(ctx);
}

/*
* R_ReplaceSubImage
*/
void R_ReplaceSubImage( image_t *image, int layer, int x, int y, uint8_t **pic, int width, int height )
{
TracyCZone(ctx, 1);
assert( image );
assert( image->texture );

Expand Down Expand Up @@ -1254,13 +1264,15 @@ void R_ReplaceSubImage( image_t *image, int layer, int x, int y, uint8_t **pic,
R_DeferDataSync();

image->registrationSequence = rsh.registrationSequence;
TracyCZoneEnd(ctx);
}

/*
* R_ReplaceImageLayer
*/
void R_ReplaceImageLayer( image_t *image, int layer, uint8_t **pic )
{
TracyCZone(ctx, 1);
assert( image );
assert( image->texture );

Expand Down Expand Up @@ -1301,6 +1313,7 @@ void R_ReplaceImageLayer( image_t *image, int layer, uint8_t **pic )
R_DeferDataSync();

image->registrationSequence = rsh.registrationSequence;
TracyCZoneEnd(ctx);
}

/*
Expand All @@ -1311,6 +1324,7 @@ void R_ReplaceImageLayer( image_t *image, int layer, uint8_t **pic )
*/
image_t *R_FindImage( const char *name, const char *suffix, int flags, int minmipsize, int tags )
{
TracyCZone(ctx, 1);
assert( name );
assert( name[0] );
struct UploadImgBuffer {
Expand Down Expand Up @@ -1577,6 +1591,7 @@ image_t *R_FindImage( const char *name, const char *suffix, int flags, int minmi
T_FreeTextureBuf(&uploads[i].buffer);
}
qStrFree(&resolvedPath);
TracyCZoneEnd(ctx);
return image;
}

Expand Down Expand Up @@ -1909,6 +1924,7 @@ void R_TouchImage( image_t *image, int tags )
*/
void R_FreeUnusedImagesByTags( int tags )
{
TracyCZone(ctx, 1);
int i;
image_t *image;
int keeptags = ~tags;
Expand All @@ -1931,6 +1947,7 @@ void R_FreeUnusedImagesByTags( int tags )

__FreeImage( R_ActiveFrameCmd(),image );
}
TracyCZoneEnd(ctx);
}

/*
Expand All @@ -1946,6 +1963,7 @@ void R_FreeUnusedImages( void )
*/
void R_ShutdownImages( void )
{
TracyCZone(ctx, 1);
int i;
image_t *image;

Expand Down Expand Up @@ -1977,6 +1995,7 @@ void R_ShutdownImages( void )
r_imagesPool = NULL;
r_screenShotBuffer = NULL;
r_screenShotBufferSize = 0;
TracyCZoneEnd(ctx);

}

9 changes: 7 additions & 2 deletions source/ref_nri/r_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "r_local.h"
#include "iqm.h"

#include "tracy/TracyC.h"

void Mod_LoadAliasMD3Model( model_t *mod, model_t *parent, void *buffer, bspFormatDesc_t *unused );
void Mod_LoadSkeletalModel( model_t *mod, model_t *parent, void *buffer, bspFormatDesc_t *unused );
void Mod_LoadQ3BrushModel( model_t *mod, model_t *parent, void *buffer, bspFormatDesc_t *format );
Expand Down Expand Up @@ -1288,6 +1290,7 @@ static void R_FinishMapConfig( const model_t *mod )
*/
void R_RegisterWorldModel( const char *model, const dvis_t *pvsData )
{
TracyCZone( ctx, 1 );
r_prevworldmodel = rsh.worldModel;
rsh.worldModel = NULL;
rsh.worldBrushModel = NULL;
Expand All @@ -1301,15 +1304,17 @@ void R_RegisterWorldModel( const char *model, const dvis_t *pvsData )
mod_isworldmodel = false;

if( !rsh.worldModel ) {
TracyCZoneEnd( ctx );
return;
}

// FIXME: this is ugly...
mapConfig = mod_mapConfigs[rsh.worldModel - mod_known];

R_TouchModel( rsh.worldModel );
rsh.worldBrushModel = ( mbrushmodel_t * )rsh.worldModel->extradata;
rsh.worldBrushModel->pvs = ( dvis_t * )pvsData;
rsh.worldBrushModel = (mbrushmodel_t *)rsh.worldModel->extradata;
rsh.worldBrushModel->pvs = (dvis_t *)pvsData;
TracyCZoneEnd( ctx );
}

/*
Expand Down
Loading

0 comments on commit 95a8fc5

Please sign in to comment.