1 <?xml version="1.0" encoding="UTF-8"?>
2 <draft href="EXT_disjoint_timer_query/">
3 <name>EXT_disjoint_timer_query</name>
5 <contact> <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL
6 working group</a> (public_webgl 'at' khronos.org) </contact>
9 <contributor>Contributors to ARB_occlusion_query</contributor>
10 <contributor>Contributors to EXT_timer_query</contributor>
11 <contributor>Contributors to ARB_timer_query</contributor>
12 <contributor>Ben Vanik, Google Inc.</contributor>
13 <contributor>Daniel Koch, TransGaming Inc.</contributor>
14 <contributor>Florian Boesch (pyalot 'at' gmail.com)</contributor>
15 <contributor>Members of the WebGL working group</contributor>
25 <mirrors href="http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt"
26 name="EXT_disjoint_timer_query">
28 Specifies that queries' results only become available at certain well-defined times.
34 This extension provides a query mechanism that can be used to determine
35 the amount of time it takes to fully complete a set of GL commands, and
36 without stalling the rendering pipeline. It uses the query object
37 mechanisms first introduced in the occlusion query extension, which allow
38 time intervals to be polled asynchronously by the application.
43 <idl xml:space="preserve">
44 typedef unsigned long long GLuint64EXT;
47 interface WebGLTimerQueryEXT : WebGLObject {
51 interface EXT_disjoint_timer_query {
52 const GLenum QUERY_COUNTER_BITS_EXT = 0x8864;
53 const GLenum CURRENT_QUERY_EXT = 0x8865;
54 const GLenum QUERY_RESULT_EXT = 0x8866;
55 const GLenum QUERY_RESULT_AVAILABLE_EXT = 0x8867;
56 const GLenum TIME_ELAPSED_EXT = 0x88BF;
57 const GLenum TIMESTAMP_EXT = 0x8E28;
58 const GLenum GPU_DISJOINT_EXT = 0x8FBB;
60 WebGLTimerQueryEXT? createQueryEXT();
61 void deleteQueryEXT(WebGLTimerQueryEXT? query);
62 [WebGLHandlesContextLoss] boolean isQueryEXT(WebGLTimerQueryEXT? query);
63 void beginQueryEXT(enum target, WebGLTimerQueryEXT? query);
64 void endQueryEXT(enum target);
65 void queryCounterEXT(WebGLTimerQueryEXT? query, enum target);
66 any getQueryEXT(enum target, enum pname);
67 any getQueryObjectEXT(WebGLTimerQueryEXT? query, enum pname);
72 <function name="createQueryEXT" type="WebGLTimerQueryEXT?">
77 <function name="deleteQueryEXT" type="void">
78 <param name="query" type="WebGLTimerQueryEXT?"/>
83 <function name="isQueryEXT" type="boolean">
84 <param name="query" type="WebGLTimerQueryEXT?"/>
85 Returns true if the passed WebGLTimerQueryEXT is valid and false otherwise. Returns false if
87 href="http://www.khronos.org/registry/webgl/specs/1.0.1/#webgl-object-invalidated-flag">invalidated
93 <function name="beginQueryEXT" type="void">
94 <param name="target" type="GLenum"/>
95 <param name="query" type="WebGLTimerQueryEXT?"/>
96 <code>target</code> accepts <code>TIME_ELAPSED_EXT</code>.
101 <function name="endQueryEXT" type="void">
102 <param name="target" type="GLenum"/>
103 <code>target</code> accepts <code>TIME_ELAPSED_EXT</code>.
108 <function name="queryCounterEXT" type="void">
109 <param name="query" type="WebGLTimerQueryEXT?"/>
110 <param name="target" type="GLenum"/>
111 <code>target</code> accepts <code>TIMESTAMP_EXT</code>.
116 <function name="getQueryEXT" type="any">
117 <param name="target" type="GLenum"/>
118 <param name="pname" type="GLenum"/>
119 <code>target</code> accepts <code>TIME_ELAPSED_EXT</code> or <code>TIMESTAMP_EXT</code>.
120 <code>pname</code> accepts <code>CURRENT_QUERY_EXT</code> or <code>QUERY_COUNTER_BITS_EXT</code>.
122 The return type of this method depends on the parameter queried:
124 <tr><th>pname</th><th>returned type</th></tr>
125 <tr><td>CURRENT_QUERY_EXT</td><td>WebGLTimerQueryEXT?</td></tr>
126 <tr><td>QUERY_COUNTER_BITS_EXT</td><td>GLint</td></tr>
132 <function name="getQueryObjectEXT" type="any">
133 <param name="query" type="WebGLTimerQueryEXT?"/>
134 <param name="pname" type="GLenum"/>
135 <code>pname</code> accepts <code>QUERY_RESULT_EXT</code> or <code>QUERY_RESULT_AVAILABLE_EXT</code>.
137 The return type of this method depends on the parameter queried:
139 <tr><th>pname</th><th>returned type</th></tr>
140 <tr><td>QUERY_RESULT_EXT</td><td>GLuint64EXT</td></tr>
141 <tr><td>QUERY_RESULT_AVAILABLE_EXT</td><td>boolean</td></tr>
144 In order to ensure consistent behavior across platforms, queries' results must only be made
145 available when the user agent's <a
146 href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-loops">event
147 loop</a> is not executing a task. In other words:
149 <li> A query's result must not be made available until the current frame has completed
151 <li> Repeatedly fetching a query's QUERY_RESULT_AVAILABLE_EXT parameter in a loop, without
152 returning control to the user agent, must always return the same value. </li>
158 <function name="getParameter" type="any">
159 <param name="pname" type="GLenum"/>
160 <code>pname</code> accepts <code>TIMESTAMP_EXT</code> or <code>GPU_DISJOINT_EXT</code>.
163 The return type depends on the parameter queried:
165 <tr><th>pname</th><th>returned type</th></tr>
166 <tr><td>TIMESTAMP_EXT</td><td>GLuint64EXT</td></tr>
167 <tr><td>GPU_DISJOINT_EXT</td><td>boolean</td></tr>
176 Can getQueryObjectEXT be exposed in its current form according to ECMAScript
177 semantics? ECMAScript's <a
178 href="http://wiki.ecmascript.org/doku.php?id=strawman:concurrency">de-facto concurrency
179 model</a> is "shared nothing" communicating event loops. Is it acceptable for sequential
180 calls to getQueryObjectEXT to return different answers? Note that Date.now() advances
181 during script execution, so this may be fine; but if concerns are raised, then the API may
182 need to be redesigned to use callbacks.
188 <samplecode xml:space="preserve">
190 // Example (1) -- uses beginQueryEXT/endQueryEXT.
191 var ext = gl.getExtension('EXT_disjoint_timer_query');
192 var query = ext.createQueryEXT();
193 ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query);
196 gl.drawElements(...);
198 ext.endQueryEXT(ext.TIME_ELAPSED_EXT);
200 // At some point in the future, after returning control to the browser and being called again:
201 var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT);
202 var disjoint = gl.getParamater(ext.GPU_DISJOINT_EXT);
204 if (available && !disjoint) {
205 // See how much time the rendering of the object took in nanoseconds.
206 var timeElapsed = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT);
208 // Do something useful with the time. Note that care should be
209 // taken to use all significant bits of the result, not just the
210 // least significant 32 bits.
211 adjustObjectLODBasedOnDrawTime(timeElapsed);
215 //----------------------------------------------------------------------
217 // Example (2) -- same as the example above, but uses queryCounterEXT instead.
218 var ext = gl.getExtension('EXT_disjoint_timer_query');
219 var startQuery = ext.createQueryEXT();
220 var endQuery = ext.createQueryEXT();
221 ext.queryCounterEXT(startQuery, ext.TIMESTAMP_EXT);
224 gl.drawElements(...);
226 ext.queryCounterEXT(endQuery, ext.TIMESTAMP_EXT);
228 // At some point in the future, after returning control to the browser and being called again:
229 var available = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_AVAILABLE_EXT);
230 var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT);
232 if (available && !disjoint) {
233 // See how much time the rendering of the object took in nanoseconds.
234 var timeStart = ext.getQueryObjectEXT(startQuery, ext.QUERY_RESULT_EXT);
235 var timeEnd = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_EXT);
237 // Do something useful with the time. Note that care should be
238 // taken to use all significant bits of the result, not just the
239 // least significant 32 bits.
240 adjustObjectLODBasedOnDrawTime(timeEnd - timeStart);
246 <revision date="2013/04/02">
247 <change>Initial revision.</change>
249 <revision date="2013/04/03">
250 <change>Based on public_webgl discussion, specified that queries' results only become available at well-defined times.</change>
252 <revision date="2014/02/12">
253 <change>Recast as EXT_disjoint_timer_query and harmonized with mirrored extension.</change>
255 <revision date="2014/07/15">
256 <change>Added NoInterfaceObject extended attribute.</change>