From 8dcc2fe20da0cebdbf31ffb0c69a34337a401cd3 Mon Sep 17 00:00:00 2001
From: Hannu Hanhi <hhanhipublic@gmail.com>
Date: Fri, 1 May 2020 20:57:48 +0300
Subject: [PATCH] Move some render stats variables to better locations, add
 I_FinishUpdate timing

---
 src/d_main.c           | 14 ++++++++------
 src/hardware/hw_main.c | 10 +---------
 src/hardware/hw_main.h |  6 ------
 src/r_main.c           |  7 +++++++
 src/r_main.h           |  8 ++++++++
 5 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/src/d_main.c b/src/d_main.c
index 09aa2d340d..28e134d65c 100644
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -620,10 +620,10 @@ static void D_Display(void)
 				snprintf(s, sizeof s - 1, "sdrw %d", rs_spritedrawtime / divisor);
 				V_DrawThinString(30, 70, V_MONOSPACE | V_YELLOWMAP, s);
 				/*snprintf(s, sizeof s - 1, "post %d", rs_posttime / divisor);
+				V_DrawThinString(30, 80, V_MONOSPACE | V_YELLOWMAP, s);*/
+				snprintf(s, sizeof s - 1, "fin  %d", rs_swaptime / divisor);
 				V_DrawThinString(30, 80, V_MONOSPACE | V_YELLOWMAP, s);
-				snprintf(s, sizeof s - 1, "flip %d", rs_swaptime / divisor);
-				V_DrawThinString(30, 90, V_MONOSPACE | V_YELLOWMAP, s);
-				snprintf(s, sizeof s - 1, "test %d", rs_test / divisor);
+				/*snprintf(s, sizeof s - 1, "test %d", rs_test / divisor);
 				V_DrawThinString(30, 100, V_MONOSPACE | V_YELLOWMAP, s);*/
 
 				snprintf(s, sizeof s - 1, "nbsp %d", rs_numbspcalls);
@@ -658,14 +658,16 @@ static void D_Display(void)
 					V_DrawThinString(185, 30, V_MONOSPACE | V_PURPLEMAP, s);
 				}*/
 			}
-/*			else
+			else
 			{
-				snprintf(s, sizeof s - 1, "flip %d", rs_swaptime / divisor);
+				snprintf(s, sizeof s - 1, "fin  %d", rs_swaptime / divisor);
 				V_DrawThinString(30, 30, V_MONOSPACE | V_YELLOWMAP, s);
-			}*/
+			}
 		}
 
+		rs_swaptime = I_GetTimeMicros();
 		I_FinishUpdate(); // page flip or blit buffer
+		rs_swaptime = I_GetTimeMicros() - rs_swaptime;
 	}
 
 	needpatchflush = false;
diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index ed43ec9ae5..79cc83bba7 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -146,9 +146,7 @@ static float gr_fovlud;
 static angle_t gr_aimingangle;
 static void HWR_SetTransformAiming(FTransform *trans, player_t *player, boolean skybox);
 
-// render stats
-int rs_prevframetime = 0;
-int rs_rendercalltime = 0;
+// Render stats
 int rs_bsptime = 0;
 int rs_nodetime = 0;
 int rs_nodesorttime = 0;
@@ -162,7 +160,6 @@ int rs_numsprites = 0;
 int rs_numpolyobjects = 0;
 
 //int rs_posttime = 0;
-//int rs_swaptime = 0;
 
 
 // ==========================================================================
@@ -6166,11 +6163,6 @@ consvar_t cv_granisotropicmode = {"gr_anisotropicmode", "1", CV_CALL, granisotro
 consvar_t cv_grcorrecttricks = {"gr_correcttricks", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_grsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
 
-// render stats
-// for now have it in here in the hw code
-// could have it somewhere else since renderstats could also be a software rendering thing
-consvar_t cv_renderstats = {"renderstats", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
-
 static void CV_grfiltermode_OnChange(void)
 {
 	if (rendermode == render_opengl)
diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h
index 8aaa335fbe..f89809cc7f 100644
--- a/src/hardware/hw_main.h
+++ b/src/hardware/hw_main.h
@@ -105,11 +105,6 @@ extern fixed_t *hwbbox;
 extern FTransform atransform;
 
 
-// render stats console toggle
-extern consvar_t cv_renderstats;
-// render stats time counter variables
-extern int rs_prevframetime;// time when previous frame was rendered
-extern int rs_rendercalltime;
 extern int rs_bsptime;
 extern int rs_nodetime;
 extern int rs_nodesorttime;
@@ -118,7 +113,6 @@ extern int rs_spritesorttime;
 extern int rs_spritedrawtime;
 
 //extern int rs_posttime;
-//extern int rs_swaptime;
 
 extern int rs_numdrawnodes;
 extern int rs_numbspcalls;
diff --git a/src/r_main.c b/src/r_main.c
index a881e046d2..17eae94954 100644
--- a/src/r_main.c
+++ b/src/r_main.c
@@ -98,6 +98,11 @@ lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
 // Hack to support extra boom colormaps.
 extracolormap_t *extra_colormaps = NULL;
 
+// Render stats
+int rs_prevframetime = 0;
+int rs_rendercalltime = 0;
+int rs_swaptime = 0;
+
 static CV_PossibleValue_t drawdist_cons_t[] = {
 	{256, "256"},	{512, "512"},	{768, "768"},
 	{1024, "1024"},	{1536, "1536"},	{2048, "2048"},
@@ -148,6 +153,8 @@ consvar_t cv_homremoval = {"homremoval", "No", CV_SAVE, homremoval_cons_t, NULL,
 
 consvar_t cv_maxportals = {"maxportals", "2", CV_SAVE, maxportals_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 
+consvar_t cv_renderstats = {"renderstats", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};
+
 void SplitScreen_OnChange(void)
 {
 	if (!cv_debug && netgame)
diff --git a/src/r_main.h b/src/r_main.h
index 578eb3d54b..72d340bd9b 100644
--- a/src/r_main.h
+++ b/src/r_main.h
@@ -74,6 +74,14 @@ subsector_t *R_PointInSubsectorOrNull(fixed_t x, fixed_t y);
 
 boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph);
 
+// Render stats
+
+extern consvar_t cv_renderstats;
+
+extern int rs_prevframetime;// time when previous frame was rendered
+extern int rs_rendercalltime;
+extern int rs_swaptime;
+
 //
 // REFRESH - the actual rendering functions.
 //
-- 
GitLab