performance: improve GPUTimer performance?

This commit is contained in:
FMS-Cat
2021-03-22 02:39:02 +09:00
parent 4239eeea81
commit 7d50170a60
2 changed files with 19 additions and 5 deletions

View File

@@ -6,6 +6,8 @@ export class GPUTimer {
public stack: Promise<number>[];
public ext: any;
private __loopTasks: Set<() => void>;
public constructor() {
const queries = new Array( 1024 ).fill( 1 ).map( () => gl.createQuery()! );
this.queries = new Pool( queries );
@@ -13,6 +15,14 @@ export class GPUTimer {
this.stack = [];
this.ext = glCat.getExtension( 'EXT_disjoint_timer_query_webgl2' );
this.__loopTasks = new Set();
}
public update(): void {
for ( const task of this.__loopTasks ) {
task();
}
}
public async measure( func: () => void ): Promise<number> {
@@ -49,17 +59,16 @@ export class GPUTimer {
public check( query: WebGLQuery ): Promise<number> {
return new Promise( ( resolve ) => {
const loop = () => {
const task = () => {
const isAvailable = gl.getQueryParameter( query, gl.QUERY_RESULT_AVAILABLE );
if ( isAvailable ) {
this.__loopTasks.delete( task );
resolve( gl.getQueryParameter( query, gl.QUERY_RESULT ) * 0.001 * 0.001 );
} else {
setTimeout( loop, 1 );
}
}
};
loop();
this.__loopTasks.add( task );
} );
}
}

View File

@@ -20,6 +20,7 @@ import { music } from './globals/music';
import { randomTexture } from './globals/randomTexture';
import { BufferRenderTarget } from './heck/BufferRenderTarget';
import { CanvasRenderTarget } from './heck/CanvasRenderTarget';
import { Component } from './heck/components/Component';
import { Lambda } from './heck/components/Lambda';
import { Dog } from './heck/Dog';
import { Entity } from './heck/Entity';
@@ -39,6 +40,10 @@ dog.root.components.push( new Lambda( {
totalFrame ++;
isInitialFrame = false;
if ( process.env.DEV ) {
Component.gpuTimer!.update();
}
randomTexture.update();
automaton.update( music.time );
},