[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] For review: ANGLE_timer_query extension



Thanks for the sample.

The problem is that even in this form, the query's result would still
be retrieved with a polling API (getQueryParameter). This means that
the spec would still have to include all of the caveats like
getQueryParameter generating INVALID_OPERATION if the query hadn't
been processed.

To address this issue, each query would need a callback, which would
receive the result as argument. There would be no way of retrieving
the query's result separately.

Another version of the timer query extension is about to be published
by the ES WG which introduces the concept of invalidating previous
queries, specifically if the device goes into a low power state after
the query is issued. This fits within the callback model; it would be
called with a different argument if the query was invalidated.

I'm going to try restructuring this extension in terms of callbacks.
It may turn out to be too inefficient. It'll probably be necessary to
prototype both forms to see.

-Ken


On Tue, Apr 9, 2013 at 4:02 AM, Florian Bösch <pyalot@gmail.com> wrote:
> So I have made the argument that callbacks would be no worse than polling,
> I'd like to illustrate that in code. Below is an example of how thousands of
> queries would be used but only one callback per frame is attached.
>
> // create a 10k query cache
> var queryPool = [];
> for(var i=0; i<1024*10; i++){
>   queryPool.push(ext.createQueryANGLE());
> }
>
> // frame object to hold queries
> var Frame = function(){ this.queries = []; }
>
> // called at the start of a frame, returnes used queries
> Frame.prototype.start = function(frameCount){
>   this.frameCount = frameCount;
>   while(this.queries.length > 0){
>     queryPool.push(this.queries.pop());
>   }
> }
>
> // called during a frame to obtain queries from the pool
> Frame.prototype.createQuery = function(){
>   var query = queryPool.pop();
>   query.onready = null;
>   this.queries.push(query);
>   return query;
> }
>
> // called at the end of a frame, attaches callback to the last query of the
> frame
> Frame.prototype.finish = function(callback){
>   this.queries[this.queries.length-1].onready = callback;
> }
>
> // create a 10 frame cache
> var framePool = [];
> for(var i=0; i<10; i++){
>    framePool.push(new Frame());
> }
>
> // passed to frame.finish as callback
> var onFrameMeasured = function(frame){
>   // whatever processing on frame.queries, they're all ready
>   framePool.push(frame); // return frame to the frame pool
> }
>
> var frameCounter = 0;
> var draw = function(){
>   // start a frame
>   var frame = framePool.pop();
>   frame.start(frameCounter++);
>
>   // work with your thousands of query objects
>   for(var i=0; i<1000; i++){
>    var query = frame.createQuery();
>    ext.beginQueryANGLE(ext.TIME_ELAPSED_ANGLE, query);
>    gl.drawElements(...);
>    ext.endQueryANGLE(ext.TIME_ELAPSED_ANGLE);
>   }
>
>   // attach one callback per frame
>   frame.finish(onFrameMeasured);
>
>   // wash rhinse repeat
>   requestAnimationFrame(draw);
> }
>
> requestAnimationFrame(draw);

-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------