summaryrefslogtreecommitdiff
path: root/reduced_system_layer.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-04-07 08:02:24 +0200
committerMitya Selivanov <automainint@guattari.tech>2025-04-07 08:02:24 +0200
commitaf8c9212a029ddaf8e7eef66cecaa762263ca0c5 (patch)
tree3453d3e0eeacd6c3e496aba1e66e11ae3504a590 /reduced_system_layer.c
parent3a9715a7a5cc03fef0f99064601112c093ddaae1 (diff)
downloadreduced_system_layer-af8c9212a029ddaf8e7eef66cecaa762263ca0c5.zip
Add graphics profiling
Diffstat (limited to 'reduced_system_layer.c')
-rwxr-xr-xreduced_system_layer.c72
1 files changed, 47 insertions, 25 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index 7e0dcf7..131ee5c 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -268,7 +268,7 @@ i32 main(i32 argc, c8 **argv);
#endif
#ifndef STATIC_MEMORY_BUFFER_SIZE
-#define STATIC_MEMORY_BUFFER_SIZE (200 * 1024 * 1024)
+#define STATIC_MEMORY_BUFFER_SIZE (400 * 1024 * 1024)
#endif
#ifndef MEMORY_CHUNK_SIZE
@@ -756,10 +756,20 @@ extern Platform g_platform;
Platform g_platform = {0};
enum {
+ PROFILE_MEMORY,
PROFILE_DOWNSCALE,
PROFILE_RESIZE,
PROFILE_WAITING,
PROFILE_FRAME,
+ PROFILE_DRAW_PIXELS,
+ PROFILE_FILL_RECTANGLE,
+ PROFILE_FILL_TRIANGLE,
+ PROFILE_FILL_TRIANGLES,
+ PROFILE_FILL_QUAD,
+ PROFILE_FILL_ELLIPSE,
+ PROFILE_FILL_LINE,
+ PROFILE_DRAW_TEXT_AREA,
+ PROFILE_DRAW_TEXT_CURSOR,
};
// ================================================================
@@ -1285,6 +1295,10 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf
return NULL;
}
+ u8 *dst = NULL;
+
+ PROFILER_begin(PROFILE_MEMORY);
+
i64 occupied_len = memory_buffer_occupied_len_(memory_buffer_size);
i64 occupied_len_bytes = occupied_len * 8;
i64 occupied_len_bits = occupied_len * 64;
@@ -1293,27 +1307,27 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf
if (memory_buffer_size <= occupied_len_bytes) {
LOG_ERROR("Memory buffer too small.");
- return NULL;
+ goto _finish;
}
if (alignment <= 0) {
LOG_ERROR("Invalid alignment: %lld", alignment);
- return NULL;
+ goto _finish;
}
if (size < 0) {
LOG_ERROR("Invalid size: %lld", size);
- return NULL;
+ goto _finish;
}
if (previous_size < 0) {
LOG_ERROR("Invalid previous size: %lld", previous_size);
- return NULL;
+ goto _finish;
}
if (previous_size > 0 && previous_data == NULL) {
LOG_ERROR("Invalid previous data.");
- return NULL;
+ goto _finish;
}
u8 *data = memory_buffer + occupied_len_bytes;
@@ -1329,10 +1343,10 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf
i64 num_chunks = (align_(size, alignment) + MEMORY_CHUNK_SIZE - 1) / MEMORY_CHUNK_SIZE;
i64 chunk = (memory_buffer_size + MEMORY_CHUNK_SIZE - 1) / MEMORY_CHUNK_SIZE;
- if (num_chunks == prev_num_chunks)
- return previous_data;
-
- u8 *dst = NULL;
+ if (num_chunks == prev_num_chunks) {
+ dst = (u8 *) previous_data;
+ goto _finish;
+ }
if (num_chunks < prev_num_chunks) {
// Reuse previously allocated space.
@@ -1399,8 +1413,10 @@ static void *memory_buffer_allocate_from_(i64 memory_buffer_size, u8 *memory_buf
}
if (num_chunks == 0)
- return NULL;
+ dst = NULL;
+_finish:
+ PROFILER_end(PROFILE_MEMORY);
return dst;
}
@@ -1493,10 +1509,8 @@ void PROFILER_init(u32 slot, c8 *name) {
}
void PROFILER_begin(u32 slot) {
- if ((i64) (u64) slot >= _profiler_num_slots) {
- LOG_ERROR("Invalid slot: %d", (i32) slot);
+ if ((i64) (u64) slot >= _profiler_num_slots)
return;
- }
if (_profiler_slots[slot].count < 0) {
LOG_ERROR("Sanity");
@@ -1533,10 +1547,8 @@ static void normalize_time_(i64 *sec, i64 *nsec) {
}
void PROFILER_end(u32 slot) {
- if ((i64) (u64) slot >= _profiler_num_slots) {
- LOG_ERROR("Invalid slot: %d", (i32) slot);
+ if ((i64) (u64) slot >= _profiler_num_slots)
return;
- }
if (_profiler_slots[slot].count <= 0) {
LOG_ERROR("Sanity");
@@ -3125,10 +3137,20 @@ void put_image_to_main_window_(void) {
}
void init_main_window(void) {
- PROFILER_init(PROFILE_DOWNSCALE, "Downscale anti-aliasing");
- PROFILER_init(PROFILE_RESIZE, "Resize in-place");
- PROFILER_init(PROFILE_WAITING, "Waiting for events");
- PROFILER_init(PROFILE_FRAME, "Update frame");
+ PROFILER_init(PROFILE_MEMORY, "Memory allocator");
+ PROFILER_init(PROFILE_DOWNSCALE, "Downscale anti-aliasing");
+ PROFILER_init(PROFILE_RESIZE, "Resize in-place");
+ PROFILER_init(PROFILE_WAITING, "Waiting for events");
+ PROFILER_init(PROFILE_FRAME, "Update frame");
+ PROFILER_init(PROFILE_DRAW_PIXELS, "Draw pixels");
+ PROFILER_init(PROFILE_FILL_RECTANGLE, "Fill rectangle");
+ PROFILER_init(PROFILE_FILL_TRIANGLE, "Fill triangle");
+ PROFILER_init(PROFILE_FILL_TRIANGLES, "Fill triangles");
+ PROFILER_init(PROFILE_FILL_QUAD, "Fill quad");
+ PROFILER_init(PROFILE_FILL_ELLIPSE, "Fill ellipse");
+ PROFILER_init(PROFILE_FILL_LINE, "Fill line");
+ PROFILER_init(PROFILE_DRAW_TEXT_AREA, "Draw text area");
+ PROFILER_init(PROFILE_DRAW_TEXT_CURSOR, "Draw text cursor");
for (i64 i = 0; i < NUM_FRAMES_AVERAGED; ++i)
_frame_duration[i] = (MIN_FRAME_DURATION + MAX_FRAME_DURATION) / 2;
@@ -3358,11 +3380,11 @@ void shutdown_all_systems(void) {
if (_profiler_num_slots > 0) {
printf("\nPROFILER REPORT\n\n");
for (i64 i = 0; i < _profiler_num_slots; ++i) {
- if (_profiler_slots[i].name == NULL)
- continue;
- f64 k = 1. / _profiler_slots[i].amount;
+ if (_profiler_slots[i].name == NULL || _profiler_slots[i].amount == 0)
+ continue;
+ f64 k = _profiler_slots[i].amount == 0 ? 0. : 1. / _profiler_slots[i].amount;
f64 f = ((f64) _profiler_slots[i].time_sec) * k + ((f64 )_profiler_slots[i].time_nsec * .000000001) * k;
- printf("%-31s %3lld.%09lld / %4lld = %g\n", _profiler_slots[i].name, _profiler_slots[i].time_sec, _profiler_slots[i].time_nsec, _profiler_slots[i].amount, f);
+ printf("%-31s %3lld.%09lld / %4lld = %.6f\n", _profiler_slots[i].name, _profiler_slots[i].time_sec, _profiler_slots[i].time_nsec, _profiler_slots[i].amount, f);
}
printf("\n");
}