generate visual profiler zones in pre pass
This commit is contained in:
parent
aa78bf649a
commit
b7c454e7ef
@ -604,7 +604,7 @@ i32 W32_Main(void)
|
||||
i64 start_tsc;
|
||||
i64 end_tsc;
|
||||
// Collect samples
|
||||
u32 tsc_sleep_calibration_ms = 20;
|
||||
u32 tsc_sleep_calibration_ms = 10;
|
||||
{
|
||||
start_tsc = __rdtsc();
|
||||
QueryPerformanceCounter(&start_qpc);
|
||||
|
||||
@ -5730,6 +5730,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
f64 view_start_ns = profiler->view_ns;
|
||||
f64 view_end_ns = view_start_ns + view_range_len_ns;
|
||||
|
||||
f64 view_start_px = view_start_ns / profiler->ns_per_px;
|
||||
f64 view_end_px = view_end_ns / profiler->ns_per_px;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -5745,20 +5748,28 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
|
||||
//- Visible zones
|
||||
Struct(VisRow)
|
||||
Struct(VisZone)
|
||||
{
|
||||
VisRow *next;
|
||||
V_ZoneRow *zone_row;
|
||||
V_ZoneChunk *closest_zone_chunk;
|
||||
VisZone *next;
|
||||
u32 depth;
|
||||
u64 id;
|
||||
String name;
|
||||
Vec4 color;
|
||||
|
||||
f64 start_px;
|
||||
f64 len_px;
|
||||
|
||||
i64 elapsed_ns;
|
||||
};
|
||||
|
||||
Struct(VisTrack)
|
||||
{
|
||||
VisTrack *next;
|
||||
V_ZoneTrack *zone_track;
|
||||
u64 id;
|
||||
|
||||
VisRow *first_row;
|
||||
VisRow *last_row;
|
||||
u32 rows_count;
|
||||
VisZone *first_zone;
|
||||
VisZone *last_zone;
|
||||
};
|
||||
|
||||
VisTrack *first_vis_track = 0;
|
||||
@ -5772,7 +5783,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
// TODO: Ignore non-visible tracks
|
||||
VisTrack *vis_track = PushStruct(frame->arena, VisTrack);
|
||||
SllQueuePush(first_vis_track, last_vis_track, vis_track);
|
||||
vis_track->zone_track = zone_track;
|
||||
vis_track->id = zone_track->id;
|
||||
|
||||
// TODO: Ignore non-visible rows
|
||||
for (u64 row_idx = 0; row_idx < zone_track->rows_count; ++row_idx)
|
||||
@ -5792,10 +5803,54 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
if (closest_start->end_ns >= view_start_ns && closest_start->start_ns <= view_end_ns)
|
||||
{
|
||||
VisRow *vis_row = PushStruct(perm, VisRow);
|
||||
SllQueuePush(vis_track->first_row, vis_track->last_row, vis_row);
|
||||
vis_row->zone_row = zone_row;
|
||||
vis_row->closest_zone_chunk = closest_start;
|
||||
f32 zone_collapse_threshold_px = 5;
|
||||
for (V_ZoneChunk *chunk = closest_start; chunk && chunk->start_ns <= view_end_ns; chunk = chunk->nexts[0])
|
||||
{
|
||||
i64 visual_chunk_start_ns = MaxI64(chunk->start_ns, profiler->view_ns);
|
||||
i64 visual_chunk_end_ns = MinI64(chunk->end_ns, profiler->view_ns + view_range_len_ns);
|
||||
f64 visual_chunk_len_px = (visual_chunk_end_ns - visual_chunk_start_ns) / profiler->ns_per_px;
|
||||
|
||||
b32 should_collapse_chunk = visual_chunk_len_px <= zone_collapse_threshold_px;
|
||||
|
||||
if (!should_collapse_chunk)
|
||||
{
|
||||
b32 reached_end_of_view = 0;
|
||||
for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->zones_count && !reached_end_of_view; ++chunk_zone_idx)
|
||||
{
|
||||
V_Zone *zone = &chunk->zones[chunk_zone_idx];
|
||||
|
||||
i64 zone_start_ns = zone->start_ns;
|
||||
i64 zone_end_ns = MinI64(zone->end_ns, frame->time_ns);
|
||||
i64 zone_elapsed_ns = zone_end_ns - zone_start_ns;
|
||||
|
||||
i64 visual_zone_start_ns = MaxI64(zone_start_ns, profiler->view_ns);
|
||||
i64 visual_zone_end_ns = MinI64(zone_end_ns, profiler->view_ns + view_range_len_ns);
|
||||
f64 visual_zone_start_px = visual_zone_start_ns / profiler->ns_per_px;
|
||||
f64 visual_zone_len_px = (visual_zone_end_ns - visual_zone_start_ns) / profiler->ns_per_px;
|
||||
|
||||
b32 zone_should_collapse = visual_zone_len_px <= zone_collapse_threshold_px;
|
||||
|
||||
if (visual_zone_start_ns > view_end_ns)
|
||||
{
|
||||
reached_end_of_view = 1;
|
||||
}
|
||||
|
||||
if (visual_zone_end_ns >= view_start_ns && visual_zone_start_ns <= view_end_ns && !zone_should_collapse)
|
||||
{
|
||||
VisZone *vis_zone = PushStruct(frame->arena, VisZone);
|
||||
SllQueuePush(vis_track->first_zone, vis_track->last_zone, vis_zone);
|
||||
vis_zone->name = zone->name;
|
||||
vis_zone->id = zone->id;
|
||||
vis_zone->color = zone->color;
|
||||
vis_zone->start_px = visual_zone_start_px;
|
||||
vis_zone->len_px = visual_zone_len_px;
|
||||
vis_zone->elapsed_ns = zone_elapsed_ns;
|
||||
vis_zone->depth = row_idx;
|
||||
vis_track->rows_count = MaxU32(vis_track->rows_count, vis_zone->depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5827,7 +5882,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_Size timeline_cursor_width = UI_Fnt(0.15, 1);
|
||||
|
||||
UI_Key hovered_zone_box = Zi;
|
||||
V_Zone *hovered_zone = 0;
|
||||
VisZone *hovered_zone = 0;
|
||||
f64 ruler_len_ns = 0;
|
||||
|
||||
Vec4 main_color_sampled = profiler_color;
|
||||
@ -5926,79 +5981,57 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
//- Zone tracks
|
||||
ProfZoneDF("Build zones")
|
||||
{
|
||||
f32 zone_collapse_threshold_px = 5;
|
||||
for (VisTrack *vis_track = first_vis_track; vis_track; vis_track = vis_track->next)
|
||||
{
|
||||
V_ZoneTrack *zone_track = vis_track->zone_track;
|
||||
|
||||
UI_SetNext(Height, track_height);
|
||||
UI_SetDF(Tag, HashF("vis track %F", FmtUint(vis_track->id)))
|
||||
UI_SetDF(Parent, UI_BuildColumn())
|
||||
{
|
||||
for (VisRow *row = vis_track->first_row; row; row = row->next)
|
||||
//- Zone rows
|
||||
UI_Key *zone_row_boxes = PushStructs(frame->arena, UI_Key, vis_track->rows_count);
|
||||
for (u64 zone_row_box_idx = 0; zone_row_box_idx < vis_track->rows_count; ++zone_row_box_idx)
|
||||
{
|
||||
//- Zone row
|
||||
UI_Key zone_row_box = UI_KeyF("zone row %F", FmtUint(zone_row_box_idx));
|
||||
zone_row_boxes[zone_row_box_idx] = zone_row_box;
|
||||
// UI_SetNext(Height, zone_height);
|
||||
UI_SetNext(Height, zone_height);
|
||||
UI_SetDF(Parent, UI_BuildRow())
|
||||
UI_SetDF(Parent, UI_BuildRowEx(zone_row_box))
|
||||
{
|
||||
for (V_ZoneChunk *chunk = row->closest_zone_chunk; chunk && chunk->start_ns <= view_end_ns; chunk = chunk->nexts[0])
|
||||
{
|
||||
i64 visual_chunk_start_ns = MaxI64(chunk->start_ns, profiler->view_ns);
|
||||
i64 visual_chunk_end_ns = MinI64(chunk->end_ns, profiler->view_ns + view_range_len_ns);
|
||||
f64 visual_chunk_len_px = (visual_chunk_end_ns - visual_chunk_start_ns) / profiler->ns_per_px;
|
||||
}
|
||||
}
|
||||
|
||||
b32 should_collapse_chunk = visual_chunk_len_px <= zone_collapse_threshold_px;
|
||||
//- Zones
|
||||
for (VisZone *zone = vis_track->first_zone; zone; zone = zone->next)
|
||||
{
|
||||
UI_Key zone_row_box = zone_row_boxes[zone->depth];
|
||||
|
||||
if (!should_collapse_chunk)
|
||||
{
|
||||
b32 reached_end_of_view = 0;
|
||||
for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->zones_count && !reached_end_of_view; ++chunk_zone_idx)
|
||||
{
|
||||
V_Zone *zone = &chunk->zones[chunk_zone_idx];
|
||||
|
||||
i64 zone_start_ns = zone->start_ns;
|
||||
i64 zone_end_ns = MinI64(zone->end_ns, frame->time_ns);
|
||||
|
||||
i64 visual_zone_start_ns = MaxI64(zone_start_ns, profiler->view_ns);
|
||||
i64 visual_zone_end_ns = MinI64(zone_end_ns, profiler->view_ns + view_range_len_ns);
|
||||
f64 visual_zone_len_px = (visual_zone_end_ns - visual_zone_start_ns) / profiler->ns_per_px;
|
||||
|
||||
b32 zone_should_collapse = visual_zone_len_px <= zone_collapse_threshold_px;
|
||||
|
||||
if (visual_zone_start_ns > view_end_ns)
|
||||
{
|
||||
reached_end_of_view = 1;
|
||||
}
|
||||
|
||||
if (visual_zone_end_ns >= view_start_ns && visual_zone_start_ns <= view_end_ns && !zone_should_collapse)
|
||||
{
|
||||
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id));
|
||||
if (UI_HotAbsolute(zone_box))
|
||||
{
|
||||
hovered_zone_box = zone_box;
|
||||
hovered_zone = zone;
|
||||
}
|
||||
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id));
|
||||
if (UI_HotAbsolute(zone_box))
|
||||
{
|
||||
hovered_zone_box = zone_box;
|
||||
hovered_zone = zone;
|
||||
}
|
||||
|
||||
|
||||
Vec4 zone_color = zone->color;
|
||||
// Vec4 zone_color_bd = Zi;
|
||||
Vec4 zone_color_bd = zone_color;
|
||||
Vec4 zone_color = zone->color;
|
||||
// Vec4 zone_color_bd = Zi;
|
||||
Vec4 zone_color_bd = zone_color;
|
||||
|
||||
// Vec4 zone_color_dim = VEC4(0.15, 0.15, 0.15, 0);
|
||||
// zone_color_bd.r -= zone_color_dim.r;
|
||||
// zone_color_bd.g -= zone_color_dim.g;
|
||||
// zone_color_bd.b -= zone_color_dim.b;
|
||||
// Vec4 zone_color_dim = VEC4(0.15, 0.15, 0.15, 0);
|
||||
// zone_color_bd.r -= zone_color_dim.r;
|
||||
// zone_color_bd.g -= zone_color_dim.g;
|
||||
// zone_color_bd.b -= zone_color_dim.b;
|
||||
|
||||
zone_color_bd = MulVec4(zone_color_bd, 0.65);
|
||||
zone_color_bd.a = 1;
|
||||
zone_color_bd = MulVec4(zone_color_bd, 0.65);
|
||||
zone_color_bd.a = 1;
|
||||
|
||||
Vec4 zone_text_color = UI_Top(TextColor);
|
||||
zone_text_color.a *= 0.75;
|
||||
Vec4 zone_text_color = UI_Top(TextColor);
|
||||
zone_text_color.a *= 0.75;
|
||||
|
||||
|
||||
// zone_color_bd = LerpSrgb(zone_color_bd, theme.col.button_selected, UI_Hot(zone_box));
|
||||
// zone_color_bd = LerpSrgb(zone_color_bd, theme.col.button_active, UI_Hot(zone_box));
|
||||
zone_color_bd = LerpSrgb(zone_color_bd, Color_White, UI_Hot(zone_box));
|
||||
// zone_color_bd = LerpSrgb(zone_color_bd, theme.col.button_selected, UI_Hot(zone_box));
|
||||
// zone_color_bd = LerpSrgb(zone_color_bd, theme.col.button_active, UI_Hot(zone_box));
|
||||
zone_color_bd = LerpSrgb(zone_color_bd, Color_White, UI_Hot(zone_box));
|
||||
|
||||
|
||||
|
||||
@ -6007,76 +6040,71 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
|
||||
|
||||
f64 zone_offset_px = (visual_zone_start_ns - profiler->view_ns) / profiler->ns_per_px;
|
||||
f64 zone_len_ns = visual_zone_end_ns - visual_zone_start_ns;
|
||||
f64 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
f64 zone_offset_px = zone->start_px - view_start_px;
|
||||
f64 zone_len_px = zone->len_px;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// f64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// f64 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// f64 zone_offset_px = (zone->end_ns - profiler->view_ns) / profiler->ns_per_px;
|
||||
// f64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// f64 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// f64 zone_offset_px = (zone->end_ns - profiler->view_ns) / profiler->ns_per_px;
|
||||
|
||||
// // f64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// // f64 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// // f32 zone_offset_px = (zone->start_ns - profiler->view_ns) / profiler->ns_per_px;
|
||||
// // f64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// // f64 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// // f32 zone_offset_px = (zone->start_ns - profiler->view_ns) / profiler->ns_per_px;
|
||||
|
||||
|
||||
Vec2 zone_pos = VEC2(zone_offset_px, 0);
|
||||
UI_Size zone_width = UI_Px(zone_len_px, 1);
|
||||
Vec2 zone_pos = VEC2(zone_offset_px, 0);
|
||||
UI_Size zone_width = UI_Px(zone_len_px, 1);
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Remove this
|
||||
UI_SetNext(Text, StringF(frame->arena, "ZONE %F", FmtUint(zone->id)));
|
||||
// TODO: Remove this
|
||||
UI_SetNext(Text, StringF(frame->arena, "ZONE %F", FmtUint(zone->id)));
|
||||
|
||||
|
||||
// if (do_break && UI_IsMouseHovered(zone_box))
|
||||
if (do_break && zone->id == 0)
|
||||
{
|
||||
// UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback | UI_DebugBreakFlag_CheckCursorHover);
|
||||
}
|
||||
// if (do_break && UI_IsMouseHovered(zone_box))
|
||||
if (do_break && zone->id == 0)
|
||||
{
|
||||
// UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback | UI_DebugBreakFlag_CheckCursorHover);
|
||||
}
|
||||
|
||||
|
||||
|
||||
UI_SetNext(Width, zone_width);
|
||||
UI_SetNext(Height, UI_Grow(1, 0));
|
||||
UI_SetNext(BackgroundColor, zone_color);
|
||||
UI_SetNext(BorderColor, zone_color_bd);
|
||||
UI_SetNext(BorderSize, 1);
|
||||
UI_SetNext(FloatingPos, zone_pos);
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_Scissor);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY);
|
||||
UI_SetDF(Parent, UI_BuildRowEx(zone_box))
|
||||
{
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0.25), Axis_X);
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0), Axis_X);
|
||||
// UI_BuildSpacer(UI_Grow(1, 0), Axis_X);
|
||||
UI_SetNext(Width, zone_width);
|
||||
UI_SetNext(Height, UI_Grow(1, 0));
|
||||
UI_SetNext(BackgroundColor, zone_color);
|
||||
UI_SetNext(BorderColor, zone_color_bd);
|
||||
UI_SetNext(BorderSize, 1);
|
||||
UI_SetNext(FloatingPos, zone_pos);
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_Scissor);
|
||||
UI_SetNext(Parent, zone_row_box);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY);
|
||||
UI_SetDF(Parent, UI_BuildRowEx(zone_box))
|
||||
{
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0.25), Axis_X);
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0), Axis_X);
|
||||
// UI_BuildSpacer(UI_Grow(1, 0), Axis_X);
|
||||
|
||||
// UI_SetNext(Width, UI_Shrink(0, 1));
|
||||
UI_SetNext(Width, UI_Shrink(0, 0));
|
||||
// UI_SetNext(Width, UI_Grow(1, 1));
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
// UI_SetNext(ChildAlignment, UI_Region_Left);
|
||||
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5);
|
||||
UI_SetNext(TextColor, zone_text_color);
|
||||
UI_SetNext(Text, zone->name);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText);
|
||||
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
||||
UI_BuildRow();
|
||||
// UI_SetNext(Width, UI_Shrink(0, 1));
|
||||
UI_SetNext(Width, UI_Shrink(0, 0));
|
||||
// UI_SetNext(Width, UI_Grow(1, 1));
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
// UI_SetNext(ChildAlignment, UI_Region_Left);
|
||||
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5);
|
||||
UI_SetNext(TextColor, zone_text_color);
|
||||
UI_SetNext(Text, zone->name);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText);
|
||||
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
||||
UI_BuildRow();
|
||||
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 1), Axis_X);
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0), Axis_X);
|
||||
// UI_BuildSpacer(UI_Grow(1, 0), Axis_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 1), Axis_X);
|
||||
// UI_BuildSpacer(UI_Px(zone_text_padding_px, 0), Axis_X);
|
||||
// UI_BuildSpacer(UI_Grow(1, 0), Axis_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6196,9 +6224,8 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
if (show_hovered_zone)
|
||||
{
|
||||
V_Zone *zone = hovered_zone;
|
||||
VisZone *zone = hovered_zone;
|
||||
// UI_BuildLabelF("Hi!!");
|
||||
i64 zone_elapsed_ns = zone->end_ns - zone->start_ns;
|
||||
|
||||
|
||||
|
||||
@ -6208,7 +6235,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(TextColor, theme.col.hint);
|
||||
UI_BuildLabelF("%F: ", FmtString(zone->name));
|
||||
|
||||
UI_BuildLabelF("%F", FmtTimeNs(zone_elapsed_ns, .p = 2));
|
||||
UI_BuildLabelF("%F", FmtTimeNs(zone->elapsed_ns, .p = 2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user