Clean up some of the base layer and port Seasight changes over

This commit is contained in:
2025-07-25 22:34:07 +10:00
parent 172362cdb8
commit 31efa0cdcb
25 changed files with 954 additions and 1068 deletions
+2 -2
View File
@@ -71,7 +71,7 @@ DN_API void DN_Core_Init(DN_Core *core, DN_CoreOnInit on_init)
for (DN_ForIndexU(feature_index, DN_CPUFeature_Count)) {
DN_CPUFeatureDecl feature_decl = g_dn_cpu_feature_decl[feature_index];
bool has_feature = DN_CPU_HasFeature(report, feature_decl.value);
bool has_feature = DN_CPUHasFeature(report, feature_decl.value);
DN_Str8Builder_AppendF(&builder,
" %.*s:%*s%s\n",
DN_STR_FMT(feature_decl.label),
@@ -88,7 +88,7 @@ DN_API void DN_Core_Init(DN_Core *core, DN_CoreOnInit on_init)
DN_API void DN_Core_BeginFrame()
{
DN_Atomic_SetValue64(&g_dn_os_core_->mem_allocs_frame, 0);
DN_AtomicSetValue64(&g_dn_os_core_->mem_allocs_frame, 0);
}
#if !defined(DN_NO_PROFILER)
+9 -6
View File
@@ -1,5 +1,8 @@
#define DN_CORE_DEBUG_CPP
#include "../dn_base_inc.h"
#include "../dn_os_inc.h"
DN_API DN_StackTraceWalkResult DN_StackTrace_Walk(DN_Arena *arena, uint16_t limit)
{
DN_StackTraceWalkResult result = {};
@@ -209,7 +212,7 @@ DN_API void DN_StackTrace_ReloadSymbols()
// NOTE: DN_Debug //////////////////////////////////////////////////////////////////////////////////
#if defined(DN_LEAK_TRACKING)
DN_API void DN_Debug_TrackAlloc(void *ptr, DN_USize size, bool leak_permitted)
DN_API void DN_DBGTrackAlloc(void *ptr, DN_USize size, bool leak_permitted)
{
if (!ptr)
return;
@@ -236,7 +239,7 @@ DN_API void DN_Debug_TrackAlloc(void *ptr, DN_USize size, bool leak_permitted)
"This pointer is already in the leak tracker, however it has not been freed yet. This "
"same pointer is being ask to be tracked twice in the allocation table, e.g. one if its "
"previous free calls has not being marked freed with an equivalent call to "
"DN_Debug_TrackDealloc()\n"
"DN_DBGTrackDealloc()\n"
"\n"
"The pointer (0x%p) originally allocated %.*s at:\n"
"\n"
@@ -268,7 +271,7 @@ DN_API void DN_Debug_TrackAlloc(void *ptr, DN_USize size, bool leak_permitted)
g_dn_core->alloc_table_bytes_allocated_for_stack_traces += alloc->stack_trace.size;
}
DN_API void DN_Debug_TrackDealloc(void *ptr)
DN_API void DN_DBGTrackDealloc(void *ptr)
{
if (!ptr)
return;
@@ -317,7 +320,7 @@ DN_API void DN_Debug_TrackDealloc(void *ptr)
g_dn_core->alloc_table_bytes_allocated_for_stack_traces += alloc->freed_stack_trace.size;
}
DN_API void DN_Debug_DumpLeaks()
DN_API void DN_DBGDumpLeaks()
{
uint64_t leak_count = 0;
uint64_t leaked_bytes = 0;
@@ -383,7 +386,7 @@ DN_API DN_ProfilerZone DN_Profiler_BeginZoneAtIndex(DN_Str8 name, uint16_t ancho
#endif
anchor->name = name;
DN_ProfilerZone result = {};
result.begin_tsc = DN_CPU_TSC();
result.begin_tsc = DN_CPUGetTSC();
result.anchor_index = anchor_index;
result.parent_zone = g_dn_core->profiler->parent_zone;
result.elapsed_tsc_at_zone_start = anchor->tsc_inclusive;
@@ -393,7 +396,7 @@ DN_API DN_ProfilerZone DN_Profiler_BeginZoneAtIndex(DN_Str8 name, uint16_t ancho
DN_API void DN_Profiler_EndZone(DN_ProfilerZone zone)
{
uint64_t elapsed_tsc = DN_CPU_TSC() - zone.begin_tsc;
uint64_t elapsed_tsc = DN_CPUGetTSC() - zone.begin_tsc;
DN_ProfilerAnchor *anchor_buffer = DN_Profiler_WriteBuffer();
DN_ProfilerAnchor *anchor = anchor_buffer + zone.anchor_index;
+13 -1
View File
@@ -1,6 +1,8 @@
#if !defined(DN_CORE_DEBUG_H)
#define DN_CORE_DEBUG_H
#include "../dn_base_inc.h"
// NOTE: DN_StackTrace /////////////////////////////////////////////////////////////////////////////
// NOTE: DN_Debug //////////////////////////////////////////////////////////////////////////////////
enum DN_DebugAllocFlag
@@ -93,6 +95,16 @@ DN_API void DN_Profiler_EndZone (DN_ProfilerZ
DN_API DN_ProfilerAnchor * DN_Profiler_AnchorBuffer (DN_ProfilerAnchorBuffer buffer);
DN_API void DN_Profiler_SwapAnchorBuffer ();
DN_API void DN_Profiler_Dump (DN_U64 tsc_per_second);
#endif // !defined(DN_NO_PROFILER)
#if defined(DN_LEAK_TRACKING)
DN_API void DN_DBGTrackAlloc (void *ptr, DN_USize size, bool alloc_can_leak);
DN_API void DN_DBGTrackDealloc (void *ptr);
DN_API void DN_DBGDumpLeaks ();
#else
#define DN_DBGTrackAlloc(ptr, size, alloc_can_leak) do { (void)ptr; (void)size; (void)alloc_can_leak; } while (0)
#define DN_DBGTrackDealloc(ptr) do { (void)ptr; } while (0)
#define DN_DBGDumpLeaks() do { } while (0)
#endif
#endif // DN_CORE_DEBUG_H
+3 -3
View File
@@ -39,15 +39,15 @@ void DN_Docs_Demo()
DN_Core_Init(&core, DN_CoreOnInit_Nil);
#endif
// NOTE: DN_Atomic_SetValue64 /////////////////////////////////////////////////////////////////
// NOTE: DN_Atomic_SetValue32 /////////////////////////////////////////////////////////////////
// NOTE: DN_AtomicSetValue64 /////////////////////////////////////////////////////////////////
// NOTE: DN_AtomicSetValue32 /////////////////////////////////////////////////////////////////
// Atomically set the value into the target using an atomic compare and swap
// idiom. The return value of the function is the value that was last stored
// in the target.
{
uint64_t target = 8;
uint64_t value_to_set = 0xCAFE;
if (DN_Atomic_SetValue64(&target, value_to_set) == 8) {
if (DN_AtomicSetValue64(&target, value_to_set) == 8) {
// Atomic swap was successful, e.g. the last value that this thread
// observed was '8' which is the value we initialised with e.g. no
// other thread has modified the value.