Skip to content

Commit abdef9f

Browse files
committed
Add tracing scopes to the mission load code
This makes it easier to determine what takes the most time while loading the mission (loading models) and how we could optimize that load time (optimize model loading). This is not a bug fix but it also shouldn't cause any regressions since there are no actual code changes so this could be merged before the release of 3.8.
1 parent f67a42d commit abdef9f

File tree

14 files changed

+103
-12
lines changed

14 files changed

+103
-12
lines changed

code/bmpman/bmpman.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ship/ship.h"
3636
#include "tgautils/tgautils.h"
3737
#include "tracing/Monitor.h"
38+
#include "tracing/tracing.h"
3839

3940
#include <ctype.h>
4041
#include <limits.h>
@@ -2577,6 +2578,8 @@ void bm_page_in_start() {
25772578
}
25782579

25792580
void bm_page_in_stop() {
2581+
TRACE_SCOPE(tracing::PageInStop);
2582+
25802583
int i;
25812584

25822585
#ifndef NDEBUG
@@ -2593,6 +2596,7 @@ void bm_page_in_stop() {
25932596
for (i = 0; i < MAX_BITMAPS; i++) {
25942597
if ((bm_bitmaps[i].type != BM_TYPE_NONE) && (bm_bitmaps[i].type != BM_TYPE_RENDER_TARGET_DYNAMIC) && (bm_bitmaps[i].type != BM_TYPE_RENDER_TARGET_STATIC)) {
25952598
if (bm_bitmaps[i].preloaded) {
2599+
TRACE_SCOPE(tracing::PageInSingleBitmap);
25962600
if (bm_preloading) {
25972601
if (!gr_preload(bm_bitmaps[i].handle, (bm_bitmaps[i].preloaded == 2))) {
25982602
mprintf(("Out of VRAM. Done preloading.\n"));

code/gamesnd/gamesnd.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "parse/parselo.h"
1616
#include "sound/ds.h"
1717
#include "species_defs/species_defs.h"
18+
#include "tracing/tracing.h"
1819

1920
SCP_vector<game_snd> Snds;
2021
SCP_vector<game_snd> Snds_iface;

code/mission/missionload.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "missionui/missionshipchoice.h"
2222
#include "playerman/managepilot.h"
2323
#include "ui/ui.h"
24-
24+
#include "tracing/tracing.h"
2525

2626

2727
extern mission The_mission; // need to send this info to the briefing
@@ -82,6 +82,8 @@ void ml_update_recent_missions(char *filename)
8282
// returns -1 if failed, 0 if successful
8383
int mission_load(char *filename_ext)
8484
{
85+
TRACE_SCOPE(tracing::LoadMissionLoad);
86+
8587
char filename[MAX_PATH_LEN], *ext;
8688

8789
if ( (filename_ext != NULL) && (Game_current_mission_filename != filename_ext) )

code/model/modelcollide.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "math/vecmat.h"
1919
#include "model/model.h"
2020
#include "model/modelsinc.h"
21+
#include "tracing/tracing.h"
2122
#include "tracing/Monitor.h"
2223

2324

@@ -731,6 +732,8 @@ void model_collide_parse_bsp_flatpoly(bsp_collision_leaf *leaf, SCP_vector<model
731732

732733
void model_collide_parse_bsp(bsp_collision_tree *tree, void *model_ptr, int version)
733734
{
735+
TRACE_SCOPE(tracing::ModelParseBSPTree);
736+
734737
ubyte *p = (ubyte *)model_ptr;
735738
ubyte *next_p;
736739

code/model/modelinterp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "ship/shipfx.h"
3636
#include "weapon/shockwave.h"
3737
#include "tracing/Monitor.h"
38+
#include "tracing/tracing.h"
3839

3940
#include <limits.h>
4041

@@ -2255,6 +2256,8 @@ bool model_interp_config_buffer(indexed_vertex_source *vert_src, vertex_buffer *
22552256

22562257
void interp_configure_vertex_buffers(polymodel *pm, int mn)
22572258
{
2259+
TRACE_SCOPE(tracing::ModelConfigureVertexBuffers);
2260+
22582261
int i, j, first_index;
22592262
uint total_verts = 0;
22602263
SCP_vector<int> vertex_list;
@@ -2501,6 +2504,8 @@ void interp_fill_detail_index_buffer(SCP_vector<int> &submodel_list, polymodel *
25012504

25022505
void interp_create_detail_index_buffer(polymodel *pm, int detail_num)
25032506
{
2507+
TRACE_SCOPE(tracing::ModelCreateDetailIndexBuffers);
2508+
25042509
SCP_vector<int> submodel_list;
25052510

25062511
submodel_list.clear();
@@ -2523,6 +2528,8 @@ void interp_create_detail_index_buffer(polymodel *pm, int detail_num)
25232528

25242529
void interp_create_transparency_index_buffer(polymodel *pm, int mn)
25252530
{
2531+
TRACE_SCOPE(tracing::ModelCreateTransparencyIndexBuffer);
2532+
25262533
const int NUM_VERTS_PER_TRI = 3;
25272534

25282535
bsp_info *sub_model = &pm->submodel[mn];

code/model/modeloctant.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "math/vecmat.h"
1919
#include "model/model.h"
2020
#include "model/modelsinc.h"
21+
#include "tracing/tracing.h"
2122

2223
// returns 1 if a point is in an octant.
2324
int point_in_octant( polymodel * pm, model_octant * oct, vec3d *vert )
@@ -311,6 +312,8 @@ void model_octant_find_faces( polymodel * pm, model_octant * oct )
311312
// Creates the octants for a given polygon model
312313
void model_octant_create( polymodel * pm )
313314
{
315+
TRACE_SCOPE(tracing::ModelCreateOctants);
316+
314317
vec3d min, max, center;
315318
int i, x, y, z;
316319

code/model/modelread.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "render/3dinternal.h"
3737
#include "ship/ship.h"
3838
#include "weapon/weapon.h"
39+
#include "tracing/tracing.h"
40+
3941
#include <algorithm>
4042

4143
flag_def_list model_render_flags[] =
@@ -877,6 +879,8 @@ void create_vertex_buffer(polymodel *pm)
877879
return;
878880
}
879881

882+
TRACE_SCOPE(tracing::ModelCreateVertexBuffers);
883+
880884
int i;
881885

882886
// determine the size and configuration of each buffer segment
@@ -1061,7 +1065,9 @@ int read_model_file(polymodel * pm, const char *filename, int n_subsystems, mode
10611065
}
10621066

10631067
return -1;
1064-
}
1068+
}
1069+
1070+
TRACE_SCOPE(tracing::ReadModelFile);
10651071

10661072
// generate checksum for the POF
10671073
cfseek(fp, 0, SEEK_SET);
@@ -2637,7 +2643,9 @@ int model_load(const char *filename, int n_subsystems, model_subsystem *subsyst
26372643
if ( num == -1 ) {
26382644
Error( LOCATION, "Too many models" );
26392645
return -1;
2640-
}
2646+
}
2647+
2648+
TRACE_SCOPE(tracing::LoadModelFile);
26412649

26422650
mprintf(( "Loading model '%s' into slot '%i'\n", filename, num ));
26432651

@@ -2846,6 +2854,8 @@ int model_load(const char *filename, int n_subsystems, model_subsystem *subsyst
28462854
model_octant_create( pm );
28472855

28482856
if ( !Cmdline_old_collision_sys ) {
2857+
TRACE_SCOPE(tracing::ModelParseAllBSPTrees);
2858+
28492859
for ( i = 0; i < pm->n_models; ++i ) {
28502860
pm->submodel[i].collision_tree_index = model_create_bsp_collision_tree();
28512861
bsp_collision_tree *tree = model_get_bsp_collision_tree(pm->submodel[i].collision_tree_index);

code/ship/ship.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "weapon/swarm.h"
8686
#include "weapon/weapon.h"
8787
#include "tracing/Monitor.h"
88+
#include "tracing/tracing.h"
8889

8990
using namespace Ship;
9091

@@ -16114,6 +16115,8 @@ int get_max_ammo_count_for_turret_bank(ship_weapon *swp, int bank, int ammo_type
1611416115
*/
1611516116
void ship_page_in()
1611616117
{
16118+
TRACE_SCOPE(tracing::ShipPageIn);
16119+
1611716120
int i, j, k;
1611816121
int num_subsystems_needed = 0;
1611916122

code/sound/sound.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "sound/ds3d.h"
2626
#include "sound/dscap.h"
2727
#include "tracing/Monitor.h"
28+
#include "tracing/tracing.h"
2829

2930
#include "globalincs/pstypes.h"
3031

@@ -313,6 +314,7 @@ int snd_load( game_snd *gs, int allow_hardware_load )
313314

314315
si = &snd->info;
315316

317+
TRACE_SCOPE(tracing::LoadSound);
316318

317319
std::unique_ptr<ffmpeg::WaveFile> audio_file(new ffmpeg::WaveFile());
318320

code/tracing/categories.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,24 @@ Category CutsceneProcessAudioData("Process audio data", false);
9191
Category CutsceneFFmpegVideoDecoder("FFmpeg decode video", false);
9292
Category CutsceneFFmpegAudioDecoder("FFmpeg decode video", false);
9393

94+
Category LoadMissionLoad("Load mission", false);
95+
Category LoadPostMissionLoad("Mission load post processing", false);
96+
Category LoadModelFile("Load model file", false);
97+
Category ReadModelFile("Read model file", false);
98+
Category ModelCreateVertexBuffers("Create model vertex buffers", false);
99+
Category ModelCreateOctants("Create model octants", false);
100+
Category ModelParseAllBSPTrees("Parse all BSP trees", false);
101+
Category ModelParseBSPTree("Parse BSP tree", false);
102+
Category ModelConfigureVertexBuffers("Model configure vertex buffers", false);
103+
Category ModelCreateTransparencyIndexBuffer("Model create transparency buffer", false);
104+
Category ModelCreateDetailIndexBuffers("Model create detail index buffers", false);
105+
106+
Category PreloadMissionSounds("Preload mission sounds", false);
107+
Category LoadSound("Load Sound", false);
108+
109+
Category LevelPageIn("Level page in", false);
110+
Category PageInStop("Finish page in", false);
111+
Category PageInSingleBitmap("Page in single bitmap", false);
112+
Category ShipPageIn("Ship page in", false);
113+
Category WeaponPageIn("Weapon page in", false);
94114
}

0 commit comments

Comments
 (0)