aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-22 18:30:45 +0200
committerBad Diode <bd@badd10de.dev>2023-04-22 18:30:45 +0200
commit4305d585d87c6bbc197b0fe2d9f144d6d0b772e2 (patch)
tree97491407729dd51e14a908d42ffff4d0d94e844e
parent84196f9aa9c1cacc0d240b4aafa795cd26febaa9 (diff)
downloaduxngba-4305d585d87c6bbc197b0fe2d9f144d6d0b772e2.tar.gz
uxngba-4305d585d87c6bbc197b0fe2d9f144d6d0b772e2.zip
Add frame time and FPS calculation to profiling macros
-rw-r--r--src/common.h1
-rw-r--r--src/main.c17
2 files changed, 15 insertions, 3 deletions
diff --git a/src/common.h b/src/common.h
index 1fbfa4c..bbe6b52 100644
--- a/src/common.h
+++ b/src/common.h
@@ -735,6 +735,7 @@ wait_vsync(void) {
735#define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0])) 735#define LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
736 736
737// Fixed-point arithmetic for (i.P) numbers. 737// Fixed-point arithmetic for (i.P) numbers.
738#define FP_NUM(A,P) ((A) << (P))
738#define FP_MUL(A,B,P) (((A) * (B)) >> (P)) 739#define FP_MUL(A,B,P) (((A) * (B)) >> (P))
739#define FP_DIV(A,B,P) (((A) << (P)) / (B)) 740#define FP_DIV(A,B,P) (((A) << (P)) / (B))
740#define FP_LERP(Y0,Y1,X,P) ((Y0) + FP_MUL((X), ((Y1) - (Y0)), P)) 741#define FP_LERP(Y0,Y1,X,P) ((Y0) + FP_MUL((X), ((Y1) - (Y0)), P))
diff --git a/src/main.c b/src/main.c
index c6242c2..a2a43d4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -88,8 +88,19 @@
88 txt_printf(">FLIP %.8lu\n", avg_flip_cycles);\ 88 txt_printf(">FLIP %.8lu\n", avg_flip_cycles);\
89 txt_printf("AUDIO %.8lu\n", avg_mix_cycles);\ 89 txt_printf("AUDIO %.8lu\n", avg_mix_cycles);\
90 txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\ 90 txt_printf("TOTAL %.8lu\n", avg_frame_cycles);\
91 screen_fill(BG_BACK, 0, 0, 8 * 16, 8 * 10, 0);\ 91 u32 frame_time =\
92 flipbuf();\ 92 FP_DIV(\
93 FP_NUM(avg_frame_cycles + 1, 2),\
94 FP_NUM(2809, 2),\
95 2) * 166;\
96 u32 fps =\
97 FP_DIV(\
98 FP_NUM(280896 * 60, 2),\
99 FP_NUM(avg_frame_cycles + 1, 2),\
100 2);\
101 txt_printf("TIME %.8lu\n", frame_time >> 2);\
102 txt_printf("FPS %.8lu\n", (fps >> 2) + 1);\
103 screen_fill(BG_BACK, 0, 0, 8 * 16, 8 * 12, 2);\
93 } while (0) 104 } while (0)
94 105
95static u32 prof_frame_counter = 0; 106static u32 prof_frame_counter = 0;
@@ -727,7 +738,6 @@ main(void) {
727 // NOTE: A VBLANK is 83776 cycles, anything other than that will make it so 738 // NOTE: A VBLANK is 83776 cycles, anything other than that will make it so
728 // we fail to render at 60FPS. 739 // we fail to render at 60FPS.
729 while(true) { 740 while(true) {
730 PROF_SHOW();
731 bios_vblank_wait(); 741 bios_vblank_wait();
732 FRAME_START(); 742 FRAME_START();
733 PROF(handle_input(&u), input_cycles); 743 PROF(handle_input(&u), input_cycles);
@@ -735,6 +745,7 @@ main(void) {
735 PROF(sound_mix(), mix_cycles); 745 PROF(sound_mix(), mix_cycles);
736 // TODO: allow configuration to do VSYNC at 15 or 30 fps to avoid too 746 // TODO: allow configuration to do VSYNC at 15 or 30 fps to avoid too
737 // much memory copying on demanding uxn roms. 747 // much memory copying on demanding uxn roms.
748 PROF_SHOW();
738 PROF(flipbuf(), flip_cycles); 749 PROF(flipbuf(), flip_cycles);
739 frame_counter++; 750 frame_counter++;
740 if (frame_counter == 60) { 751 if (frame_counter == 60) {