| 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <extension href="EXT_disjoint_timer_query/"> |
| 3 | <name>EXT_disjoint_timer_query</name> |
| 4 | |
| 5 | <contact> <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL |
| 6 | working group</a> (public_webgl 'at' khronos.org) </contact> |
| 7 | |
| 8 | <contributors> |
| 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> |
| 16 | </contributors> |
| 17 | |
| 18 | <number>26</number> |
| 19 | |
| 20 | <depends> |
| 21 | <api version="1.0"/> |
| 22 | </depends> |
| 23 | |
| 24 | <overview> |
| 25 | <mirrors href="http://www.khronos.org/registry/gles/extensions/EXT/EXT_disjoint_timer_query.txt" |
| 26 | name="EXT_disjoint_timer_query"> |
| 27 | <addendum> |
| 28 | Specifies that queries' results only become available at certain well-defined times. |
| 29 | </addendum> |
| 30 | </mirrors> |
| 31 | |
| 32 | <features> |
| 33 | <feature> |
| 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. |
| 39 | </feature> |
| 40 | <feature> |
| 41 | This version of the disjoint_timer_query extension is exposed |
| 42 | only on on WebGL 1.0 contexts. See the _webgl2 version of the |
| 43 | extension for how it is exposed on WebGL 2.0 contexts. |
| 44 | </feature> |
| 45 | </features> |
| 46 | </overview> |
| 47 | |
| 48 | <idl xml:space="preserve"> |
| 49 | typedef unsigned long long GLuint64EXT; |
| 50 | |
| 51 | [NoInterfaceObject] |
| 52 | interface WebGLTimerQueryEXT : WebGLObject { |
| 53 | }; |
| 54 | |
| 55 | [NoInterfaceObject] |
| 56 | interface EXT_disjoint_timer_query { |
| 57 | const GLenum QUERY_COUNTER_BITS_EXT = 0x8864; |
| 58 | const GLenum CURRENT_QUERY_EXT = 0x8865; |
| 59 | const GLenum QUERY_RESULT_EXT = 0x8866; |
| 60 | const GLenum QUERY_RESULT_AVAILABLE_EXT = 0x8867; |
| 61 | const GLenum TIME_ELAPSED_EXT = 0x88BF; |
| 62 | const GLenum TIMESTAMP_EXT = 0x8E28; |
| 63 | const GLenum GPU_DISJOINT_EXT = 0x8FBB; |
| 64 | |
| 65 | WebGLTimerQueryEXT? createQueryEXT(); |
| 66 | void deleteQueryEXT(WebGLTimerQueryEXT? query); |
| 67 | [WebGLHandlesContextLoss] boolean isQueryEXT(WebGLTimerQueryEXT? query); |
| 68 | void beginQueryEXT(GLenum target, WebGLTimerQueryEXT query); |
| 69 | void endQueryEXT(GLenum target); |
| 70 | void queryCounterEXT(WebGLTimerQueryEXT query, GLenum target); |
| 71 | any getQueryEXT(GLenum target, GLenum pname); |
| 72 | any getQueryObjectEXT(WebGLTimerQueryEXT query, GLenum pname); |
| 73 | }; |
| 74 | </idl> |
| 75 | |
| 76 | <newfun> |
| 77 | <function name="createQueryEXT" type="WebGLTimerQueryEXT?"> |
| 78 | </function> |
| 79 | </newfun> |
| 80 | |
| 81 | <newfun> |
| 82 | <function name="deleteQueryEXT" type="void"> |
| 83 | <param name="query" type="WebGLTimerQueryEXT?"/> |
| 84 | </function> |
| 85 | </newfun> |
| 86 | |
| 87 | <newfun> |
| 88 | <function name="isQueryEXT" type="boolean"> |
| 89 | <param name="query" type="WebGLTimerQueryEXT?"/> |
| 90 | Returns true if the passed WebGLTimerQueryEXT is valid and false otherwise. Returns false if |
| 91 | the query's <a |
| 92 | href="http://www.khronos.org/registry/webgl/specs/1.0.1/#webgl-object-invalidated-flag">invalidated |
| 93 | flag</a> is set. |
| 94 | </function> |
| 95 | </newfun> |
| 96 | |
| 97 | <newfun> |
| 98 | <function name="beginQueryEXT" type="void"> |
| 99 | <param name="target" type="GLenum"/> |
| 100 | <param name="query" type="WebGLTimerQueryEXT?"/> |
| 101 | <code>target</code> accepts <code>TIME_ELAPSED_EXT</code>. |
| 102 | </function> |
| 103 | </newfun> |
| 104 | |
| 105 | <newfun> |
| 106 | <function name="endQueryEXT" type="void"> |
| 107 | <param name="target" type="GLenum"/> |
| 108 | <code>target</code> accepts <code>TIME_ELAPSED_EXT</code>. |
| 109 | </function> |
| 110 | </newfun> |
| 111 | |
| 112 | <newfun> |
| 113 | <function name="queryCounterEXT" type="void"> |
| 114 | <param name="query" type="WebGLTimerQueryEXT?"/> |
| 115 | <param name="target" type="GLenum"/> |
| 116 | <code>target</code> accepts <code>TIMESTAMP_EXT</code>. |
| 117 | </function> |
| 118 | </newfun> |
| 119 | |
| 120 | <newfun> |
| 121 | <function name="getQueryEXT" type="any"> |
| 122 | <param name="target" type="GLenum"/> |
| 123 | <param name="pname" type="GLenum"/> |
| 124 | <code>target</code> and <code>pname</code> accept the following combinations of |
| 125 | parameters. The return type of this method depends on the parameter queried. |
| 126 | <br/> |
| 127 | <table width="30%"> |
| 128 | <tr><th>target</th><th>pname</th><th>returned type</th></tr> |
| 129 | <tr><td>TIME_ELAPSED_EXT</td><td>CURRENT_QUERY</td><td>WebGLQuery?</td></tr> |
| 130 | <tr><td>TIMESTAMP_EXT</td><td>CURRENT_QUERY</td><td>null</td></tr> |
| 131 | <tr><td>TIME_ELAPSED_EXT</td><td>QUERY_COUNTER_BITS_EXT</td><td>GLint</td></tr> |
| 132 | <tr><td>TIMESTAMP_EXT</td><td>QUERY_COUNTER_BITS_EXT</td><td>GLint</td></tr> |
| 133 | </table> |
| 134 | </function> |
| 135 | </newfun> |
| 136 | |
| 137 | <newfun> |
| 138 | <function name="getQueryObjectEXT" type="any"> |
| 139 | <param name="query" type="WebGLTimerQueryEXT?"/> |
| 140 | <param name="pname" type="GLenum"/> |
| 141 | <code>pname</code> accepts <code>QUERY_RESULT_EXT</code> or <code>QUERY_RESULT_AVAILABLE_EXT</code>. |
| 142 | <br/> |
| 143 | The return type of this method depends on the parameter queried: |
| 144 | <table width="30%"> |
| 145 | <tr><th>pname</th><th>returned type</th></tr> |
| 146 | <tr><td>QUERY_RESULT_EXT</td><td>GLuint64EXT</td></tr> |
| 147 | <tr><td>QUERY_RESULT_AVAILABLE_EXT</td><td>boolean</td></tr> |
| 148 | </table> |
| 149 | <br/> |
| 150 | In order to ensure consistent behavior across platforms, queries' results must only be made |
| 151 | available when the user agent's <a |
| 152 | href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-loops">event |
| 153 | loop</a> is not executing a task. In other words: |
| 154 | <ul> |
| 155 | <li> A query's result must not be made available until control has returned to the user |
| 156 | agent's main loop. </li> |
| 157 | <li> Repeatedly fetching a query's QUERY_RESULT_AVAILABLE_EXT parameter in a loop, without |
| 158 | returning control to the user agent, must always return the same value. </li> |
| 159 | </ul> |
| 160 | |
| 161 | <div class="note"> |
| 162 | A query's result may or may not be made available when control returns to the user |
| 163 | agent's event loop. It is not guaranteed that using a single setTimeout callback with a |
| 164 | delay of 0, or a single requestAnimationFrame callback, will allow sufficient time for |
| 165 | the WebGL implementation to supply the query's results. |
| 166 | </div> |
| 167 | |
| 168 | <div class="note rationale"> |
| 169 | This change compared to the original extension specification is enforced in order to prevent |
| 170 | applications from relying on being able to issue a query and fetch its result in the same |
| 171 | frame. In order to ensure best portability among devices and best performance among |
| 172 | implementations, applications must expect that queries' results will become available |
| 173 | asynchronously. |
| 174 | </div> |
| 175 | </function> |
| 176 | </newfun> |
| 177 | |
| 178 | <newtok> |
| 179 | <function name="getParameter" type="any"> |
| 180 | <param name="pname" type="GLenum"/> |
| 181 | <code>pname</code> accepts <code>TIMESTAMP_EXT</code> or <code>GPU_DISJOINT_EXT</code>. |
| 182 | <br/> |
| 183 | |
| 184 | The return type depends on the parameter queried: |
| 185 | <table width="30%"> |
| 186 | <tr><th>pname</th><th>returned type</th></tr> |
| 187 | <tr><td>TIMESTAMP_EXT</td><td>GLuint64EXT</td></tr> |
| 188 | <tr><td>GPU_DISJOINT_EXT</td><td>boolean</td></tr> |
| 189 | </table> |
| 190 | </function> |
| 191 | </newtok> |
| 192 | |
| 193 | <issues> |
| 194 | <ol> |
| 195 | <li> |
| 196 | <p> |
| 197 | Can getQueryObjectEXT be exposed in its current form according to ECMAScript |
| 198 | semantics? ECMAScript's <a |
| 199 | href="http://wiki.ecmascript.org/doku.php?id=strawman:concurrency">de-facto concurrency |
| 200 | model</a> is "shared nothing" communicating event loops. Is it acceptable for sequential |
| 201 | calls to getQueryObjectEXT to return different answers? Note that Date.now() advances |
| 202 | during script execution, so this may be fine; but if concerns are raised, then the API may |
| 203 | need to be redesigned to use callbacks. |
| 204 | </p> |
| 205 | </li> |
| 206 | </ol> |
| 207 | </issues> |
| 208 | |
| 209 | <samplecode xml:space="preserve"> |
| 210 | <pre> |
| 211 | // Example (1) -- uses beginQueryEXT/endQueryEXT. |
| 212 | var ext = gl.getExtension('EXT_disjoint_timer_query'); |
| 213 | var query = ext.createQueryEXT(); |
| 214 | ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query); |
| 215 | |
| 216 | // Draw object |
| 217 | gl.drawElements(...); |
| 218 | |
| 219 | ext.endQueryEXT(ext.TIME_ELAPSED_EXT); |
| 220 | |
| 221 | // ...at some point in the future, after returning control to the browser and being called again: |
| 222 | var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT); |
| 223 | var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT); |
| 224 | |
| 225 | if (available && !disjoint) { |
| 226 | // See how much time the rendering of the object took in nanoseconds. |
| 227 | var timeElapsed = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT); |
| 228 | |
| 229 | // Do something useful with the time. Note that care should be |
| 230 | // taken to use all significant bits of the result, not just the |
| 231 | // least significant 32 bits. |
| 232 | adjustObjectLODBasedOnDrawTime(timeElapsed); |
| 233 | } |
| 234 | |
| 235 | //---------------------------------------------------------------------- |
| 236 | |
| 237 | // Example (2) -- same as the example above, but uses queryCounterEXT instead. |
| 238 | var ext = gl.getExtension('EXT_disjoint_timer_query'); |
| 239 | var startQuery = ext.createQueryEXT(); |
| 240 | var endQuery = ext.createQueryEXT(); |
| 241 | ext.queryCounterEXT(startQuery, ext.TIMESTAMP_EXT); |
| 242 | |
| 243 | // Draw object |
| 244 | gl.drawElements(...); |
| 245 | |
| 246 | ext.queryCounterEXT(endQuery, ext.TIMESTAMP_EXT); |
| 247 | |
| 248 | // ...at some point in the future, after returning control to the browser and being called again: |
| 249 | var available = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_AVAILABLE_EXT); |
| 250 | var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT); |
| 251 | |
| 252 | if (available && !disjoint) { |
| 253 | // See how much time the rendering of the object took in nanoseconds. |
| 254 | var timeStart = ext.getQueryObjectEXT(startQuery, ext.QUERY_RESULT_EXT); |
| 255 | var timeEnd = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_EXT); |
| 256 | |
| 257 | // Do something useful with the time. Note that care should be |
| 258 | // taken to use all significant bits of the result, not just the |
| 259 | // least significant 32 bits. |
| 260 | adjustObjectLODBasedOnDrawTime(timeEnd - timeStart); |
| 261 | } |
| 262 | |
| 263 | //---------------------------------------------------------------------- |
| 264 | |
| 265 | // Example (3) -- check the number of timestamp bits to determine how to best |
| 266 | // measure elapsed time. |
| 267 | var ext = gl.getExtension('EXT_disjoint_timer_query'); |
| 268 | var timeElapsedQuery; |
| 269 | var startQuery; |
| 270 | var endQuery; |
| 271 | |
| 272 | var useTimestamps = false; |
| 273 | |
| 274 | if (ext.getQueryEXT(ext.TIMESTAMP_EXT, ext.QUERY_COUNTER_BITS_EXT) > 0) { |
| 275 | useTimestamps = true; |
| 276 | } |
| 277 | |
| 278 | // Clear the disjoint state before starting to work with queries to increase |
| 279 | // the chances that the results will be valid. |
| 280 | gl.getParameter(ext.GPU_DISJOINT_EXT); |
| 281 | |
| 282 | if (useTimestamps) { |
| 283 | startQuery = ext.createQueryEXT(); |
| 284 | endQuery = ext.createQueryEXT(); |
| 285 | ext.queryCounterEXT(startQuery, ext.TIMESTAMP_EXT); |
| 286 | } else { |
| 287 | timeElapsedQuery = ext.createQueryEXT(); |
| 288 | ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, timeElapsedQuery); |
| 289 | } |
| 290 | |
| 291 | // Draw object |
| 292 | gl.drawElements(...); |
| 293 | |
| 294 | if (useTimestamps) { |
| 295 | ext.queryCounterEXT(endQuery, ext.TIMESTAMP_EXT); |
| 296 | } else { |
| 297 | ext.endQueryEXT(ext.TIME_ELAPSED_EXT); |
| 298 | } |
| 299 | |
| 300 | // ...at some point in the future, after returning control to the browser and being called again: |
| 301 | var disjoint = gl.getParameter(ext.GPU_DISJOINT_EXT); |
| 302 | if (disjoint) { |
| 303 | // Have to redo all of the measurements. |
| 304 | } else { |
| 305 | var available; |
| 306 | if (useTimestamps) { |
| 307 | available = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_AVAILABLE_EXT); |
| 308 | } else { |
| 309 | available = ext.getQueryObjectEXT(timeElapsedQuery, ext.QUERY_RESULT_AVAILABLE_EXT); |
| 310 | } |
| 311 | |
| 312 | if (available) { |
| 313 | var timeElapsed; |
| 314 | if (useTimestamps) { |
| 315 | // See how much time the rendering of the object took in nanoseconds. |
| 316 | var timeStart = ext.getQueryObjectEXT(startQuery, ext.QUERY_RESULT_EXT); |
| 317 | var timeEnd = ext.getQueryObjectEXT(endQuery, ext.QUERY_RESULT_EXT); |
| 318 | timeElapsed = timeEnd - timeStart; |
| 319 | } else { |
| 320 | timeElapsed = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT); |
| 321 | } |
| 322 | |
| 323 | // Do something useful with the time. Note that care should be |
| 324 | // taken to use all significant bits of the result, not just the |
| 325 | // least significant 32 bits. |
| 326 | adjustObjectLODBasedOnDrawTime(timeElapsed); |
| 327 | } |
| 328 | } |
| 329 | </pre> |
| 330 | </samplecode> |
| 331 | |
| 332 | <history> |
| 333 | <revision date="2013/04/02"> |
| 334 | <change>Initial revision.</change> |
| 335 | </revision> |
| 336 | <revision date="2013/04/03"> |
| 337 | <change>Based on public_webgl discussion, specified that queries' results only become available at well-defined times.</change> |
| 338 | </revision> |
| 339 | <revision date="2014/02/12"> |
| 340 | <change>Recast as EXT_disjoint_timer_query and harmonized with mirrored extension.</change> |
| 341 | </revision> |
| 342 | <revision date="2014/07/15"> |
| 343 | <change>Added NoInterfaceObject extended attribute.</change> |
| 344 | </revision> |
| 345 | <revision date="2015/10/05"> |
| 346 | <change>Revised language regarding queries' availability based on feedback from Jeff Gilbert.</change> |
| 347 | </revision> |
| 348 | <revision date="2015/10/19"> |
| 349 | <change>Promoted to community approved after discussion on public_webgl.</change> |
| 350 | </revision> |
| 351 | <revision date="2016/06/08"> |
| 352 | <change>Added example choosing measurement technique based on number of timestamp bits.</change> |
| 353 | </revision> |
| 354 | <revision date="2016/09/30"> |
| 355 | <change>Added clarifying note that this document only applies to WebGL 1.0. Minor reformatting and typo fixes.</change> |
| 356 | </revision> |
| 357 | </history> |
| 358 | </extension> |