mirror of
https://github.com/FMS-Cat/condition.git
synced 2025-08-17 19:06:42 +02:00
performance: improve GPUTimer performance?
This commit is contained in:
@@ -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 );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
@@ -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 );
|
||||
},
|
||||
|
Reference in New Issue
Block a user