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

Fixes #1320
This commit is contained in:
rdb 2022-06-29 16:39:35 +02:00
parent 91dd802de6
commit 5493a0d5fc
7 changed files with 13 additions and 26 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

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

View File

@ -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

View File

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