|
@@ -73,26 +73,35 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
const renderContextData = this.get( renderContext );
|
|
const renderContextData = this.get( renderContext );
|
|
|
|
|
|
|
|
+ if ( this.queryRunning ) {
|
|
|
|
+
|
|
|
|
+ if ( ! renderContextData.queryQueue ) renderContextData.queryQueue = [];
|
|
|
|
+ renderContextData.queryQueue.push( renderContext );
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
if ( renderContextData.activeQuery ) {
|
|
if ( renderContextData.activeQuery ) {
|
|
|
|
|
|
- // End the previous query if it's still active
|
|
|
|
- this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
|
|
|
|
|
|
+ this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
|
|
|
|
+ renderContextData.activeQuery = null;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
renderContextData.activeQuery = this.gl.createQuery();
|
|
renderContextData.activeQuery = this.gl.createQuery();
|
|
|
|
+
|
|
if ( renderContextData.activeQuery !== null ) {
|
|
if ( renderContextData.activeQuery !== null ) {
|
|
|
|
|
|
- this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery );
|
|
|
|
|
|
+ this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery );
|
|
|
|
+ this.queryRunning = true;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// timestamp utils
|
|
// timestamp utils
|
|
|
|
|
|
- prepareTimestampBuffer( renderContext ) {
|
|
|
|
|
|
+ prepareTimestampBuffer( renderContext ) {
|
|
|
|
|
|
if ( ! this.disjoint || ! this.trackTimestamp ) return;
|
|
if ( ! this.disjoint || ! this.trackTimestamp ) return;
|
|
|
|
|
|
@@ -100,39 +109,45 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
if ( renderContextData.activeQuery ) {
|
|
if ( renderContextData.activeQuery ) {
|
|
|
|
|
|
- this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
|
|
|
|
- // Add the active query to the gpuQueries array and reset it
|
|
|
|
- if ( renderContextData.gpuQueries === undefined ) renderContextData.gpuQueries = [];
|
|
|
|
- renderContextData.gpuQueries.push( { query: renderContextData.activeQuery } );
|
|
|
|
- renderContextData.activeQuery = null;
|
|
|
|
|
|
+ this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
|
|
|
|
+
|
|
|
|
+ if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
|
|
|
|
+ renderContextData.gpuQueries.push( { query: renderContextData.activeQuery } );
|
|
|
|
+ renderContextData.activeQuery = null;
|
|
|
|
+ this.queryRunning = false;
|
|
|
|
+
|
|
|
|
+ if ( renderContextData.queryQueue && renderContextData.queryQueue.length > 0 ) {
|
|
|
|
+
|
|
|
|
+ const nextRenderContext = renderContextData.queryQueue.shift();
|
|
|
|
+ this.initTimestampQuery( nextRenderContext );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- async resolveTimestampAsync( renderContext, type = 'render' ) {
|
|
|
|
|
|
+ async resolveTimestampAsync( renderContext, type = 'render' ) {
|
|
|
|
|
|
if ( ! this.disjoint || ! this.trackTimestamp ) return;
|
|
if ( ! this.disjoint || ! this.trackTimestamp ) return;
|
|
|
|
|
|
const renderContextData = this.get( renderContext );
|
|
const renderContextData = this.get( renderContext );
|
|
|
|
|
|
- for ( let i = 0; i < renderContextData.gpuQueries.length; i ++ ) {
|
|
|
|
|
|
+ if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
|
|
|
|
|
|
- const queryInfo = renderContextData.gpuQueries[ i ];
|
|
|
|
|
|
+ for ( let i = 0; i < renderContextData.gpuQueries.length; i ++ ) {
|
|
|
|
|
|
- const available = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT_AVAILABLE );
|
|
|
|
- const disjoint = this.gl.getParameter( this.disjoint.GPU_DISJOINT_EXT );
|
|
|
|
|
|
+ const queryInfo = renderContextData.gpuQueries[ i ];
|
|
|
|
+ const available = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT_AVAILABLE );
|
|
|
|
+ const disjoint = this.gl.getParameter( this.disjoint.GPU_DISJOINT_EXT );
|
|
|
|
|
|
- if ( available && ! disjoint ) {
|
|
|
|
|
|
+ if ( available && ! disjoint ) {
|
|
|
|
|
|
const elapsed = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT );
|
|
const elapsed = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT );
|
|
const duration = Number( elapsed ) / 1000000; // Convert nanoseconds to milliseconds
|
|
const duration = Number( elapsed ) / 1000000; // Convert nanoseconds to milliseconds
|
|
-
|
|
|
|
this.gl.deleteQuery( queryInfo.query );
|
|
this.gl.deleteQuery( queryInfo.query );
|
|
renderContextData.gpuQueries.splice( i, 1 ); // Remove the processed query
|
|
renderContextData.gpuQueries.splice( i, 1 ); // Remove the processed query
|
|
-
|
|
|
|
i --;
|
|
i --;
|
|
-
|
|
|
|
this.renderer.info.updateTimestamp( type, duration );
|
|
this.renderer.info.updateTimestamp( type, duration );
|
|
|
|
|
|
}
|
|
}
|