vk: profiler: explicit metric types; also more metrics

This commit is contained in:
Ivan Avdeev 2023-03-25 10:45:37 -07:00 committed by Ivan Avdeev
parent 8ecfae5bf0
commit f2ebcd663b
7 changed files with 58 additions and 20 deletions

View File

@ -27,7 +27,7 @@ enum {
typedef struct {
int *p_value;
const char *name;
const char *unit;
r_speeds_metric_type_t type;
// int low_watermark, high_watermark;
} r_speeds_metric_t;
@ -267,7 +267,18 @@ static int drawFrames( int draw, uint32_t prev_frame_index, int y, const uint64_
static void printMetrics( void ) {
for (int i = 0; i < g_speeds.metrics_count; ++i) {
const r_speeds_metric_t *const metric = g_speeds.metrics + i;
speedsPrintf("%s: %d%s\n", metric->name, *metric->p_value, metric->unit);
switch (metric->type) {
case kSpeedsMetricCount:
speedsPrintf("%s: %d\n", metric->name, *metric->p_value);
break;
case kSpeedsMetricBytes:
// TODO different units for different ranges, e.g. < 10k: bytes, < 10M: KiB, >10M: MiB
speedsPrintf("%s: %d%s\n", metric->name, *metric->p_value / 1024, "KiB");
break;
case kSpeedsMetricMicroseconds:
speedsPrintf("%s: %.03fms\n", metric->name, *metric->p_value * 1e-3f);
break;
}
*metric->p_value = 0;
}
}
@ -364,11 +375,11 @@ qboolean R_SpeedsMessage( char *out, size_t size )
return true;
}
void R_SpeedsRegisterMetric( int* p_value, const char *name, const char *unit ) {
void R_SpeedsRegisterMetric(int* p_value, const char *name, r_speeds_metric_type_t type) {
ASSERT(g_speeds.metrics_count < MAX_SPEEDS_METRICS);
r_speeds_metric_t *metric = g_speeds.metrics + (g_speeds.metrics_count++);
metric->p_value = p_value;
metric->name = name;
metric->unit = unit;
metric->type = type;
}

View File

@ -9,4 +9,10 @@ void R_ShowExtendedProfilingData(uint32_t prev_frame_index, uint64_t gpu_frame_b
// Called from the engine into ref_api to get the latest speeds info
qboolean R_SpeedsMessage( char *out, size_t size );
void R_SpeedsRegisterMetric( int* p_value, const char *name, const char *unit );
typedef enum {
kSpeedsMetricCount,
kSpeedsMetricBytes,
kSpeedsMetricMicroseconds,
} r_speeds_metric_type_t;
void R_SpeedsRegisterMetric(int* p_value, const char *name, r_speeds_metric_type_t type);

View File

@ -14,6 +14,7 @@
#include "vk_light.h"
#include "vk_mapents.h"
#include "vk_previous_frame.h"
#include "r_speeds.h"
#include "ref_params.h"
#include "eiface.h"
@ -30,6 +31,10 @@ typedef struct vk_brush_model_s {
static struct {
struct {
int num_vertices, num_indices;
int models_drawn;
int water_surfaces_drawn;
int water_polys_drawn;
} stat;
int rtable[MOD_FRAMES][MOD_FRAMES];
@ -57,6 +62,10 @@ qboolean VK_BrushInit( void )
{
VK_InitRandomTable ();
R_SpeedsRegisterMetric(&g_brush.stat.models_drawn, "models_brush", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_brush.stat.water_surfaces_drawn, "water_surfaces", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_brush.stat.water_polys_drawn, "water_polys", kSpeedsMetricCount);
return true;
}
@ -93,6 +102,8 @@ static void EmitWaterPolys( const cl_entity_t *ent, const msurface_t *warp, qboo
uint16_t *indices;
r_geometry_buffer_lock_t buffer;
++g_brush.stat.water_surfaces_drawn;
prev_time = R_PrevFrame_Time(ent->index);
#define MAX_WATER_VERTICES 16
@ -123,6 +134,8 @@ static void EmitWaterPolys( const cl_entity_t *ent, const msurface_t *warp, qboo
return;
}
g_brush.stat.water_polys_drawn += num_indices / 3;
indices = buffer.indices.ptr;
for( p = warp->polys; p; p = p->next )
@ -390,6 +403,8 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
if (bmodel->render_model.num_geometries == 0)
return;
++g_brush.stat.models_drawn;
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
vk_render_geometry_t *geom = bmodel->render_model.geometries + i;
const int surface_index = geom->surf - mod->surfaces;

View File

@ -102,9 +102,9 @@ qboolean VK_LightsInit( void ) {
return false;
}
R_SpeedsRegisterMetric(&g_lights_.stats.dirty_cells, "lights_dirty_cells", "");
R_SpeedsRegisterMetric(&g_lights_.stats.dirty_cells_size, "lights_dirty_cells_size", "KiB");
R_SpeedsRegisterMetric(&g_lights_.stats.ranges_uploaded, "lights_ranges_uploaded", "");
R_SpeedsRegisterMetric(&g_lights_.stats.dirty_cells, "lights_dirty_cells", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_lights_.stats.dirty_cells_size, "lights_dirty_cells_size", kSpeedsMetricBytes);
R_SpeedsRegisterMetric(&g_lights_.stats.ranges_uploaded, "lights_ranges_uploaded", kSpeedsMetricCount);
return true;
}
@ -1360,7 +1360,7 @@ void RT_LightsFrameEnd( void ) {
#endif
}
g_lights_.stats.dirty_cells_size = g_lights_.stats.dirty_cells * sizeof(struct LightCluster) / 1024;
g_lights_.stats.dirty_cells_size = g_lights_.stats.dirty_cells * sizeof(struct LightCluster);
debug_dump_lights.enabled = false;
APROF_SCOPE_END(finalize);

View File

@ -260,8 +260,8 @@ qboolean RT_VkAccelInit(void) {
g_accel.tlas_geom_buffer_addr = R_VkBufferGetDeviceAddress(g_accel.tlas_geom_buffer.buffer);
R_FlippingBuffer_Init(&g_accel.tlas_geom_buffer_alloc, MAX_ACCELS * 2);
R_SpeedsRegisterMetric(&g_accel_.stats.blas_count, "blas_count", "");
R_SpeedsRegisterMetric(&g_accel_.stats.accels_built, "accels_built", "");
R_SpeedsRegisterMetric(&g_accel_.stats.blas_count, "blas_count", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_accel_.stats.accels_built, "accels_built", kSpeedsMetricCount);
return true;
}

View File

@ -48,6 +48,7 @@ static struct {
struct {
int dynamic_model_count;
int models_count;
} stats;
} g_render;
@ -338,7 +339,8 @@ qboolean VK_RenderInit( void ) {
if (!createPipelines())
return false;
R_SpeedsRegisterMetric(&g_render.stats.dynamic_model_count, "models_dynamic", "");
R_SpeedsRegisterMetric(&g_render.stats.dynamic_model_count, "models_dynamic", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_render.stats.models_count, "models", kSpeedsMetricCount);
return true;
}
@ -602,6 +604,10 @@ void VK_RenderEnd( VkCommandBuffer cmdbuf )
case DrawLabelEnd:
vkCmdEndDebugUtilsLabelEXT(cmdbuf);
continue;
case DrawDraw:
// Continue drawing below
break;
}
if (ubo_offset != draw->draw.ubo_offset)
@ -711,6 +717,8 @@ void VK_RenderModelDraw( const cl_entity_t *ent, vk_render_model_t* model ) {
ASSERT(model->lightmap <= MAX_LIGHTMAPS);
const int lightmap = model->lightmap > 0 ? tglob.lightmapTextures[model->lightmap - 1] : tglob.whiteTexture;
++g_render.stats.models_count;
if (g_render_state.current_frame_is_ray_traced) {
if (ent != NULL && model != NULL) {
R_PrevFrame_SaveCurrentState( ent->index, g_render_state.model );

View File

@ -54,12 +54,12 @@ qboolean R_VkStagingInit(void) {
R_FlippingBuffer_Init(&g_staging.buffer_alloc, DEFAULT_STAGING_SIZE);
R_SpeedsRegisterMetric(&g_staging.stats.total_size, "staging_total_size", "KiB");
R_SpeedsRegisterMetric(&g_staging.stats.buffers_size, "staging_buffers_size", "KiB");
R_SpeedsRegisterMetric(&g_staging.stats.images_size, "staging_images_size", "KiB");
R_SpeedsRegisterMetric(&g_staging.stats.total_size, "staging_total_size", kSpeedsMetricBytes);
R_SpeedsRegisterMetric(&g_staging.stats.buffers_size, "staging_buffers_size", kSpeedsMetricBytes);
R_SpeedsRegisterMetric(&g_staging.stats.images_size, "staging_images_size", kSpeedsMetricBytes);
R_SpeedsRegisterMetric(&g_staging.stats.buffer_chunks, "staging_buffer_chunks", "");
R_SpeedsRegisterMetric(&g_staging.stats.images, "staging_images", "");
R_SpeedsRegisterMetric(&g_staging.stats.buffer_chunks, "staging_buffer_chunks", kSpeedsMetricCount);
R_SpeedsRegisterMetric(&g_staging.stats.images, "staging_images", kSpeedsMetricCount);
return true;
}
@ -275,9 +275,7 @@ VkCommandBuffer R_VkStagingFrameEnd(void) {
g_staging.upload_pool.buffers[1] = g_staging.upload_pool.buffers[2];
g_staging.upload_pool.buffers[2] = tmp;
g_staging.stats.total_size = (g_staging.stats.images_size + g_staging.stats.buffers_size) / 1024;
g_staging.stats.images_size /= 1024;
g_staging.stats.buffers_size /= 1024;
g_staging.stats.total_size = g_staging.stats.images_size + g_staging.stats.buffers_size;
return cmdbuf;
}