Skip to content

Commit

Permalink
feat: add some sample zones for testing
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 e0dc940 commit d2a38ba
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ 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_TRACY_PROFILING "Tracy performance tracking" OFF)

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

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
20 changes: 14 additions & 6 deletions source/ref_nri/r_texture_buffer_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

#include "../qcommon/qfiles.h"

#include "tracy/TracyC.h"

static uint32_t pallet[256];

bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pallet) {

TracyCZone(ctx, 1);
void* const raw;
size_t len = R_LoadFile( filename, (void **)&raw );
if(raw == NULL) {
ri.Com_Printf(S_COLOR_YELLOW "can't resolve file: %s", filename);
TracyCZoneEnd(ctx);
return false;
}

Expand All @@ -35,10 +39,10 @@ bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pall

if( sizeof(*pcx) > len ) {
ri.Com_DPrintf( S_COLOR_YELLOW "PCX file %s was malformed", filename );
TracyCZoneEnd(ctx);
return false;
}


pcx->xmin = LittleShort( pcx->xmin );
pcx->ymin = LittleShort( pcx->ymin );
pcx->xmax = LittleShort( pcx->xmax );
Expand All @@ -50,6 +54,7 @@ bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pall

if( (sizeof(*pcx) + (pcx->ymax * pcx->xmax) + sizeof(uint32_t) * 256) > len ) {
ri.Com_Printf( S_COLOR_YELLOW "PCX file %s was malformed", filename );
TracyCZoneEnd(ctx);
return false;
}

Expand All @@ -58,6 +63,7 @@ bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pall
len < 768 ) {
ri.Com_Printf( S_COLOR_YELLOW "Bad pcx file %s\n", filename );
R_FreeFile( pcx );
TracyCZoneEnd(ctx);
return false;
}

Expand Down Expand Up @@ -101,9 +107,8 @@ bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pall

R_FreeFile( pcx);


TracyCZoneEnd(ctx);
return true;

}

static void __R_stbi_free_image(void* p) {
Expand All @@ -112,6 +117,7 @@ static void __R_stbi_free_image(void* p) {
}

bool T_LoadImageSTBI(char *filename, struct texture_buf_s* buffer ) {
TracyCZone(ctx, 1);
uint8_t* data;
size_t size = R_LoadFile( filename, ( void ** ) &data );
if(data == NULL) {
Expand Down Expand Up @@ -145,26 +151,27 @@ bool T_LoadImageSTBI(char *filename, struct texture_buf_s* buffer ) {
default:
stbi_image_free(stbiBuffer);
ri.Com_Printf(S_COLOR_YELLOW "unhandled channel count: %d", channelCount);
TracyCZoneEnd(ctx);
return false;
}
R_FreeFile( data );
const int res = T_AliasTextureBuf_Free(buffer, &desc, stbiBuffer, 0, stbiBuffer, __R_stbi_free_image);
assert(res == TEXTURE_BUF_SUCCESS);
TracyCZoneEnd(ctx);
return true;
}

void T_SetPallet(uint32_t p[256]) {
memcpy(pallet, p, sizeof(pallet));
}



uint32_t* T_Pallet() {
return pallet;
}

//https://developer.valvesoftware.com/wiki/WAL
bool T_LoadImageWAL(char *filename, struct texture_buf_s* tex) {
TracyCZone(ctx, 1);
// load the file
uint8_t* const buf = NULL;
const size_t size = R_LoadFile( filename, (void **)&buf);
Expand Down Expand Up @@ -219,9 +226,10 @@ bool T_LoadImageWAL(char *filename, struct texture_buf_s* tex) {
*( (uint32_t *)block ) = pallet[p];
}
}
Mem_ValidationAllAllocations();
Mem_ValidationAllAllocations();

R_FreeFile( buf );
TracyCZoneEnd(ctx);
return true;
}

Expand Down

0 comments on commit d2a38ba

Please sign in to comment.