functioning profiler
This commit is contained in:
parent
d7c42d2462
commit
30271866f3
@ -1,5 +1,5 @@
|
||||
// This is the includable version of the base layer manifest.
|
||||
// The base layer uses an includable file rather than a '.lay' file so
|
||||
// The base layer uses an includable header rather than a typical .lay file so
|
||||
// that it may be depended on by the metaprogram.
|
||||
|
||||
//- Api
|
||||
@ -7,6 +7,7 @@
|
||||
#if IsCpu
|
||||
#include "base_memory.h"
|
||||
#include "base_arena.h"
|
||||
#include "base_prof.h"
|
||||
#include "base_futex.h"
|
||||
#include "base_sync.h"
|
||||
#include "base_time.h"
|
||||
@ -36,6 +37,7 @@
|
||||
#if IsCpu
|
||||
#include "base_tweak.c"
|
||||
#include "base_arena.c"
|
||||
#include "base_prof.c"
|
||||
#include "base_sync.c"
|
||||
#include "base_uid.c"
|
||||
#include "base_string.c"
|
||||
|
||||
@ -342,6 +342,26 @@ Vec4 SrgbFromLinear(Vec4 lin)
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec4 SrgbFromHsv(f32 h, f32 s, f32 v)
|
||||
{
|
||||
h = ModF32(h, 360.0f);
|
||||
if (h < 0)
|
||||
{
|
||||
h += 360.0f;
|
||||
}
|
||||
f32 c = v * s;
|
||||
f32 x = c * (1.0f - AbsF32(ModF32(h / 60.0f, 2.0f) - 1.0f));
|
||||
f32 m = v - c;
|
||||
Vec4 result = VEC4(0, 0, 0, 1);
|
||||
if (h < 60.0f) { result.r = c; result.g = x; result.b = 0; }
|
||||
else if (h < 120.0f) { result.r = x; result.g = c; result.b = 0; }
|
||||
else if (h < 180.0f) { result.r = 0; result.g = c; result.b = x; }
|
||||
else if (h < 240.0f) { result.r = 0; result.g = x; result.b = c; }
|
||||
else if (h < 300.0f) { result.r = x; result.g = 0; result.b = c; }
|
||||
else { result.r = c; result.g = 0; result.b = x; }
|
||||
return result;
|
||||
}
|
||||
|
||||
Vec4 PremulFromLinear(Vec4 lin)
|
||||
{
|
||||
Vec4 result = Zi;
|
||||
|
||||
@ -339,6 +339,7 @@ f32 LinearFromSrgbF32(f32 srgb);
|
||||
|
||||
Vec4 LinearFromSrgb(Vec4 srgb);
|
||||
Vec4 SrgbFromLinear(Vec4 lin);
|
||||
Vec4 SrgbFromHsv(f32 h, f32 s, f32 v);
|
||||
|
||||
Vec4 PremulFromLinear(Vec4 lin);
|
||||
Vec4 PremulFromSrgb(Vec4 srgb);
|
||||
@ -437,7 +438,7 @@ u32 U32FromVec4(Vec4 v);
|
||||
|
||||
//- Rng1
|
||||
f32 NormRng(Rng r, f32 v);
|
||||
#define Norm(min, max, v) NormRng(RNG((min), (max)), (v))
|
||||
#define Norm(v, min, max) NormRng(RNG((min), (max)), (v))
|
||||
|
||||
//- Rng2
|
||||
b32 IsRng2Empty(Rng2 r);
|
||||
|
||||
49
src/base/base_prof.c
Normal file
49
src/base/base_prof.c
Normal file
@ -0,0 +1,49 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Profile zone
|
||||
|
||||
void PushProfZoneEx(char *name_cstr_lit, b32 end_zone)
|
||||
{
|
||||
ProfTrack *track = Base_tl.prof.thread_track;
|
||||
if (!track)
|
||||
{
|
||||
Arena *perm = PermArena();
|
||||
{
|
||||
track = PushStruct(perm, ProfTrack);
|
||||
Base_tl.prof.thread_track = track;
|
||||
}
|
||||
LockTicketMutex(&Base.prof.register_track_tm);
|
||||
{
|
||||
Base_tl.prof.track_idx = Atomic32Fetch(&Base.prof.tracks_count);
|
||||
Base.prof.tracks[Base_tl.prof.track_idx] = track;
|
||||
Atomic32FetchAdd(&Base.prof.tracks_count, 1);
|
||||
}
|
||||
UnlockTicketMutex(&Base.prof.register_track_tm);
|
||||
}
|
||||
|
||||
u64 sample_seq = track->top_sample_seq;
|
||||
ProfSample *sample = &track->samples[sample_seq % ProfTrackSamplesCap];
|
||||
{
|
||||
// TODO: Wrap rdtsc for cpu-relative <-> program-relative timestamp conversion
|
||||
// sample->stamp = __rdtsc() | ((u64)end_zone << 63);
|
||||
sample->stamp = TimeNs() | ((u64)end_zone << 63);
|
||||
sample->name_cstr_lit = name_cstr_lit;
|
||||
}
|
||||
track->top_sample_seq = sample_seq + 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Retrieve tracks
|
||||
|
||||
RegisteredProfTracksArray FetchRegisteredProfTracks(Arena *arena)
|
||||
{
|
||||
RegisteredProfTracksArray result = Zi;
|
||||
{
|
||||
result.count = Atomic32Fetch(&Base.prof.tracks_count);
|
||||
result.tracks = PushStructsNoZero(arena, ProfTrack *, result.count);
|
||||
for (u64 track_idx = 0; track_idx < result.count; ++track_idx)
|
||||
{
|
||||
result.tracks[track_idx] = Base.prof.tracks[track_idx];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
59
src/base/base_prof.h
Normal file
59
src/base/base_prof.h
Normal file
@ -0,0 +1,59 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Profile types
|
||||
|
||||
#define ProfTrackSamplesCap Kibi(256)
|
||||
#define MaxRegisteredProfTracks Kibi(32)
|
||||
|
||||
#define NsFromProfStamp(stamp) (stamp & ~((u64)1 << 63))
|
||||
|
||||
Struct(ProfSample)
|
||||
{
|
||||
// Bit 63: zone-end, Bits 62-0: timestamp
|
||||
u64 stamp;
|
||||
char *name_cstr_lit;
|
||||
};
|
||||
|
||||
Struct(ProfTrack)
|
||||
{
|
||||
u64 top_sample_seq;
|
||||
ProfSample samples[ProfTrackSamplesCap];
|
||||
};
|
||||
|
||||
Struct(RegisteredProfTracksArray)
|
||||
{
|
||||
u64 count;
|
||||
ProfTrack **tracks;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ State types
|
||||
|
||||
Struct(ProfCtx)
|
||||
{
|
||||
TicketMutex register_track_tm;
|
||||
|
||||
Atomic32 tracks_count;
|
||||
ProfTrack *tracks[MaxRegisteredProfTracks];
|
||||
};
|
||||
|
||||
Struct(ThreadLocalProfCtx)
|
||||
{
|
||||
u32 track_idx;
|
||||
ProfTrack *thread_track;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Profile zone
|
||||
|
||||
void PushProfZoneEx(char *name_cstr_lit, b32 end_zone);
|
||||
|
||||
#if PROFILING_ENABLED
|
||||
#define ProfZoneDF(name_cstr_lit) DeferFor(PushProfZoneEx(name_cstr_lit"\0", 0), PushProfZoneEx(name_cstr_lit"\0", 1))
|
||||
#else
|
||||
#define ProfZoneDF(...)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Retrieve tracks
|
||||
|
||||
RegisteredProfTracksArray FetchRegisteredProfTracks(Arena *arena);
|
||||
@ -8,6 +8,7 @@ Struct(BaseCtx)
|
||||
ResourceCtx resource;
|
||||
GstatCtx gstat;
|
||||
AsyncCtx async;
|
||||
ProfCtx prof;
|
||||
};
|
||||
|
||||
extern BaseCtx Base;
|
||||
@ -18,6 +19,7 @@ extern BaseCtx Base;
|
||||
Struct(BaseThreadLocalCtx)
|
||||
{
|
||||
ThreadLocalArenaCtx arenas;
|
||||
ThreadLocalProfCtx prof;
|
||||
};
|
||||
|
||||
extern ThreadLocal BaseThreadLocalCtx Base_tl;
|
||||
|
||||
@ -86,6 +86,7 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
b32 shutdown = 0;
|
||||
while (!shutdown)
|
||||
ProfZoneDF("Sim Frame")
|
||||
{
|
||||
shutdown = Atomic32Fetch(&S.shutdown);
|
||||
P_tl.debug_draw_enabled = TweakBool("Simulation debug draw", 0);
|
||||
|
||||
@ -1,28 +1,5 @@
|
||||
V_Ctx V = Zi;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// FIXME: Remove this
|
||||
|
||||
ProfCtx Prof = Zi;
|
||||
ThreadLocal ProfThreadLocalCtx Prof_tl = Zi;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Bootstrap
|
||||
|
||||
@ -894,6 +871,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
b32 shutdown = 0;
|
||||
while (!shutdown)
|
||||
ProfZoneDF("Vis frame")
|
||||
{
|
||||
shutdown = Atomic32Fetch(&V.shutdown);
|
||||
P_tl.debug_draw_enabled = TweakBool("Vis debug draw", 0);
|
||||
@ -4777,7 +4755,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Width, UI_GROW(1, 0));
|
||||
UI_SetNext(Height, UI_SHRINK(0, 1));
|
||||
UI_SetNext(FloatingPos, VEC2(0, -lister_offset));
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren);
|
||||
UI_PushCp(UI_BuildRowEx(lister_key));
|
||||
{
|
||||
UI_SetNext(Tint, 0);
|
||||
@ -4999,7 +4977,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Width, UI_SHRINK(0, 1));
|
||||
UI_SetNext(Height, UI_SHRINK(0, 1));
|
||||
UI_SetNext(Text, new_tweak_str);
|
||||
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_NoTextTruncation);
|
||||
UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText);
|
||||
UI_SetNext(BackgroundColor, 0);
|
||||
UI_SetNext(BorderColor, 0);
|
||||
UI_BuildBox();
|
||||
@ -5134,7 +5112,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
// UI_SetNext(Anchor, UI_Region_Center);
|
||||
// UI_SetNext(FloatingPos, VEC2(marker_pos, (marker_size_px * 0.5)));
|
||||
UI_SetNext(FloatingPos, VEC2(marker_pos, -marker_dims.y * 0.125));
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY | UI_BoxFlag_CaptureMouse);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse);
|
||||
UI_BuildBoxEx(marker_key);
|
||||
}
|
||||
}
|
||||
@ -5263,7 +5241,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Anchor, UI_Region_Center);
|
||||
UI_SetNext(Anchor, UI_Region_Top);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating);
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampY);
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingY);
|
||||
UI_SetNext(Anchor, UI_Region_Top);
|
||||
UI_BuildBoxEx(thumb_key);
|
||||
}
|
||||
@ -5428,7 +5406,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
if (frame->tick == 1)
|
||||
{
|
||||
profiler->ns_per_px = NsFromSeconds(0.010);
|
||||
profiler->ns_per_px = NsFromSeconds(0.0001);
|
||||
}
|
||||
|
||||
profiler->graph_dims = DimsFromRng2(UI_Rect(profiler_graph_box));
|
||||
@ -5494,12 +5472,13 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
UI_Size profiler_height = UI_FNT(40, 1);
|
||||
UI_Size header_height = UI_FNT(2, 1);
|
||||
UI_Size window_padding = UI_FNT(0.5, 1);
|
||||
UI_Size footer_height = UI_FNT(2, 1);
|
||||
UI_Size window_padding = UI_FNT(0.60, 1);
|
||||
// UI_Size graph_height = UI_GROW(0.25, 0);
|
||||
UI_Size graph_height = UI_FNT(2, 1);
|
||||
UI_Size main_height = UI_GROW(1, 0);
|
||||
UI_Size zone_height = UI_FNT(0.75, 0);
|
||||
UI_Size track_height = UI_FNT(4, 0);
|
||||
UI_Size zone_height = UI_FNT(1, 0);
|
||||
UI_Size track_height = UI_FNT(25, 0);
|
||||
|
||||
// Vec2 old_main_dims = DimsFromRng2(UI_Rect(main_box));
|
||||
// old_main_dims.x = MaxF32(old_main_dims.x, 1);
|
||||
@ -5519,7 +5498,13 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
// i64 old_cursor_ns = profiler->view_start_ns + old_cursor_offset_ns;
|
||||
|
||||
f32 cursor_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x;
|
||||
i64 cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns;
|
||||
|
||||
b32 is_hovered = UI_HotAbsolute(main_box);
|
||||
if (is_hovered)
|
||||
{
|
||||
profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns;
|
||||
}
|
||||
|
||||
f32 view_offset_px = profiler->view_ns / profiler->ns_per_px;
|
||||
|
||||
|
||||
@ -5541,8 +5526,8 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
profiler->ns_per_px *= zoom_factor;
|
||||
|
||||
// profiler->view_ns -= (cursor_ns - profiler->view_ns) / zoom_factor;
|
||||
profiler->view_ns = cursor_ns - (cursor_ns - profiler->view_ns) * zoom_factor;
|
||||
// profiler->view_ns -= (profiler->cursor_ns - profiler->view_ns) / zoom_factor;
|
||||
profiler->view_ns = profiler->cursor_ns - (profiler->cursor_ns - profiler->view_ns) * zoom_factor;
|
||||
|
||||
|
||||
|
||||
@ -5573,13 +5558,23 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
|
||||
|
||||
if (UI_Downs(main_box, Button_M3))
|
||||
|
||||
|
||||
// TODO: Drag in px units for sharper resolution
|
||||
if (UI_Downs(main_box, Button_M1) || UI_Downs(main_box, Button_M2) || UI_Downs(main_box, Button_M3))
|
||||
{
|
||||
profiler->drag_view_ns = profiler->view_ns;
|
||||
profiler->drag_cursor_px = cursor_px;
|
||||
}
|
||||
|
||||
if (UI_Held(main_box, Button_M3))
|
||||
// Drag ruler
|
||||
if (UI_Held(main_box, Button_M1))
|
||||
{
|
||||
// profiler->
|
||||
}
|
||||
|
||||
// Drag view
|
||||
if (UI_Held(main_box, Button_M2) || UI_Held(main_box, Button_M3))
|
||||
{
|
||||
profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px);
|
||||
}
|
||||
@ -5605,7 +5600,12 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
// f64 ns_per_px = MaxF64((profiler->view_end_ns - profiler->view_start_ns) / old_main_dims.x, 1);
|
||||
|
||||
Vec4 profiler_color = theme.col.window_bg;
|
||||
profiler_color.a = 1;
|
||||
f32 profiler_opacity = 1;
|
||||
|
||||
Vec4 main_color = profiler_color;
|
||||
main_color.r *= 0.75;
|
||||
main_color.g *= 0.75;
|
||||
main_color.b *= 0.75;
|
||||
|
||||
UI_SetNext(Parent, vis_ui_box);
|
||||
UI_SetNext(BorderColor, theme.col.window_bd);
|
||||
@ -5614,6 +5614,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Rounding, UI_RPIX(10 * theme.rounding));
|
||||
UI_SetNext(Height, profiler_height);
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||
UI_SetNext(Opacity, profiler_opacity);
|
||||
UI_PushDF(Width, UI_GROW(1, 0))
|
||||
UI_PushDF(Parent, UI_BuildColumnEx(profiler_box))
|
||||
UI_PushDF(Parent, UI_BuildRow())
|
||||
@ -5640,16 +5641,18 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_PushDF(Parent, UI_BuildBoxEx(profiler_graph_box))
|
||||
{
|
||||
}
|
||||
UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
|
||||
// UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
|
||||
|
||||
//- Main
|
||||
//- Main area
|
||||
if (do_break)
|
||||
{
|
||||
UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback);
|
||||
UI_SetNext(Text, Lit("MAIN"));
|
||||
// UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback);
|
||||
}
|
||||
UI_SetNext(Text, Lit("MAIN"));
|
||||
UI_SetNext(BackgroundColor, main_color);
|
||||
UI_SetNext(Height, main_height);
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren);
|
||||
UI_SetNext(Rounding, UI_RPIX(4));
|
||||
UI_SetNext(Flags, UI_BoxFlag_CaptureMouse | UI_BoxFlag_CaptureThroughChildren | UI_BoxFlag_Scissor);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||
UI_PushDF(Parent, UI_BuildColumnEx(main_box))
|
||||
{
|
||||
@ -5687,24 +5690,16 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
// };
|
||||
|
||||
|
||||
|
||||
Struct(V_ZoneDesc)
|
||||
{
|
||||
Vec4 color;
|
||||
i64 start_ns;
|
||||
i64 end_ns;
|
||||
};
|
||||
|
||||
u32 tracks_count = Atomic32Fetch(&Prof.tracks_count);
|
||||
for (u64 track_idx = 0; track_idx < tracks_count; ++track_idx)
|
||||
RegisteredProfTracksArray tracks = FetchRegisteredProfTracks(frame->arena);
|
||||
for (u64 track_idx = 0; track_idx < tracks.count; ++track_idx)
|
||||
{
|
||||
UI_Key track_box = UI_KeyF("track %F", FmtUint(track_idx));
|
||||
UI_SetNext(Height, track_height);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||
UI_PushDF(Tag, track_box.v)
|
||||
UI_PushDF(Parent, UI_BuildRowEx(track_box))
|
||||
UI_PushDF(Parent, UI_BuildColumnEx(track_box))
|
||||
{
|
||||
ProfTrack *track = Prof.tracks[track_idx];
|
||||
ProfTrack *track = tracks.tracks[track_idx];
|
||||
|
||||
// u64 zones_count = 64;
|
||||
// V_ZoneDesc *zones = PushStructs(frame->arena, V_ZoneDesc, zones_count);
|
||||
@ -5760,6 +5755,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
|
||||
|
||||
samples_end_seq = MinU64(samples_end_seq, samples_start_seq + 512);
|
||||
|
||||
|
||||
|
||||
@ -5768,82 +5764,291 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
|
||||
|
||||
u64 zones_count = samples_end_seq - samples_start_seq;
|
||||
|
||||
zones_count = MinU64(zones_count, 100);
|
||||
|
||||
V_ZoneDesc *zones = PushStructs(frame->arena, V_ZoneDesc, zones_count);
|
||||
for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
|
||||
|
||||
|
||||
Struct(V_ZoneDesc)
|
||||
{
|
||||
V_ZoneDesc *zone = &zones[zone_idx];
|
||||
V_ZoneDesc *prev;
|
||||
V_ZoneDesc *next;
|
||||
|
||||
ProfSample *sample = &samples[samples_start_seq % ProfTrackSamplesCap];
|
||||
V_ZoneDesc *prev_in_row;
|
||||
V_ZoneDesc *next_in_row;
|
||||
|
||||
// zone->color = VEC4(0.5, 0.2, 0.2, 0.5);
|
||||
// zone->color.r += 0.5 * Norm24(MixU64(zone_idx));
|
||||
String name;
|
||||
u64 start_sample_seq;
|
||||
u64 end_sample_seq;
|
||||
|
||||
u64 seed0 = MixU64(zone_idx + 1);
|
||||
u64 seed1 = MixU64(seed0);
|
||||
u64 seed2 = MixU64(seed1);
|
||||
u64 seed3 = MixU64(seed2);
|
||||
u32 depth;
|
||||
|
||||
zone->color = VEC4(Norm24(seed0), Norm24(seed1), Norm24(seed2), 1);
|
||||
zone->color.r += (1.0 - zone->color.r) * 0.25;
|
||||
|
||||
zone->start_ns = NsFromSeconds(zone_idx * 2);
|
||||
zone->end_ns = NsFromSeconds(zone_idx * 2 + 1);
|
||||
|
||||
// zone->start_ns = NsFromProfStamp(sample->stamp);
|
||||
// zone->end_ns = zone->start_ns + NsFromSeconds(0.100);
|
||||
Vec4 color;
|
||||
i64 start_ns;
|
||||
i64 end_ns;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// u64 zones_count = samples_end_seq - samples_start_seq;
|
||||
// zones_count = MinU64(zones_count, 1000);
|
||||
|
||||
// V_ZoneDesc *zones = PushStructs(frame->arena, V_ZoneDesc, zones_count);
|
||||
|
||||
|
||||
//- Zones
|
||||
for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
//- Create zones
|
||||
V_ZoneDesc *first_zone = 0;
|
||||
V_ZoneDesc *last_zone = 0;
|
||||
u64 zone_rows_count = 0;
|
||||
{
|
||||
V_ZoneDesc *zone = &zones[zone_idx];
|
||||
// FIXME: Clamp depth
|
||||
// u64 zone_idx = 0;
|
||||
u64 depth = 0;
|
||||
|
||||
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone_idx));
|
||||
|
||||
Vec4 zone_color = zone->color;
|
||||
zone_color = LerpSrgb(zone_color, Color_Cyan, UI_Hot(zone_box));
|
||||
|
||||
// Vec4 zone_color_bd = Zi;
|
||||
// zone_color_bd
|
||||
|
||||
i64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
f32 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// i6
|
||||
|
||||
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_PIX(zone_len_px, 1);
|
||||
|
||||
UI_SetNext(Text, StringF(frame->arena, "ZONE %F", FmtUint(zone_idx)));
|
||||
// if (do_break && UI_IsMouseHovered(zone_box))
|
||||
if (do_break && zone_idx == 0)
|
||||
for (u64 sample_seq = 0; sample_seq < samples_end_seq; ++sample_seq)
|
||||
{
|
||||
UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback | UI_DebugBreakFlag_CheckCursorHover);
|
||||
}
|
||||
ProfSample *sample = &samples[sample_seq % ProfTrackSamplesCap];
|
||||
|
||||
i64 time_ns = NsFromProfStamp(sample->stamp);
|
||||
|
||||
b32 is_end = !!(sample->stamp & ((u64)1 << 63));
|
||||
if (is_end)
|
||||
{
|
||||
depth -= 1;
|
||||
V_ZoneDesc *zone = last_zone;
|
||||
for (; zone->depth > depth;)
|
||||
{
|
||||
zone = zone->prev;
|
||||
}
|
||||
zone->end_ns = time_ns;
|
||||
zone->end_sample_seq = sample_seq;
|
||||
}
|
||||
else
|
||||
{
|
||||
V_ZoneDesc *zone = PushStruct(frame->arena, V_ZoneDesc);
|
||||
zone->start_ns = time_ns;
|
||||
DllQueuePush(first_zone, last_zone, zone);
|
||||
|
||||
char *name_cstr = sample->name_cstr_lit;
|
||||
String name = StringFromCstrNoLimit(name_cstr);
|
||||
|
||||
u64 seed = HashString(name);
|
||||
// u64 seed = MixU64((u64)name_cstr);
|
||||
|
||||
f32 h = (Norm16(seed >> 0) * 1) * 360;
|
||||
f32 s = TweakFloat("Profiler zone saturation", 0.85, 0, 1);
|
||||
f32 v = TweakFloat("Profiler zone brightness", 0.50, 0, 1);
|
||||
|
||||
zone->color = SrgbFromHsv(h, s, v);
|
||||
|
||||
zone->start_sample_seq = sample_seq;
|
||||
zone->name = name;
|
||||
zone->depth = depth;
|
||||
|
||||
|
||||
|
||||
UI_SetNext(Width, zone_width);
|
||||
UI_SetNext(Height, zone_height);
|
||||
UI_SetNext(BackgroundColor, zone_color);
|
||||
UI_SetNext(FloatingPos, zone_pos);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY | UI_BoxFlag_CaptureMouse);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY);
|
||||
UI_PushDF(Parent, UI_BuildBoxEx(zone_box))
|
||||
{
|
||||
depth += 1;
|
||||
zone_rows_count = MaxU64(depth, zone_rows_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Struct(V_ZoneRow)
|
||||
{
|
||||
u64 count;
|
||||
V_ZoneDesc *first_zone;
|
||||
V_ZoneDesc *last_zone;
|
||||
};
|
||||
|
||||
//- Push zones to rows
|
||||
V_ZoneRow *zone_rows = PushStructs(frame->arena, V_ZoneRow, zone_rows_count);
|
||||
for (V_ZoneDesc *zone = first_zone; zone; zone = zone->next)
|
||||
{
|
||||
V_ZoneRow *row = &zone_rows[zone->depth];
|
||||
row->count += 1;
|
||||
DllQueuePushNP(row->first_zone, row->last_zone, zone, next_in_row, prev_in_row);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
// {
|
||||
// V_ZoneDesc *zone = &zones[zone_idx];
|
||||
// ProfSample *sample = &samples[(zone_idx + samples_start_seq) % ProfTrackSamplesCap];
|
||||
|
||||
// // zone->color = VEC4(0.5, 0.2, 0.2, 0.5);
|
||||
// // zone->color.r += 0.5 * Norm24(MixU64(zone_idx));
|
||||
|
||||
// u64 seed0 = MixU64(zone_idx + 1);
|
||||
// u64 seed1 = MixU64(seed0);
|
||||
// u64 seed2 = MixU64(seed1);
|
||||
// u64 seed3 = MixU64(seed2);
|
||||
|
||||
// zone->color = VEC4(Norm24(seed0), Norm24(seed1), Norm24(seed2), 1);
|
||||
// zone->color.r += (1.0 - zone->color.r) * 0.25;
|
||||
|
||||
// // zone->start_ns = NsFromSeconds(zone_idx * 2);
|
||||
// // zone->end_ns = NsFromSeconds(zone_idx * 2 + 1);
|
||||
|
||||
// zone->start_ns = NsFromProfStamp(sample->stamp);
|
||||
// zone->end_ns = zone->start_ns + NsFromSeconds(0.100);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
// {
|
||||
// V_ZoneDesc *zone = &zones[zone_idx];
|
||||
|
||||
// ProfSample *sample = &samples[(zone_idx + samples_start_seq) % ProfTrackSamplesCap];
|
||||
|
||||
// // zone->color = VEC4(0.5, 0.2, 0.2, 0.5);
|
||||
// // zone->color.r += 0.5 * Norm24(MixU64(zone_idx));
|
||||
|
||||
// u64 seed0 = MixU64(zone_idx + 1);
|
||||
// u64 seed1 = MixU64(seed0);
|
||||
// u64 seed2 = MixU64(seed1);
|
||||
// u64 seed3 = MixU64(seed2);
|
||||
|
||||
// zone->color = VEC4(Norm24(seed0), Norm24(seed1), Norm24(seed2), 1);
|
||||
// zone->color.r += (1.0 - zone->color.r) * 0.25;
|
||||
|
||||
// // zone->start_ns = NsFromSeconds(zone_idx * 2);
|
||||
// // zone->end_ns = NsFromSeconds(zone_idx * 2 + 1);
|
||||
|
||||
// zone->start_ns = NsFromProfStamp(sample->stamp);
|
||||
// zone->end_ns = zone->start_ns + NsFromSeconds(0.100);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
for (u64 zone_row_idx = 0; zone_row_idx < zone_rows_count; ++zone_row_idx)
|
||||
{
|
||||
V_ZoneRow *row = &zone_rows[zone_row_idx];
|
||||
|
||||
//- Zone row
|
||||
// UI_SetNext(Height, zone_height);
|
||||
UI_SetNext(Height, zone_height);
|
||||
UI_PushDF(Parent, UI_BuildRow())
|
||||
{
|
||||
//- Zones in row
|
||||
u64 zone_idx = 0;
|
||||
for (V_ZoneDesc *zone = row->first_zone; zone; zone = zone->next_in_row)
|
||||
{
|
||||
if (zone->end_ns > zone->start_ns)
|
||||
{
|
||||
UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->start_sample_seq));
|
||||
|
||||
Vec4 zone_color = zone->color;
|
||||
Vec4 zone_color_bd = zone_color;
|
||||
// zone_color = LerpSrgb(zone_color, Color_Cyan, 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));
|
||||
|
||||
i64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
f32 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// i6
|
||||
|
||||
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_PIX(zone_len_px, 1);
|
||||
|
||||
UI_SetNext(Text, StringF(frame->arena, "ZONE %F", FmtUint(zone_idx)));
|
||||
// if (do_break && UI_IsMouseHovered(zone_box))
|
||||
if (do_break && zone_idx == 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_PushDF(Parent, UI_BuildRowEx(zone_box))
|
||||
{
|
||||
UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
UI_SetNext(FontSize, UI_Top(FontSize) * 0.75);
|
||||
UI_SetNext(Text, zone->name);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_DrawText | UI_BoxFlag_DontTruncateText);
|
||||
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
||||
UI_BuildRow();
|
||||
}
|
||||
zone_idx += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
// {
|
||||
// V_ZoneDesc *zone = &zones[zone_idx];
|
||||
|
||||
// UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone_idx));
|
||||
|
||||
// Vec4 zone_color = zone->color;
|
||||
// zone_color = LerpSrgb(zone_color, Color_Cyan, UI_Hot(zone_box));
|
||||
|
||||
// // Vec4 zone_color_bd = Zi;
|
||||
// // zone_color_bd
|
||||
|
||||
// i64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// f32 zone_len_px = zone_len_ns / profiler->ns_per_px;
|
||||
// // i6
|
||||
|
||||
// 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_PIX(zone_len_px, 1);
|
||||
|
||||
// UI_SetNext(Text, StringF(frame->arena, "ZONE %F", FmtUint(zone_idx)));
|
||||
// // if (do_break && UI_IsMouseHovered(zone_box))
|
||||
// if (do_break && zone_idx == 0)
|
||||
// {
|
||||
// UI_SetNext(DebugBreakFlags, UI_DebugBreakFlag_BuildFeedback | UI_DebugBreakFlag_CheckCursorHover);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// UI_SetNext(Width, zone_width);
|
||||
// UI_SetNext(Height, zone_height);
|
||||
// UI_SetNext(BackgroundColor, zone_color);
|
||||
// UI_SetNext(FloatingPos, zone_pos);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY | UI_BoxFlag_CaptureMouse);
|
||||
// // UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY);
|
||||
// UI_PushDF(Parent, UI_BuildBoxEx(zone_box))
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -5858,9 +6063,9 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
//- Timeline cursor
|
||||
{
|
||||
// Vec2 timeline_cursor_pos = VEC2(old_cursor_offset_px, 0);
|
||||
Vec2 timeline_cursor_pos = VEC2((cursor_ns - profiler->view_ns) / profiler->ns_per_px, 0);
|
||||
Vec2 timeline_cursor_pos = VEC2((profiler->cursor_ns - profiler->view_ns) / profiler->ns_per_px, 0);
|
||||
Vec4 timeline_cursor_color = theme.col.window_bd;
|
||||
timeline_cursor_color.a = UI_Hot(main_box);
|
||||
timeline_cursor_color.a = UI_Hot(main_box) * 0.5;
|
||||
|
||||
UI_SetNext(Width, UI_FNT(0.15, 1));
|
||||
UI_SetNext(Height, UI_GROW(1, 0));
|
||||
@ -5871,346 +6076,29 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
}
|
||||
|
||||
// UI_BuildSpacer(window_padding, Axis_Y);
|
||||
|
||||
//- Footer
|
||||
UI_PushDF(Height, footer_height)
|
||||
UI_PushDF(ChildAlignment, UI_Region_Center)
|
||||
UI_PushDF(Parent, UI_BuildRow())
|
||||
{
|
||||
UI_BuildSpacer(UI_GROW(1, 0), Axis_X);
|
||||
|
||||
if (do_break)
|
||||
{
|
||||
UI_ForceNext(DebugBreakFlags, UI_DebugBreakFlag_PrepLayout);
|
||||
}
|
||||
|
||||
UI_SetNext(Opacity, UI_Hot(main_box));
|
||||
UI_BuildLabelF("%Fs", FmtFloat(SecondsFromNs(profiler->cursor_ns), .p = 3));
|
||||
}
|
||||
}
|
||||
UI_BuildSpacer(window_padding, Axis_X);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //////////////////////////////
|
||||
// //- Build profiler
|
||||
|
||||
|
||||
// // FIXME: Finalize
|
||||
|
||||
|
||||
// V_Profiler *profiler = &frame->profiler;
|
||||
// UI_Key profiler_graph_box = UI_KeyF("graph");
|
||||
// UI_PushDF(OmitFlags, UI_BoxFlag_CaptureMouse * !!(frame->is_looking))
|
||||
// if (TweakBool("Show profiler", 1))
|
||||
// {
|
||||
// profiler->is_showing = 1;
|
||||
|
||||
// UI_BoxReports profiler_graph_box = UI_ReportsFromKey(profiler_graph_box);
|
||||
// profiler->graph_dims = DimsFromRng2(profiler_graph_box.UI_Rect());
|
||||
|
||||
// //- Init test samples
|
||||
// // // FIXME: Remove this
|
||||
// // Struct(SampleState)
|
||||
// // {
|
||||
// // i64 ready_samples_count;
|
||||
// // Arena *samples_arena;
|
||||
// // };
|
||||
// // Struct(Sample)
|
||||
// // {
|
||||
// // u64 zone_id;
|
||||
// // u64 thread_id;
|
||||
// // i64 start_ns;
|
||||
// // i64 end_ns;
|
||||
// // };
|
||||
// // PERSIST i64 sample_states_count = 1;
|
||||
// // PERSIST SampleState *sample_states = 0;
|
||||
// // if (!sample_states)
|
||||
// // {
|
||||
// // sample_states = PushStructs(perm, SampleState, sample_states_count);
|
||||
// // for (i64 sample_state_idx = 0; sample_state_idx < sample_states_count; ++sample_state_idx)
|
||||
// // {
|
||||
// // SampleState *ss = &sample_states[sample_state_idx];
|
||||
// // ss->samples_arena = AcquireArena(Gibi(64));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // ss->ready_samples_count = 128;
|
||||
// // for (i64 sample_idx = 0; sample_idx < ss->ready_samples_count; ++sample_idx)
|
||||
// // {
|
||||
// // Sample *sample = PushStruct(ss->samples_arena, Sample);
|
||||
// // sample->zone_id = (u64)"Hello there";
|
||||
// // sample->thread_id = 0;
|
||||
// // sample->start_ns = NsFromSeconds(sample_idx);
|
||||
// // sample->end_ns = NsFromSeconds(sample_idx + 1);
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
|
||||
|
||||
// // FIXME: Remove this
|
||||
// {
|
||||
// V_ProfilerFrame *pf = &V.profiler_frames[V.profiler_frame_seq % V_ProfilerFramesCap];
|
||||
// V.profiler_frame_seq += 1;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //- Build profiler
|
||||
// UI_Key profiler_box = UI_KeyF("profiler");
|
||||
// UI_PushDF(Tag, profiler_box.v)
|
||||
// UI_PushDF(Parent, profiler_box)
|
||||
// {
|
||||
// UI_Key main_box = UI_KeyF("main");
|
||||
|
||||
// UI_Size profiler_height = UI_FNT(40, 1);
|
||||
// UI_Size header_height = UI_FNT(2, 1);
|
||||
// UI_Size window_padding = UI_FNT(0.5, 1);
|
||||
// // UI_Size graph_height = UI_GROW(0.25, 0);
|
||||
// UI_Size graph_height = UI_FNT(2, 1);
|
||||
// UI_Size main_height = UI_GROW(1, 0);
|
||||
// UI_Size zone_height = UI_FNT(0.75, 0);
|
||||
|
||||
// UI_BoxReports main_box = UI_ReportsFromKey(main_box);
|
||||
|
||||
|
||||
// Vec2 old_main_dims = DimsFromRng2(UI_Rect(main_box));
|
||||
// old_main_dims.x = MaxF32(old_main_dims.x, 1);
|
||||
// old_main_dims.y = MaxF32(old_main_dims.y, 1);
|
||||
|
||||
|
||||
|
||||
// if (profiler->view_start_ns == 0 && profiler->view_end_ns == 0)
|
||||
// {
|
||||
// profiler->view_start_ns = NsFromSeconds(0);
|
||||
// profiler->view_end_ns = NsFromSeconds(10);
|
||||
// }
|
||||
|
||||
|
||||
// f32 old_cursor_offset_px = frame->screen_cursor.x - UI_Rect(main_box).p0.x;
|
||||
// i64 old_cursor_offset_ns = (old_cursor_offset_px / old_main_dims.x) * (profiler->view_end_ns - profiler->view_start_ns);
|
||||
// i64 old_cursor_ns = profiler->view_start_ns + old_cursor_offset_ns;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // FIXME: Remove this
|
||||
// f32 prof_zoom_rate = 2;
|
||||
// // profiler->view_start_ns += NsFromSeconds(1) * main_box.draw.buttons[Button_WheelUp].presses * prof_zoom_rate;
|
||||
// // profiler->view_start_ns -= NsFromSeconds(1) * main_box.draw.buttons[Button_WheelDown].presses * prof_zoom_rate;
|
||||
|
||||
// // profiler->view_start_ns -= main_box.draw.buttons[Button_WheelUp].presses * ns_to_left * prof_zoom_rate;
|
||||
// // profiler->view_end_ns += main_box.draw.buttons[Button_WheelDown].presses * ns_to_right * prof_zoom_rate;
|
||||
|
||||
// // profiler->view_start_ns -= main_box.draw.buttons[Button_WheelDown].presses * ns_to_left * prof_zoom_rate;
|
||||
// // profiler->view_end_ns += main_box.draw.buttons[Button_WheelDown].presses * ns_to_right * prof_zoom_rate;
|
||||
|
||||
// if (main_box.draw.buttons[Button_WheelUp].presses)
|
||||
// {
|
||||
// DEBUGBREAKABLE;
|
||||
// }
|
||||
|
||||
// // profiler->view_start_ns += main_box.draw.buttons[Button_WheelUp].presses * ns_to_left / prof_zoom_rate;
|
||||
// // profiler->view_end_ns -= main_box.draw.buttons[Button_WheelUp].presses * ns_to_right / prof_zoom_rate;
|
||||
|
||||
// for (i32 zoom_idx = 0; zoom_idx < main_box.draw.buttons[Button_WheelUp].presses; ++zoom_idx)
|
||||
// {
|
||||
// i64 ns_to_left = old_cursor_ns - profiler->view_start_ns;
|
||||
// i64 ns_to_right = profiler->view_end_ns - old_cursor_ns;
|
||||
// profiler->view_start_ns += (old_cursor_ns - profiler->view_start_ns) / prof_zoom_rate;
|
||||
// profiler->view_end_ns -= (profiler->view_end_ns - old_cursor_ns) / prof_zoom_rate;
|
||||
// }
|
||||
// for (i32 zoom_idx = 0; zoom_idx < main_box.draw.buttons[Button_WheelDown].presses; ++zoom_idx)
|
||||
// {
|
||||
// i64 ns_to_left = old_cursor_ns - profiler->view_start_ns;
|
||||
// i64 ns_to_right = profiler->view_end_ns - old_cursor_ns;
|
||||
// profiler->view_start_ns -= (old_cursor_ns - profiler->view_start_ns) * prof_zoom_rate;
|
||||
// profiler->view_end_ns += (profiler->view_end_ns - old_cursor_ns) * prof_zoom_rate;
|
||||
// }
|
||||
|
||||
// if (main_box.draw.buttons[Button_M3].downs)
|
||||
// {
|
||||
// profiler->drag_view_start_ns = profiler->view_start_ns;
|
||||
// profiler->drag_cursor_ns = old_cursor_ns;
|
||||
// }
|
||||
|
||||
// if (main_box.draw.buttons[Button_M3].held)
|
||||
// {
|
||||
// // i64 ns_delta = prev_frame->profiler.
|
||||
// i64 ns_delta = old_cursor_ns - profiler->drag_cursor_ns;
|
||||
|
||||
// // i64 dims_ns = profiler->view_end_ns - profiler->view_start_ns;
|
||||
|
||||
// // profiler->view_start_ns = profiler->drag_view_start_ns - ns_delta;
|
||||
// // profiler->view_end_ns = profiler->view_start_ns + dims_ns;
|
||||
|
||||
// i64 dims_ns = profiler->view_end_ns - profiler->view_start_ns;
|
||||
// profiler->view_start_ns = profiler->drag_view_start_ns - ns_delta;
|
||||
// profiler->view_end_ns = profiler->view_start_ns + dims_ns;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// f64 ns_per_px = MaxF64((profiler->view_end_ns - profiler->view_start_ns) / old_main_dims.x, 1);
|
||||
|
||||
// Vec4 profiler_color = theme.col.window_bg;
|
||||
// profiler_color.a = 1;
|
||||
|
||||
// UI_SetNext(Parent, vis_ui_box);
|
||||
// UI_SetNext(BorderColor, theme.col.window_bd);
|
||||
// UI_SetNext(BorderSize, 2);
|
||||
// UI_SetNext(BackgroundColor, profiler_color);
|
||||
// UI_SetNext(Rounding, UI_RPIX(10 * theme.rounding));
|
||||
// UI_SetNext(Height, profiler_height);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||
// UI_PushDF(Width, UI_GROW(1, 0))
|
||||
// UI_PushDF(Parent, UI_BuildColumnEx(profiler_box))
|
||||
// UI_PushDF(Parent, UI_BuildRow())
|
||||
// {
|
||||
// UI_BuildSpacer(window_padding, Axis_X);
|
||||
// UI_PushDF(Parent, UI_BuildColumn())
|
||||
// {
|
||||
// //- Header
|
||||
// // UI_PushDF(BackgroundColor, Color_Red)
|
||||
// // UI_SetNext(BorderColor, Color_Red);
|
||||
// // UI_SetNext(BorderSize, 1);
|
||||
// UI_SetNext(ChildAlignment, UI_Region_Center);
|
||||
// UI_PushDF(Height, header_height)
|
||||
// UI_PushDF(Parent, UI_BuildBoxF("profiler header"))
|
||||
// {
|
||||
// UI_PushDF(TextColor, theme.col.hint)
|
||||
// UI_BuildLabelF("Profiler");
|
||||
// }
|
||||
// UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
|
||||
|
||||
// //- Graph
|
||||
// // UI_SetNext(BackgroundColor, Color_Cyan);
|
||||
// UI_SetNext(Height, graph_height);
|
||||
// UI_PushDF(Parent, UI_BuildBoxEx(profiler_graph_box))
|
||||
// {
|
||||
// }
|
||||
// UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
|
||||
|
||||
// //- Main
|
||||
// UI_SetNext(Height, main_height);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_CaptureMouse);
|
||||
// UI_PushDF(Parent, UI_BuildRowEx(main_box))
|
||||
// {
|
||||
|
||||
// // FIXME: Remove this
|
||||
|
||||
// Struct(V_ZoneDesc)
|
||||
// {
|
||||
// Vec4 color;
|
||||
// i64 start_ns;
|
||||
// i64 end_ns;
|
||||
// };
|
||||
|
||||
// u64 zones_count = 64;
|
||||
// V_ZoneDesc *zones = PushStructs(frame->arena, V_ZoneDesc, zones_count);
|
||||
// for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
// {
|
||||
// V_ZoneDesc *zone = &zones[zone_idx];
|
||||
|
||||
// // zone->color = VEC4(0.5, 0.2, 0.2, 0.5);
|
||||
// // zone->color.r += 0.5 * Norm24(MixU64(zone_idx));
|
||||
|
||||
// u64 seed0 = MixU64(zone_idx + 1);
|
||||
// u64 seed1 = MixU64(seed0);
|
||||
// u64 seed2 = MixU64(seed1);
|
||||
// u64 seed3 = MixU64(seed2);
|
||||
|
||||
// zone->color = VEC4(Norm24(seed0), Norm24(seed1), Norm24(seed2), 1);
|
||||
// zone->color.r += (1.0 - zone->color.r) * 0.25;
|
||||
|
||||
// zone->start_ns = NsFromSeconds(zone_idx * 2);
|
||||
// zone->end_ns = NsFromSeconds(zone_idx * 2 + 1);
|
||||
// };
|
||||
|
||||
// //- Zones
|
||||
// for (u64 zone_idx = 0; zone_idx < zones_count; ++zone_idx)
|
||||
// {
|
||||
// V_ZoneDesc *zone = &zones[zone_idx];
|
||||
|
||||
// UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone_idx));
|
||||
// // UI_BoxReport zone_box = UI_ReportFromKey(zone_box).draw;
|
||||
|
||||
// Vec4 zone_color = zone->color;
|
||||
|
||||
// // Vec4 zone_color_bd = Zi;
|
||||
// // zone_color_bd
|
||||
|
||||
// i64 zone_len_ns = zone->end_ns - zone->start_ns;
|
||||
// f32 zone_len_px = zone_len_ns / ns_per_px;
|
||||
// // i6
|
||||
|
||||
// f32 zone_offset_px = (zone->start_ns - profiler->view_start_ns) / ns_per_px;
|
||||
// Vec2 zone_pos = VEC2(zone_offset_px, 0);
|
||||
// UI_Size zone_width = UI_PIX(zone_len_px, 1);
|
||||
|
||||
// // UI_Report
|
||||
|
||||
|
||||
// UI_SetNext(Width, zone_width);
|
||||
// UI_SetNext(Height, zone_height);
|
||||
// UI_SetNext(BackgroundColor, zone_color);
|
||||
// UI_SetNext(FloatingPos, zone_pos);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY);
|
||||
// UI_PushDF(Parent, UI_BuildBoxEx(zone_box))
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
// //- Timeline cursor
|
||||
// {
|
||||
// // Vec2 timeline_cursor_pos = VEC2(old_cursor_offset_px, 0);
|
||||
// Vec2 timeline_cursor_pos = VEC2((old_cursor_ns - profiler->view_start_ns) / ns_per_px, 0);
|
||||
// Vec4 timeline_cursor_color = theme.col.window_bd;
|
||||
// timeline_cursor_color.a = UI_Hot(main_box);
|
||||
|
||||
// UI_SetNext(Width, UI_FNT(0.15, 1));
|
||||
// UI_SetNext(Height, UI_GROW(1, 0));
|
||||
// UI_SetNext(BackgroundColor, timeline_cursor_color);
|
||||
// UI_SetNext(FloatingPos, timeline_cursor_pos);
|
||||
// UI_SetNext(Flags, UI_BoxFlag_Floating);
|
||||
// UI_BuildBox();
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// UI_BuildSpacer(window_padding, Axis_X);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
//- Build notifications
|
||||
@ -6531,7 +6419,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
UI_SetNext(Anchor, UI_Region_Center);
|
||||
UI_SetNext(FloatingPos, timeline_pos);
|
||||
UI_SetNext(BackgroundColor, tmld_bg);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY);
|
||||
UI_PushCp(UI_BuildRowEx(timeline_key));
|
||||
{
|
||||
}
|
||||
@ -6591,7 +6479,7 @@ void V_TickForever(WaveLaneCtx *lane)
|
||||
tint.a *= marker_opacity;
|
||||
|
||||
UI_SetNext(Tint, tint);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_NoFloatingClampX | UI_BoxFlag_NoFloatingClampY);
|
||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_DontClampFloatingX | UI_BoxFlag_DontClampFloatingY);
|
||||
UI_SetNext(BackgroundColor, marker_color);
|
||||
UI_SetNext(Anchor, UI_Region_Center);
|
||||
UI_SetNext(Width, width);
|
||||
|
||||
@ -1,153 +1,3 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// FIXME: Remove this
|
||||
|
||||
|
||||
// // Enum(ProfFamilyKind)
|
||||
// // {
|
||||
// // ProfFamilyKind_Unknown,
|
||||
// // ProfFamilyKind_Async,
|
||||
// // ProfFamilyKind_Vis,
|
||||
// // ProfFamilyKind_Sim,
|
||||
|
||||
// // ProfFamilyKind_COUNT
|
||||
// // };
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // // Struct(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define ProfTrackSamplesCap Kibi(256)
|
||||
#define MaxRegisteredProfTracks Kibi(32)
|
||||
|
||||
#define NsFromProfStamp(stamp) (stamp & ~((u64)1 << 63))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Struct(ProfSample)
|
||||
{
|
||||
// Bit 63: zone-end, Bits 62-0: timestamp
|
||||
u64 stamp;
|
||||
};
|
||||
|
||||
Struct(ProfTrack)
|
||||
{
|
||||
u64 top_sample_seq;
|
||||
ProfSample samples[ProfTrackSamplesCap];
|
||||
};
|
||||
|
||||
Struct(ProfCtx)
|
||||
{
|
||||
TicketMutex register_track_tm;
|
||||
|
||||
Atomic32 tracks_count;
|
||||
ProfTrack *tracks[MaxRegisteredProfTracks];
|
||||
};
|
||||
|
||||
Struct(ProfThreadLocalCtx)
|
||||
{
|
||||
u32 track_idx;
|
||||
ProfTrack *thread_track;
|
||||
};
|
||||
|
||||
extern ProfCtx Prof;
|
||||
extern ThreadLocal ProfThreadLocalCtx Prof_tl;
|
||||
|
||||
|
||||
Inline void PushProfZoneEx(b32 end_zone)
|
||||
{
|
||||
ProfTrack *track = Prof_tl.thread_track;
|
||||
if (!track)
|
||||
{
|
||||
Arena *perm = PermArena();
|
||||
{
|
||||
track = PushStruct(perm, ProfTrack);
|
||||
Prof_tl.thread_track = track;
|
||||
}
|
||||
LockTicketMutex(&Prof.register_track_tm);
|
||||
{
|
||||
Prof_tl.track_idx = Atomic32Fetch(&Prof.tracks_count);
|
||||
Prof.tracks[Prof_tl.track_idx] = track;
|
||||
Atomic32FetchAdd(&Prof.tracks_count, 1);
|
||||
}
|
||||
UnlockTicketMutex(&Prof.register_track_tm);
|
||||
}
|
||||
|
||||
u64 sample_seq = track->top_sample_seq;
|
||||
ProfSample *sample = &track->samples[sample_seq % ProfTrackSamplesCap];
|
||||
{
|
||||
// TODO: Wrap rdtsc for cpu-relative <-> program-relative timestamp conversion
|
||||
// sample->stamp = __rdtsc() | ((u64)end_zone << 63);
|
||||
sample->stamp = TimeNs() | ((u64)end_zone << 63);
|
||||
}
|
||||
track->top_sample_seq = sample_seq + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if PROFILING_ENABLED
|
||||
#define ProfZoneDF(...) DeferFor(PushProfZoneEx(0), PushProfZoneEx(1))
|
||||
#else
|
||||
#define ProfZoneDF(...)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//~ Command table
|
||||
|
||||
@ -398,6 +248,7 @@ Struct(V_Profiler)
|
||||
f32 drag_view_ns;
|
||||
f32 drag_cursor_px;
|
||||
|
||||
i64 cursor_ns;
|
||||
i64 ns_per_px;
|
||||
i64 view_ns;
|
||||
};
|
||||
|
||||
2344
src/ui/ui_core.c
2344
src/ui/ui_core.c
File diff suppressed because it is too large
Load Diff
@ -89,10 +89,10 @@ Enum(UI_BoxFlag)
|
||||
UI_BoxFlag_DrawText = (1 << 0),
|
||||
UI_BoxFlag_CaptureMouse = (1 << 1),
|
||||
UI_BoxFlag_CaptureThroughChildren = (1 << 2),
|
||||
UI_BoxFlag_NoTextTruncation = (1 << 3),
|
||||
UI_BoxFlag_DontTruncateText = (1 << 3),
|
||||
UI_BoxFlag_Floating = (1 << 4),
|
||||
UI_BoxFlag_NoFloatingClampX = (1 << 5),
|
||||
UI_BoxFlag_NoFloatingClampY = (1 << 6),
|
||||
UI_BoxFlag_DontClampFloatingX = (1 << 5),
|
||||
UI_BoxFlag_DontClampFloatingY = (1 << 6),
|
||||
UI_BoxFlag_Scissor = (1 << 7),
|
||||
};
|
||||
|
||||
@ -136,6 +136,7 @@ Enum(UI_DebugBreakFlag)
|
||||
X(DebugColor, Vec4) \
|
||||
X(InvisibleDebugColor, Vec4) \
|
||||
X(Tint, Vec4) \
|
||||
X(Opacity, f32) \
|
||||
X(BorderSize, f32) \
|
||||
X(Anchor, UI_Region) \
|
||||
X(FloatingPos, Vec2) \
|
||||
@ -271,6 +272,7 @@ Struct(UI_BoxDesc)
|
||||
Vec4 debug_color;
|
||||
Vec4 invisible_debug_color;
|
||||
Vec4 tint;
|
||||
f32 opacity;
|
||||
f32 border_size;
|
||||
Vec2 scale;
|
||||
Vec4 text_color;
|
||||
@ -344,6 +346,7 @@ Struct(UI_Box)
|
||||
u64 post_index;
|
||||
|
||||
//- Layout data
|
||||
f32 solved_opacity;
|
||||
Vec2 solved_scale;
|
||||
Rng2 solved_scissor;
|
||||
Vec2 final_children_size_accum;
|
||||
|
||||
@ -21,6 +21,7 @@ UI_Key UI_BuildLabel(String text)
|
||||
f32 font_size = UI_Top(FontSize);
|
||||
Vec2 scale = UI_Top(Scale);
|
||||
Vec4 tint = UI_Top(Tint);
|
||||
f32 opacity = UI_Top(Opacity);
|
||||
Vec4 text_color = UI_Top(TextColor);
|
||||
UI_Region alignment = UI_Top(ChildAlignment);
|
||||
|
||||
@ -31,6 +32,7 @@ UI_Key UI_BuildLabel(String text)
|
||||
UI_Push(Parent, parent);
|
||||
UI_Push(Scale, scale);
|
||||
UI_Push(Tint, tint);
|
||||
UI_Push(Opacity, opacity);
|
||||
UI_Push(Font, font);
|
||||
UI_Push(FontSize, font_size);
|
||||
UI_Push(TextColor, text_color);
|
||||
@ -100,12 +102,14 @@ UI_Key UI_BuildDivider(UI_Size size, Vec4 color, Axis axis)
|
||||
UI_Key parent = UI_Top(Parent);
|
||||
Vec2 scale = UI_Top(Scale);
|
||||
Vec4 tint = UI_Top(Tint);
|
||||
f32 opacity = UI_Top(Opacity);
|
||||
UI_PushCp(UI_NilKey);
|
||||
{
|
||||
UI_PushDefaults();
|
||||
UI_Push(Parent, parent);
|
||||
UI_Push(Scale, scale);
|
||||
UI_Push(Tint, tint);
|
||||
UI_Push(Opacity, opacity);
|
||||
UI_Push(BackgroundColor, color);
|
||||
UI_Push(AxisSize, UI_GROW(1, 0), .axis = !axis);
|
||||
UI_Push(AxisSize, size, .axis = axis);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user