rt: print material load stats

This commit is contained in:
Ivan Avdeev 2022-08-13 13:15:17 -07:00 committed by Ivan Avdeev
parent 8ee68935d0
commit 202f2b8462
2 changed files with 37 additions and 3 deletions

View File

@ -29,6 +29,7 @@ typedef int aprof_scope_id_t;
aprof_scope_id_t aprof_scope_init(const char *scope_name);
void aprof_scope_event(aprof_scope_id_t, int begin);
void aprof_scope_frame( void );
uint64_t aprof_time_now_ns( void );
typedef struct {
const char *name;
@ -64,7 +65,7 @@ extern aprof_state_t g_aprof;
#ifdef __linux__
#include <time.h>
static uint64_t _aprof_time_now( void ) {
uint64_t aprof_time_now_ns( void ) {
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
return tp.tv_nsec + tp.tv_sec * 1000000000ull;
@ -74,7 +75,7 @@ static uint64_t _aprof_time_now( void ) {
#define WIN32_EXTRA_LEAN
#include <windows.h>
static LARGE_INTEGER _aprof_frequency;
static uint64_t _aprof_time_now( void ) {
uint64_t aprof_time_now_ns( void ) {
LARGE_INTEGER pc;
QueryPerformanceCounter(&pc);
return pc.QuadPart * 1000000000ull / _aprof_frequency.QuadPart;
@ -99,7 +100,7 @@ aprof_scope_id_t aprof_scope_init(const char *scope_name) {
}
void aprof_scope_event(aprof_scope_id_t scope_id, int begin) {
const uint64_t now = _aprof_time_now();
const uint64_t now = aprof_time_now_ns();
if (scope_id < 0 || scope_id >= g_aprof.num_scopes)
return;

View File

@ -2,6 +2,7 @@
#include "vk_textures.h"
#include "vk_mapents.h"
#include "vk_const.h"
#include "profiler.h"
#include <stdio.h>
@ -43,6 +44,14 @@ static void makePath(char *out, size_t out_size, const char *value, const char *
#define MAKE_PATH(out, value) \
makePath(out, sizeof(out), value, path_begin, path_end)
static struct {
int mat_files_read;
int texture_lookups;
int texture_loads;
int texture_lookup_duration_ns;
int texture_load_duration_ns;
} g_stats;
static void loadMaterialsFromFile( const char *filename, int depth ) {
fs_offset_t size;
const char *const path_begin = filename;
@ -107,7 +116,10 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
break;
if (Q_stricmp(key, "for") == 0) {
const uint64_t lookup_begin_ns = aprof_time_now_ns();
current_material_index = XVK_FindTextureNamedLike(value);
g_stats.texture_lookup_duration_ns += aprof_time_now_ns() - lookup_begin_ns;
g_stats.texture_lookups++;
create = false;
} else if (Q_stricmp(key, "new") == 0) {
current_material_index = XVK_CreateDummyTexture(value);
@ -147,18 +159,23 @@ static void loadMaterialsFromFile( const char *filename, int depth ) {
MAKE_PATH(texture_path, value);
if (tex_id_dest) {
const uint64_t load_begin_ns = aprof_time_now_ns();
const int tex_id = loadTexture(texture_path, force_reload);
g_stats.texture_load_duration_ns += aprof_time_now_ns() - load_begin_ns;
if (tex_id < 0) {
gEngine.Con_Printf(S_ERROR "Failed to load texture \"%s\" for key \"%s\"\n", value, key);
continue;
}
*tex_id_dest = tex_id;
g_stats.texture_loads++;
}
}
}
Mem_Free( data );
g_stats.mat_files_read++;
}
static void loadMaterialsFromFileF( const char *fmt, ... ) {
@ -173,6 +190,9 @@ static void loadMaterialsFromFileF( const char *fmt, ... ) {
}
void XVK_ReloadMaterials( void ) {
memset(&g_stats, 0, sizeof(g_stats));
const uint64_t begin_time_ns = aprof_time_now_ns();
for (int i = 0; i < MAX_TEXTURES; ++i) {
xvk_material_t *const mat = g_materials.materials + i;
const vk_texture_t *const tex = findTexture( i );
@ -199,6 +219,19 @@ void XVK_ReloadMaterials( void ) {
const model_t *map = gEngine.pfnGetModelByIndex( 1 );
loadMaterialsFromFileF("pbr/%s/%s.mat", map->name, COM_FileWithoutPath(map->name));
}
// Print out statistics
{
const int duration_ms = (aprof_time_now_ns() - begin_time_ns) / 1000000ull;
gEngine.Con_Printf("Loading materials took %dms, .mat files parsed: %d. Texture lookups: %d (%dms). Texture loads: %d (%dms).\n",
duration_ms,
g_stats.mat_files_read,
g_stats.texture_lookups,
(int)(g_stats.texture_lookup_duration_ns / 1000000ull),
g_stats.texture_loads,
(int)(g_stats.texture_load_duration_ns / 1000000ull)
);
}
}
xvk_material_t* XVK_GetMaterialForTextureIndex( int tex_index ) {