vk: profiler: simplify metric registration

This commit is contained in:
Ivan Avdeev 2023-03-25 10:20:45 -07:00 committed by Ivan Avdeev
parent cdc2a1258a
commit 8ecfae5bf0
6 changed files with 49 additions and 65 deletions

View File

@ -24,6 +24,12 @@ enum {
// These bits can be combined, e.g. `r_speeds 9`, 8+1, will display 1: basic timing info and 8: frame graphs
};
typedef struct {
int *p_value;
const char *name;
const char *unit;
// int low_watermark, high_watermark;
} r_speeds_metric_t;
static struct {
float frame_times[MAX_FRAMES_HISTORY];
@ -261,7 +267,8 @@ 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->value, metric->unit);
speedsPrintf("%s: %d%s\n", metric->name, *metric->p_value, metric->unit);
*metric->p_value = 0;
}
}
@ -357,12 +364,11 @@ qboolean R_SpeedsMessage( char *out, size_t size )
return true;
}
r_speeds_metric_t *R_SpeedsRegisterMetric( const char *name, const char *unit ) {
void R_SpeedsRegisterMetric( int* p_value, const char *name, const char *unit ) {
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;
return metric;
}

View File

@ -9,11 +9,4 @@ 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 );
typedef struct {
int value;
const char *name;
const char *unit;
// int low_watermark, high_watermark;
} r_speeds_metric_t;
r_speeds_metric_t *R_SpeedsRegisterMetric( const char *name, const char *unit );
void R_SpeedsRegisterMetric( int* p_value, const char *name, const char *unit );

View File

@ -66,9 +66,9 @@ static struct {
uint32_t frame_sequence;
struct {
r_speeds_metric_t *dirty_cells;
r_speeds_metric_t *dirty_cells_size;
r_speeds_metric_t *ranges_uploaded;
int dirty_cells;
int dirty_cells_size;
int ranges_uploaded;
} stats;
} g_lights_;
@ -102,9 +102,9 @@ qboolean VK_LightsInit( void ) {
return false;
}
g_lights_.stats.dirty_cells = R_SpeedsRegisterMetric("lights_dirty_cells", "");
g_lights_.stats.dirty_cells_size = R_SpeedsRegisterMetric("lights_dirty_cells_size", "KiB");
g_lights_.stats.ranges_uploaded = R_SpeedsRegisterMetric("lights_ranges_uploaded", "");
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", "");
return true;
}
@ -530,7 +530,7 @@ static qboolean addSurfaceLightToCell( int cell_index, int polygon_light_index )
cluster->polygons[cluster->num_polygons++] = polygon_light_index;
if (cluster->frame_sequence != g_lights_.frame_sequence) {
++g_lights_.stats.dirty_cells->value;
++g_lights_.stats.dirty_cells;
cluster->frame_sequence = g_lights_.frame_sequence;
}
return true;
@ -549,7 +549,7 @@ static qboolean addLightToCell( int cell_index, int light_index ) {
cluster->point_lights[cluster->num_point_lights++] = light_index;
if (cluster->frame_sequence != g_lights_.frame_sequence) {
++g_lights_.stats.dirty_cells->value;
++g_lights_.stats.dirty_cells;
cluster->frame_sequence = g_lights_.frame_sequence;
}
return true;
@ -947,7 +947,7 @@ void RT_LightsLoadEnd( void ) {
}
}
g_lights_.stats.dirty_cells->value = g_lights.map.grid_cells;
g_lights_.stats.dirty_cells = g_lights.map.grid_cells;
}
qboolean RT_GetEmissiveForTexture( vec3_t out, int texture_id ) {
@ -1134,9 +1134,6 @@ void RT_LightsFrameBegin( void ) {
g_lights_.num_point_lights = g_lights_.num_static.point_lights;
g_lights_.num_polygon_vertices = g_lights_.num_static.polygon_vertices;
g_lights_.stats.dirty_cells->value = 0;
g_lights_.stats.dirty_cells_size->value = 0;
for (int i = 0; i < g_lights.map.grid_cells; ++i) {
vk_lights_cell_t *const cell = g_lights.cells + i;
cell->num_polygons = cell->num_static.polygons;
@ -1173,14 +1170,12 @@ static void uploadGridRange( int begin, int end ) {
R_VkStagingUnlock( locked.handle );
g_lights_.stats.ranges_uploaded->value++;
g_lights_.stats.ranges_uploaded++;
}
static void uploadGrid( void ) {
ASSERT(g_lights.map.grid_cells <= MAX_LIGHT_CLUSTERS);
g_lights_.stats.ranges_uploaded->value = 0;
int begin = -1;
for (int i = 0; i < g_lights.map.grid_cells; ++i) {
const vk_lights_cell_t *const cell = g_lights.cells + i;
@ -1365,7 +1360,7 @@ void RT_LightsFrameEnd( void ) {
#endif
}
g_lights_.stats.dirty_cells_size->value = g_lights_.stats.dirty_cells->value * sizeof(struct LightCluster) / 1024;
g_lights_.stats.dirty_cells_size = g_lights_.stats.dirty_cells * sizeof(struct LightCluster) / 1024;
debug_dump_lights.enabled = false;
APROF_SCOPE_END(finalize);

View File

@ -12,8 +12,8 @@ struct rt_vk_ray_accel_s g_accel = {0};
static struct {
struct {
r_speeds_metric_t *blas_count;
r_speeds_metric_t *accels_built;
int blas_count;
int accels_built;
} stats;
} g_accel_;
@ -120,7 +120,7 @@ qboolean createOrUpdateAccelerationStructure(VkCommandBuffer cmdbuf, const as_bu
//gEngine.Con_Reportf("AS=%p, n_geoms=%u, scratch: %#x %d %#x\n", *args->p_accel, args->n_geoms, scratch_offset_initial, scratch_buffer_size, scratch_offset_initial + scratch_buffer_size);
g_accel_.stats.accels_built->value++;
g_accel_.stats.accels_built++;
vkCmdBuildAccelerationStructuresKHR(cmdbuf, 1, &build_info, &args->build_ranges);
return true;
}
@ -207,7 +207,7 @@ void RT_VkAccelPrepareTlas(VkCommandBuffer cmdbuf) {
}
}
g_accel_.stats.blas_count->value = g_ray_model_state.frame.num_models;
g_accel_.stats.blas_count = g_ray_model_state.frame.num_models;
// Barrier for building all BLASes
// BLAS building is now in cmdbuf, need to synchronize with results
@ -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);
g_accel_.stats.blas_count = R_SpeedsRegisterMetric("blas_count", "");
g_accel_.stats.accels_built = R_SpeedsRegisterMetric("accels_built", "");
R_SpeedsRegisterMetric(&g_accel_.stats.blas_count, "blas_count", "");
R_SpeedsRegisterMetric(&g_accel_.stats.accels_built, "accels_built", "");
return true;
}
@ -313,6 +313,4 @@ void RT_VkAccelNewMap(void) {
void RT_VkAccelFrameBegin(void) {
g_accel.frame.scratch_offset = 0;
g_accel_.stats.accels_built->value = 0;
g_accel_.stats.blas_count->value = 0;
}

View File

@ -47,7 +47,7 @@ static struct {
float fov_angle_y;
struct {
r_speeds_metric_t *models_dynamic;
int dynamic_model_count;
} stats;
} g_render;
@ -338,7 +338,7 @@ qboolean VK_RenderInit( void ) {
if (!createPipelines())
return false;
g_render.stats.models_dynamic = R_SpeedsRegisterMetric("models_dynamic", "");
R_SpeedsRegisterMetric(&g_render.stats.dynamic_model_count, "models_dynamic", "");
return true;
}
@ -363,8 +363,6 @@ enum {
void VK_RenderBegin( qboolean ray_tracing ) {
APROF_SCOPE_BEGIN(renderbegin);
g_render.stats.models_dynamic->value = 0;
g_render_state.uniform_data_set_mask = UNIFORM_UNSET;
g_render_state.current_ubo_offset_FIXME = UINT32_MAX;
memset(&g_render_state.current_uniform_data, 0, sizeof(g_render_state.current_uniform_data));
@ -815,7 +813,7 @@ void VK_RenderModelDynamicCommit( void ) {
ASSERT(g_dynamic_model.model.geometries);
if (g_dynamic_model.model.num_geometries > 0) {
g_render.stats.models_dynamic->value++;
g_render.stats.dynamic_model_count++;
g_dynamic_model.model.dynamic = true;
VK_RenderModelInit( &g_dynamic_model.model );
VK_RenderModelDraw( NULL, &g_dynamic_model.model );

View File

@ -38,11 +38,11 @@ static struct {
VkCommandBuffer cmdbuf;
struct {
r_speeds_metric_t *total_size;
r_speeds_metric_t *buffers_size;
r_speeds_metric_t *images_size;
r_speeds_metric_t *buffer_chunks;
r_speeds_metric_t *images;
int total_size;
int buffers_size;
int images_size;
int buffer_chunks;
int images;
} stats;
} g_staging = {0};
@ -54,12 +54,12 @@ qboolean R_VkStagingInit(void) {
R_FlippingBuffer_Init(&g_staging.buffer_alloc, DEFAULT_STAGING_SIZE);
g_staging.stats.total_size = R_SpeedsRegisterMetric("staging_total_size", "KiB");
g_staging.stats.buffers_size = R_SpeedsRegisterMetric("staging_buffers_size", "KiB");
g_staging.stats.images_size = R_SpeedsRegisterMetric("staging_images_size", "KiB");
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");
g_staging.stats.buffer_chunks = R_SpeedsRegisterMetric("staging_buffer_chunks", "");
g_staging.stats.images = R_SpeedsRegisterMetric("staging_images", "");
R_SpeedsRegisterMetric(&g_staging.stats.buffer_chunks, "staging_buffer_chunks", "");
R_SpeedsRegisterMetric(&g_staging.stats.images, "staging_images", "");
return true;
}
@ -189,13 +189,13 @@ static void commitBuffers(VkCommandBuffer cmdbuf) {
if (prev_buffer != VK_NULL_HANDLE) {
DEBUG_NV_CHECKPOINTF(cmdbuf, "staging dst_buffer=%p count=%d", prev_buffer, i-first_copy);
g_staging.stats.buffer_chunks->value++;
g_staging.stats.buffer_chunks++;
vkCmdCopyBuffer(cmdbuf, g_staging.buffer.buffer,
prev_buffer,
i - first_copy, g_staging.buffers.copy + first_copy);
}
g_staging.stats.buffers_size->value += g_staging.buffers.copy[i].size;
g_staging.stats.buffers_size += g_staging.buffers.copy[i].size;
prev_buffer = g_staging.buffers.dest[i];
first_copy = i;
@ -203,7 +203,7 @@ static void commitBuffers(VkCommandBuffer cmdbuf) {
if (prev_buffer != VK_NULL_HANDLE) {
DEBUG_NV_CHECKPOINTF(cmdbuf, "staging dst_buffer=%p count=%d", prev_buffer, g_staging.buffers.count-first_copy);
g_staging.stats.buffer_chunks->value++;
g_staging.stats.buffer_chunks++;
vkCmdCopyBuffer(cmdbuf, g_staging.buffer.buffer,
prev_buffer,
g_staging.buffers.count - first_copy, g_staging.buffers.copy + first_copy);
@ -219,8 +219,8 @@ static void commitImages(VkCommandBuffer cmdbuf) {
/* gEngine.Con_Reportf(" i%d: [%08llx, ?) => %p\n", i, copy->bufferOffset, g_staging.images.dest[i].image); */
/* } */
g_staging.stats.images->value++;
g_staging.stats.images_size->value += g_staging.images.dest[i].size;
g_staging.stats.images++;
g_staging.stats.images_size += g_staging.images.dest[i].size;
vkCmdCopyBufferToImage(cmdbuf, g_staging.buffer.buffer,
g_staging.images.dest[i].image,
@ -261,12 +261,6 @@ void R_VkStagingFrameBegin(void) {
g_staging.buffers.count = 0;
g_staging.images.count = 0;
g_staging.stats.images->value = 0;
g_staging.stats.buffer_chunks->value = 0;
g_staging.stats.total_size->value = 0;
g_staging.stats.buffers_size->value = 0;
g_staging.stats.images_size->value = 0;
}
VkCommandBuffer R_VkStagingFrameEnd(void) {
@ -281,9 +275,9 @@ 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->value = (g_staging.stats.images_size->value + g_staging.stats.buffers_size->value) / 1024;
g_staging.stats.images_size->value /= 1024;
g_staging.stats.buffers_size->value /= 1024;
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;
return cmdbuf;
}