Browse Source

glgsg: Fix PStats GPU timing not working with newer NVIDIA drivers

Fixes #1320
rdb 3 years ago
parent
commit
5493a0d5fc

+ 3 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -2717,6 +2717,8 @@ reset() {
 
     _glGetInteger64v = (PFNGLGETINTEGER64VPROC)
       get_extension_func("glGetInteger64v");
+
+    _glGetInteger64v(GL_TIMESTAMP, &_timer_query_epoch);
   }
 #endif
 
@@ -6889,6 +6891,7 @@ issue_timer_query(int pstats_index) {
     query = new CLP(LatencyQueryContext)(this, pstats_index);
   } else {
     query = new CLP(TimerQueryContext)(this, pstats_index);
+    query->_epoch = _timer_query_epoch;
   }
 
   if (_deleted_queries.size() >= 1) {

+ 4 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -1139,6 +1139,10 @@ public:
 
   BufferResidencyTracker _renderbuffer_residency;
 
+#ifndef OPENGLES
+  GLint64 _timer_query_epoch = 0;
+#endif
+
   static PStatCollector _load_display_list_pcollector;
   static PStatCollector _primitive_batches_display_list_pcollector;
   static PStatCollector _vertices_display_list_pcollector;

+ 2 - 20
panda/src/glstuff/glLatencyQueryContext_src.cxx

@@ -21,27 +21,9 @@ TypeHandle CLP(LatencyQueryContext)::_type_handle;
 CLP(LatencyQueryContext)::
 CLP(LatencyQueryContext)(CLP(GraphicsStateGuardian) *glgsg,
                          int pstats_index) :
-  CLP(TimerQueryContext)(glgsg, pstats_index),
-  _timestamp(0)
+  CLP(TimerQueryContext)(glgsg, pstats_index)
 {
-  glgsg->_glGetInteger64v(GL_TIMESTAMP, &_timestamp);
-}
-
-/**
- * Returns the timestamp that is the result of this timer query.  There's no
- * guarantee about which clock this uses, the only guarantee is that
- * subtracting a start time from an end time should yield a time in seconds.
- * If is_answer_ready() did not return true, this function may block before it
- * returns.
- *
- * It is only valid to call this from the draw thread.
- */
-double CLP(LatencyQueryContext)::
-get_timestamp() const {
-  GLint64 time_ns;
-  _glgsg->_glGetQueryObjecti64v(_index, GL_QUERY_RESULT, &time_ns);
-
-  return (time_ns - _timestamp) * 0.000000001;
+  glgsg->_glGetInteger64v(GL_TIMESTAMP, &_epoch);
 }
 
 #endif  // OPENGLES

+ 0 - 4
panda/src/glstuff/glLatencyQueryContext_src.h

@@ -26,10 +26,6 @@ public:
 
   ALLOC_DELETED_CHAIN(CLP(LatencyQueryContext));
 
-  virtual double get_timestamp() const;
-
-  GLint64 _timestamp;
-
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 2 - 1
panda/src/glstuff/glTimerQueryContext_src.I

@@ -19,6 +19,7 @@ CLP(TimerQueryContext)(CLP(GraphicsStateGuardian) *glgsg,
                        int pstats_index) :
   TimerQueryContext(pstats_index),
   _glgsg(glgsg),
-  _index(0)
+  _index(0),
+  _epoch(0)
 {
 }

+ 1 - 1
panda/src/glstuff/glTimerQueryContext_src.cxx

@@ -90,7 +90,7 @@ get_timestamp() const {
 
   _glgsg->_glGetQueryObjectui64v(_index, GL_QUERY_RESULT, &time_ns);
 
-  return time_ns * 0.000000001;
+  return (time_ns - _epoch) * 0.000000001;
 }
 
 #endif  // OPENGLES

+ 1 - 0
panda/src/glstuff/glTimerQueryContext_src.h

@@ -39,6 +39,7 @@ public:
 
   GLuint _index;
   WPT(CLP(GraphicsStateGuardian)) _glgsg;
+  GLint64 _epoch;
 
 public:
   static TypeHandle get_class_type() {