store chunk zone start time

This commit is contained in:
jacob 2026-04-01 02:45:30 -05:00
parent ef5b79e52f
commit 9ef91e48a0
3 changed files with 125 additions and 118 deletions

View File

@ -3862,7 +3862,7 @@ G_BackbufferHandle G_PrepareBackbuffer(G_SwapchainHandle swapchain_handle, G_For
// Wait for available backbuffer
if (swapchain->waitable)
{
ProfZoneDF("Wait on swapchain")
ProfZoneDF("Wait for swapchain")
{
DWORD wait_result = WaitForSingleObject(swapchain->waitable, 500);
if (wait_result == WAIT_TIMEOUT)

View File

@ -5454,6 +5454,7 @@ void V_TickForever(WaveLaneCtx *lane)
if (chunk->zones_count >= V_MaxZonesPerChunk || is_first_chunk)
{
chunk = PushStruct(perm, V_ZoneChunk);
chunk->start_ns = sample_time_ns;
chunk->end_ns = I64Max;
for (u32 level = 0; level < V_ZoneChunkLevelsCount; ++level)
{
@ -5487,17 +5488,16 @@ void V_TickForever(WaveLaneCtx *lane)
// TODO: More efficient name processing
char *name_cstr = sample->name_cstr_lit;
String name = StringFromCstrNoLimit(name_cstr);
zone->name = name;
u64 color_seed = HashString(name);
f32 h = (Norm16(color_seed >> 0) * 1) * 360;
f32 s = TweakFloat("Profiler zone saturation", 0.50, 0, 1);
f32 v = TweakFloat("Profiler zone brightness", 1.00, 0, 1);
zone->color = SrgbFromHsv(h, s, v);
zone->name = name;
}
zone_track->rows_count = MaxU64(zone_track->rows_count, zone_track->current_sample_depth);
zone_track->rows_count = MaxU64(zone_track->rows_count, zone_track->current_sample_depth + 1);
}
zone_track->current_sample_depth += 1;
}
@ -5537,7 +5537,8 @@ void V_TickForever(WaveLaneCtx *lane)
V_Profiler *profiler = &frame->profiler;
f64 min_profiler_ns_per_px = 1;
f64 max_profiler_ns_per_px = NsFromSeconds(100);
// f64 max_profiler_ns_per_px = NsFromSeconds(100);
f64 max_profiler_ns_per_px = frame->time_ns / 10;
profiler->target_ns_per_px = ClampF64(profiler->target_ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px);
profiler->ns_per_px = ClampF64(profiler->ns_per_px, min_profiler_ns_per_px, max_profiler_ns_per_px);
@ -5789,8 +5790,6 @@ 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);
@ -5889,7 +5888,7 @@ void V_TickForever(WaveLaneCtx *lane)
//- Main area
UI_SetNext(BackgroundColor, main_color_unsampled);
UI_SetNext(Height, main_height);
UI_SetNext(Rounding, UI_Rpx(10));
UI_SetNext(Rounding, UI_Rpx(5 * theme.rounding));
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren | UI_BoxFlag_Scissor);
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren);
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
@ -5926,6 +5925,7 @@ void V_TickForever(WaveLaneCtx *lane)
//- Zone tracks
{
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;
@ -5942,125 +5942,132 @@ void V_TickForever(WaveLaneCtx *lane)
{
for (V_ZoneChunk *chunk = row->closest_zone_chunk; chunk && chunk->start_ns <= view_end_ns; chunk = chunk->nexts[0])
{
b32 reached_end_of_visible_chunk = 0;
for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->zones_count && !reached_end_of_visible_chunk; ++chunk_zone_idx)
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;
if (visual_chunk_len_px > zone_collapse_threshold_px)
{
V_Zone *zone = &chunk->zones[chunk_zone_idx];
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;
if (visual_zone_start_ns > view_end_ns || zone->end_ns == I64Max)
b32 reached_end_of_visible_chunk = 0;
for (u64 chunk_zone_idx = 0; chunk_zone_idx < chunk->zones_count && !reached_end_of_visible_chunk; ++chunk_zone_idx)
{
reached_end_of_visible_chunk = 1;
}
else if (visual_zone_end_ns >= view_start_ns && visual_zone_len_px > 5)
{
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id));
if (UI_HotAbsolute(zone_box))
V_Zone *zone = &chunk->zones[chunk_zone_idx];
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;
if (visual_zone_start_ns > view_end_ns || zone->end_ns == I64Max)
{
hovered_zone_box = zone_box;
hovered_zone = zone;
reached_end_of_visible_chunk = 1;
}
// TODO: Dim in HSV space
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;
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;
// 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));
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_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;
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)));
// if (do_break && UI_IsMouseHovered(zone_box))
if (do_break && zone->id == 0)
else if (visual_zone_end_ns >= view_start_ns && visual_zone_len_px > zone_collapse_threshold_px)
{
// UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback | UI_DebugBreakFlag_CheckCursorHover);
}
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id));
if (UI_HotAbsolute(zone_box))
{
hovered_zone_box = zone_box;
hovered_zone = zone;
}
// TODO: Dim in HSV space
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;
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;
// 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));
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, UI_Shrink(0, 1));
UI_SetNext(Width, UI_Shrink(0, 0));
// UI_SetNext(Width, UI_Grow(1, 1));
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_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;
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)));
// 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(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(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_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_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);
}
}
}
}
}
}
}

View File

@ -240,9 +240,9 @@ Struct(V_Palette)
////////////////////////////////////////////////////////////
//~ Profiler types
#define V_MaxZonesPerChunk 256
#define V_ZoneChunkLevelsCount 32
#define V_MaxZonesPerChunk 1024
#define V_MaxZoneDepth 128
#define V_ZoneChunkLevelsCount 32
Struct(V_Zone)
{
@ -278,12 +278,12 @@ Struct(V_ZoneTrack)
V_ZoneTrack *next;
V_ZoneTrack *prev;
// FIXME: Set this
// Zones
u64 id;
u64 rows_count;
V_ZoneRow rows[V_MaxZoneDepth];
// Sample collection
ProfTrack *prof_track;
u64 next_collection_sample_seq;
u64 current_sample_depth;