vk: do not crash on corrupted scopes stack

This is not a valid reason to assert/crash, even though it is clearly a programming mistake.
If the stack is corrupted, just print its contents as an S_ERROR and continue.

Also:
- Fix the ultimate reason for stack being unbalanced for #604
- Do not analyze scopes when not needed, i.e. when `r_speeds` is zero.

Fixes #604
This commit is contained in:
Ivan 'provod' Avdeev 2023-10-31 11:58:30 -04:00 committed by Ivan Avdeev
parent f1c8b3ef2f
commit 5698746f42
2 changed files with 20 additions and 4 deletions

View File

@ -213,10 +213,24 @@ static void drawCPUProfilerScopes(int draw, const aprof_event_t *events, uint64_
ASSERT(depth > 0);
--depth;
ASSERT(stack[depth].scope_id == scope_id);
ASSERT(scope_id >= 0);
ASSERT(scope_id < APROF_MAX_SCOPES);
if (stack[depth].scope_id != scope_id) {
gEngine.Con_Printf(S_ERROR "scope_id mismatch at stack depth=%d: found %d(%s), expected %d(%s)\n",
depth,
scope_id, g_aprof.scopes[scope_id].name,
stack[depth].scope_id, g_aprof.scopes[stack[depth].scope_id].name);
gEngine.Con_Printf(S_ERROR "Full stack:\n");
for (int i = depth; i >= 0; --i) {
gEngine.Con_Printf(S_ERROR " %d: scope_id=%d(%s)\n", i,
stack[i].scope_id, g_aprof.scopes[stack[i].scope_id].name);
}
return;
}
const aprof_scope_t *const scope = g_aprof.scopes + scope_id;
const uint64_t delta_ns = timestamp_ns - stack[depth].begin_ns;
@ -482,7 +496,7 @@ static void drawGPUProfilerScopes(qboolean draw, int y, uint64_t frame_begin_tim
}
}
static int drawFrames( int draw, uint32_t prev_frame_index, int y, const vk_combuf_scopes_t *gpurofls, int gpurofls_count) {
static int analyzeScopesAndDrawFrames( int draw, uint32_t prev_frame_index, int y, const vk_combuf_scopes_t *gpurofls, int gpurofls_count) {
// Draw latest 2 frames; find their boundaries
uint32_t rewind_frame = prev_frame_index;
const int max_frames_to_draw = 2;
@ -974,10 +988,11 @@ void R_SpeedsDisplayMore(uint32_t prev_frame_index, const struct vk_combuf_scope
handlePause( prev_frame_index );
if (speeds_bits != 0)
{
int y = 100;
const int draw_frame = speeds_bits & SPEEDS_BIT_FRAME;
y = drawFrames( draw_frame, prev_frame_index, y, gpurofl, gpurofl_count );
y = analyzeScopesAndDrawFrames( draw_frame, prev_frame_index, y, gpurofl, gpurofl_count );
const int draw_graphs = speeds_bits & SPEEDS_BIT_GRAPHS;
if (draw_graphs)

View File

@ -558,7 +558,7 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
// Do not draw when we have no swapchain
if (args->dst.image_view == VK_NULL_HANDLE)
return;
goto tail;
if (g_ray_model_state.frame.instances_count == 0) {
const r_vkimage_blit_args blit_args = {
@ -592,6 +592,7 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
performTracing( args->combuf, &trace_args );
}
tail:
APROF_SCOPE_END(ray_frame_end);
}