[Bf-blender-cvs] [d58eb8d29dc] soc-2019-openxr: Add --debug-xr-time command line option for VR frame time info prints

Julian Eisel noreply at git.blender.org
Tue Jul 23 02:10:11 CEST 2019


Commit: d58eb8d29dcdde46511384c317a73112bfea5aac
Author: Julian Eisel
Date:   Tue Jul 23 02:06:08 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rBd58eb8d29dcdde46511384c317a73112bfea5aac

Add --debug-xr-time command line option for VR frame time info prints

Outputs frame render time in milliseconds and FPS this time would add up
to. We could average times so FPS is a bit more stable, but the
precision of un-averaged results may be helpful too.

===================================================================

M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_XrContext.cpp
M	intern/ghost/intern/GHOST_XrContext.h
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	source/blender/blenkernel/BKE_global.h
M	source/blender/windowmanager/intern/wm_xr.c
M	source/creator/creator_args.c

===================================================================

diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 78bb3deeb1a..b7ccb59a3a5 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -591,6 +591,7 @@ typedef struct {
 
 enum {
   GHOST_kXrContextDebug = (1 << 0),
+  GHOST_kXrContextDebugTime = (1 << 1),
 };
 
 typedef struct {
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index 2da82ec2488..03c3fed3b9e 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -57,7 +57,9 @@ void *GHOST_XrContext::s_error_handler_customdata = nullptr;
  * \{ */
 
 GHOST_XrContext::GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
-    : m_oxr(new OpenXRInstanceData()), m_debug(create_info->context_flag & GHOST_kXrContextDebug)
+    : m_oxr(new OpenXRInstanceData()),
+      m_debug(create_info->context_flag & GHOST_kXrContextDebug),
+      m_debug_time(create_info->context_flag & GHOST_kXrContextDebugTime)
 {
 }
 GHOST_XrContext::~GHOST_XrContext()
@@ -518,4 +520,9 @@ bool GHOST_XrContext::isDebugMode() const
   return m_debug;
 }
 
+bool GHOST_XrContext::isDebugTimeMode() const
+{
+  return m_debug_time;
+}
+
 /** \} */ /* Ghost Internal Accessors and Mutators */
diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h
index 3e878bfa1d6..ec3b5d23f21 100644
--- a/intern/ghost/intern/GHOST_XrContext.h
+++ b/intern/ghost/intern/GHOST_XrContext.h
@@ -66,6 +66,7 @@ class GHOST_XrContext : public GHOST_IXrContext {
   GHOST_TXrGraphicsBinding getGraphicsBindingType() const;
   XrInstance getInstance() const;
   bool isDebugMode() const;
+  bool isDebugTimeMode() const;
 
  private:
   std::unique_ptr<struct OpenXRInstanceData> m_oxr;
@@ -87,6 +88,7 @@ class GHOST_XrContext : public GHOST_IXrContext {
 
   /** Enable debug message prints and OpenXR API validation layers */
   bool m_debug{false};
+  bool m_debug_time{false};
 
   void createOpenXRInstance();
   void initDebugMessenger();
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index fbf86fcbb83..6f8c94c0d9f 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -20,6 +20,7 @@
 
 #include <algorithm>
 #include <cassert>
+#include <chrono>
 #include <cstdio>
 #include <sstream>
 
@@ -319,6 +320,10 @@ void GHOST_XrSession::beginFrameDrawing()
 
   m_draw_frame = std::unique_ptr<GHOST_XrDrawFrame>(new GHOST_XrDrawFrame());
   m_draw_frame->frame_state = frame_state;
+
+  if (m_context->isDebugTimeMode()) {
+    m_timer_begin = std::chrono::high_resolution_clock::now();
+  }
 }
 
 void GHOST_XrSession::endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> *layers)
@@ -332,6 +337,14 @@ void GHOST_XrSession::endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *
 
   CHECK_XR(xrEndFrame(m_oxr->session, &end_info), "Failed to submit rendered frame.");
   m_draw_frame = nullptr;
+
+  if (m_context->isDebugTimeMode()) {
+    std::chrono::duration<double, std::milli> duration =
+        std::chrono::high_resolution_clock::now() - m_timer_begin;
+
+    printf(
+        "VR frame render time: %.0fms (%.2f FPS)\n", duration.count(), 1000.0 / duration.count());
+  }
 }
 
 void GHOST_XrSession::draw(void *draw_customdata)
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index f427d4a89c5..e461384dd7b 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -21,6 +21,7 @@
 #ifndef __GHOST_XRSESSION_H__
 #define __GHOST_XRSESSION_H__
 
+#include <chrono>
 #include <map>
 #include <memory>
 
@@ -60,6 +61,9 @@ class GHOST_XrSession {
   /** Information on the currently drawn frame. Set while drawing only. */
   std::unique_ptr<struct GHOST_XrDrawFrame> m_draw_frame;
 
+  /** Timer storage to benchmark frame render durations. */
+  std::chrono::high_resolution_clock::time_point m_timer_begin;
+
   void initSystem();
 
   void bindGraphicsContext();
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index a72c7a7be15..de875457b2e 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -152,6 +152,7 @@ enum {
   G_DEBUG_GPU_SHADERS = (1 << 18),           /* GLSL shaders */
   G_DEBUG_GPU_FORCE_WORKAROUNDS = (1 << 19), /* force gpu workarounds bypassing detections. */
   G_DEBUG_XR = (1 << 20),                    /* XR/OpenXR messages */
+  G_DEBUG_XR_TIME = (1 << 21),               /* XR/OpenXR timing messages */
 };
 
 #define G_DEBUG_ALL \
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index cba3ec3bbdf..db4d306217e 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -117,6 +117,9 @@ bool wm_xr_context_ensure(bContext *C, wmWindowManager *wm)
     if (G.debug & G_DEBUG_XR) {
       create_info.context_flag |= GHOST_kXrContextDebug;
     }
+    if (G.debug & G_DEBUG_XR_TIME) {
+      create_info.context_flag |= GHOST_kXrContextDebugTime;
+    }
 
     wm->xr_context = GHOST_XrContextCreate(&create_info);
   }
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 34c2dd5305a..b5edd0c4b77 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -606,6 +606,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
   BLI_argsPrintArgDoc(ba, "--debug-wm");
 #  ifdef WITH_OPENXR
   BLI_argsPrintArgDoc(ba, "--debug-xr");
+  BLI_argsPrintArgDoc(ba, "--debug-xr-time");
 #  endif
   BLI_argsPrintArgDoc(ba, "--debug-all");
   BLI_argsPrintArgDoc(ba, "--debug-io");
@@ -950,6 +951,9 @@ static const char arg_handle_debug_mode_generic_set_doc_xr[] =
     "Enable debug messages for virtual reality contexts.\n"
     "\tEnables the OpenXR API validation layer, (OpenXR) debug messages and general information "
     "prints.";
+static const char arg_handle_debug_mode_generic_set_doc_xr_time[] =
+    "\n\t"
+    "Enable debug messages for virtual reality frame rendering times.";
 #  endif
 static const char arg_handle_debug_mode_generic_set_doc_jobs[] =
     "\n\t"
@@ -2094,6 +2098,12 @@ void main_args_setup(bContext *C, bArgs *ba)
 #  ifdef WITH_OPENXR
   BLI_argsAdd(
       ba, 1, NULL, "--debug-xr", CB_EX(arg_handle_debug_mode_generic_set, xr), (void *)G_DEBUG_XR);
+  BLI_argsAdd(ba,
+              1,
+              NULL,
+              "--debug-xr-time",
+              CB_EX(arg_handle_debug_mode_generic_set, xr_time),
+              (void *)G_DEBUG_XR_TIME);
 #  endif
   BLI_argsAdd(ba, 1, NULL, "--debug-all", CB(arg_handle_debug_mode_all), NULL);



More information about the Bf-blender-cvs mailing list