15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci EXT_timer_query 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_EXT_timer_query 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContact 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci James Jones, NVIDIA Corporation (jajones 'at' nvidia.com) 125bd8deadSopenharmony_ci 135bd8deadSopenharmony_ciContributors 145bd8deadSopenharmony_ci 155bd8deadSopenharmony_ci Axel Mamode, Sony 165bd8deadSopenharmony_ci Brian Paul, Tungsten Graphics 175bd8deadSopenharmony_ci Pat Brown, NVIDIA 185bd8deadSopenharmony_ci Remi Arnaud, Sony 195bd8deadSopenharmony_ci 205bd8deadSopenharmony_ciStatus 215bd8deadSopenharmony_ci 225bd8deadSopenharmony_ci Shipping (version 1.0) 235bd8deadSopenharmony_ci 245bd8deadSopenharmony_ci Supported by NVIDIA Release 80 drivers. 255bd8deadSopenharmony_ci 265bd8deadSopenharmony_ciVersion 275bd8deadSopenharmony_ci 285bd8deadSopenharmony_ci Last Modified Date: 2013/06/25 295bd8deadSopenharmony_ci Revision: 3 305bd8deadSopenharmony_ci 315bd8deadSopenharmony_ciNumber 325bd8deadSopenharmony_ci 335bd8deadSopenharmony_ci 319 345bd8deadSopenharmony_ci 355bd8deadSopenharmony_ciDependencies 365bd8deadSopenharmony_ci 375bd8deadSopenharmony_ci Written based on the wording of the OpenGL 2.0 specification. 385bd8deadSopenharmony_ci 395bd8deadSopenharmony_ci OpenGL 1.5 is required. 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ci This extension modifies ARB_occlusion_query and NV_occlusion_query. 425bd8deadSopenharmony_ci 435bd8deadSopenharmony_ciOverview 445bd8deadSopenharmony_ci 455bd8deadSopenharmony_ci Applications can benefit from accurate timing information in a number of 465bd8deadSopenharmony_ci different ways. During application development, timing information can 475bd8deadSopenharmony_ci help identify application or driver bottlenecks. At run time, 485bd8deadSopenharmony_ci applications can use timing information to dynamically adjust the amount 495bd8deadSopenharmony_ci of detail in a scene to achieve constant frame rates. OpenGL 505bd8deadSopenharmony_ci implementations have historically provided little to no useful timing 515bd8deadSopenharmony_ci information. Applications can get some idea of timing by reading timers 525bd8deadSopenharmony_ci on the CPU, but these timers are not synchronized with the graphics 535bd8deadSopenharmony_ci rendering pipeline. Reading a CPU timer does not guarantee the completion 545bd8deadSopenharmony_ci of a potentially large amount of graphics work accumulated before the 555bd8deadSopenharmony_ci timer is read, and will thus produce wildly inaccurate results. 565bd8deadSopenharmony_ci glFinish() can be used to determine when previous rendering commands have 575bd8deadSopenharmony_ci been completed, but will idle the graphics pipeline and adversely affect 585bd8deadSopenharmony_ci application performance. 595bd8deadSopenharmony_ci 605bd8deadSopenharmony_ci This extension provides a query mechanism that can be used to determine 615bd8deadSopenharmony_ci the amount of time it takes to fully complete a set of GL commands, and 625bd8deadSopenharmony_ci without stalling the rendering pipeline. It uses the query object 635bd8deadSopenharmony_ci mechanisms first introduced in the occlusion query extension, which allow 645bd8deadSopenharmony_ci time intervals to be polled asynchronously by the application. 655bd8deadSopenharmony_ci 665bd8deadSopenharmony_ciIssues 675bd8deadSopenharmony_ci 685bd8deadSopenharmony_ci What time interval is being measured? 695bd8deadSopenharmony_ci 705bd8deadSopenharmony_ci RESOLVED: The timer starts when all commands prior to BeginQuery() have 715bd8deadSopenharmony_ci been fully executed. At that point, everything that should be drawn by 725bd8deadSopenharmony_ci those commands has been written to the framebuffer. The timer stops 735bd8deadSopenharmony_ci when all commands prior to EndQuery() have been fully executed. 745bd8deadSopenharmony_ci 755bd8deadSopenharmony_ci What unit of time will time intervals be returned in? 765bd8deadSopenharmony_ci 775bd8deadSopenharmony_ci RESOLVED: Nanoseconds (10^-9 seconds). This unit of measurement allows 785bd8deadSopenharmony_ci for reasonably accurate timing of even small blocks of rendering 795bd8deadSopenharmony_ci commands. The granularity of the timer is implementation-dependent. A 805bd8deadSopenharmony_ci 32-bit query counter can express intervals of up to approximately 4 815bd8deadSopenharmony_ci seconds. 825bd8deadSopenharmony_ci 835bd8deadSopenharmony_ci What should be the minimum number of counter bits for timer queries? 845bd8deadSopenharmony_ci 855bd8deadSopenharmony_ci RESOLVED: 30 bits, which will allow timing sections that take up to 1 865bd8deadSopenharmony_ci second to render. 875bd8deadSopenharmony_ci 885bd8deadSopenharmony_ci How are counter results of more than 32 bits returned? 895bd8deadSopenharmony_ci 905bd8deadSopenharmony_ci RESOLVED: Using the int64 and uint64 datatypes (introduced in OpenGL 915bd8deadSopenharmony_ci 3.2 and used by this extension as well), and corresponding 925bd8deadSopenharmony_ci GetQueryObject entry points. These types hold integer values and have 935bd8deadSopenharmony_ci a minimum bit width of 64. 945bd8deadSopenharmony_ci 955bd8deadSopenharmony_ci Should the extension measure total time elapsed between the full 965bd8deadSopenharmony_ci completion of the BeginQuery and EndQuery commands, or just time spent in 975bd8deadSopenharmony_ci the graphics library? 985bd8deadSopenharmony_ci 995bd8deadSopenharmony_ci RESOLVED: This extension will measure the total time elapsed between 1005bd8deadSopenharmony_ci the full completion of these commands. Future extensions may implement 1015bd8deadSopenharmony_ci a query to determine time elapsed at different stages of the graphics 1025bd8deadSopenharmony_ci pipeline. 1035bd8deadSopenharmony_ci 1045bd8deadSopenharmony_ci This extension introduces a second query type supported by 1055bd8deadSopenharmony_ci BeginQuery/EndQuery. Can multiple query types be active simultaneously? 1065bd8deadSopenharmony_ci 1075bd8deadSopenharmony_ci RESOLVED: Yes; an application may perform an occlusion query and a 1085bd8deadSopenharmony_ci timer query simultaneously. An application can not perform multiple 1095bd8deadSopenharmony_ci occlusion queries or multiple timer queries simultaneously. An 1105bd8deadSopenharmony_ci application also can not use the same query object for an occlusion 1115bd8deadSopenharmony_ci query and a timer query simultaneously. 1125bd8deadSopenharmony_ci 1135bd8deadSopenharmony_ci Do query objects have a query type permanently associated with them? 1145bd8deadSopenharmony_ci 1155bd8deadSopenharmony_ci RESOLVED: No. A single query object can be used to perform different 1165bd8deadSopenharmony_ci types of queries, but not at the same time. 1175bd8deadSopenharmony_ci 1185bd8deadSopenharmony_ci Having a fixed type for each query object simplifies some aspects of the 1195bd8deadSopenharmony_ci implementation -- not having to deal with queries with different result 1205bd8deadSopenharmony_ci sizes, for example. It would also mean that BeginQuery() with a query 1215bd8deadSopenharmony_ci object of the "wrong" type would result in an INVALID_OPERATION error. 1225bd8deadSopenharmony_ci 1235bd8deadSopenharmony_ci How predictable/repeatable are the results returned by the timer query? 1245bd8deadSopenharmony_ci 1255bd8deadSopenharmony_ci RESOLVED: In general, the amount of time needed to render the same 1265bd8deadSopenharmony_ci primitives should be fairly constant. But there may be many other 1275bd8deadSopenharmony_ci system issues (e.g., context switching on the CPU and GPU, virtual 1285bd8deadSopenharmony_ci memory page faults, memory cache behavior on the CPU and GPU) that can 1295bd8deadSopenharmony_ci cause times to vary wildly. 1305bd8deadSopenharmony_ci 1315bd8deadSopenharmony_ci Note that modern GPUs are generally highly pipelined, and may be 1325bd8deadSopenharmony_ci processing different primitives in different pipeline stages 1335bd8deadSopenharmony_ci simultaneously. In this extension, the timers start and stop when the 1345bd8deadSopenharmony_ci BeginQuery/EndQuery commands reach the bottom of the rendering pipeline. 1355bd8deadSopenharmony_ci What that means is that by the time the timer starts, the GL driver on 1365bd8deadSopenharmony_ci the CPU may have started work on GL commands issued after BeginQuery, 1375bd8deadSopenharmony_ci and the higher pipeline stages (e.g., vertex transformation) may have 1385bd8deadSopenharmony_ci started as well. 1395bd8deadSopenharmony_ci 1405bd8deadSopenharmony_ci What should the new 64 bit integer type be called? 1415bd8deadSopenharmony_ci 1425bd8deadSopenharmony_ci RESOLVED: The new types will be called GLint64/GLuint64 The new 1435bd8deadSopenharmony_ci command suffixes will be i64 and ui64. These names clearly convey the 1445bd8deadSopenharmony_ci minimum size of the types. These types are similar to the C99 standard 1455bd8deadSopenharmony_ci type int_least64_t, but we use names similar to the C99 optional type 1465bd8deadSopenharmony_ci int64_t for simplicity. 1475bd8deadSopenharmony_ci 1485bd8deadSopenharmony_ci (note: previous versions of EXT_timer_query used GLint64EXT and and 1495bd8deadSopenharmony_ci GLuint64EXT. These types were later promoted to core in OpenGL 3.2, 1505bd8deadSopenharmony_ci and this extension was changed to use the core datatypes for 1515bd8deadSopenharmony_ci compatibility with changes to the OpenGL ES EXT_disjoint_timer_query 1525bd8deadSopenharmony_ci extension, which introduces the same query entry points, and would 1535bd8deadSopenharmony_ci have otherwise have had different function signatures). 1545bd8deadSopenharmony_ci 1555bd8deadSopenharmony_ciNew Procedures and Functions 1565bd8deadSopenharmony_ci 1575bd8deadSopenharmony_ci void GetQueryObjecti64vEXT(uint id, enum pname, int64 *params); 1585bd8deadSopenharmony_ci void GetQueryObjectui64vEXT(uint id, enum pname, uint64 *params); 1595bd8deadSopenharmony_ci 1605bd8deadSopenharmony_ciNew Tokens 1615bd8deadSopenharmony_ci 1625bd8deadSopenharmony_ci Accepted by the <target> parameter of BeginQuery, EndQuery, and 1635bd8deadSopenharmony_ci GetQueryiv: 1645bd8deadSopenharmony_ci 1655bd8deadSopenharmony_ci TIME_ELAPSED_EXT 0x88BF 1665bd8deadSopenharmony_ci 1675bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 2.0 Specification (OpenGL Operation) 1685bd8deadSopenharmony_ci 1695bd8deadSopenharmony_ci (Modify table 2.1, Correspondence of command suffix letters to GL argument 1705bd8deadSopenharmony_ci types, p. 8) Add two new types and suffixes: 1715bd8deadSopenharmony_ci 1725bd8deadSopenharmony_ci Letter Corresponding GL Type 1735bd8deadSopenharmony_ci ------ --------------------- 1745bd8deadSopenharmony_ci i64 int64 1755bd8deadSopenharmony_ci ui64 uint64 1765bd8deadSopenharmony_ci 1775bd8deadSopenharmony_ci (Modify table 2.2, GL data types, p. 9) Add two new types: 1785bd8deadSopenharmony_ci 1795bd8deadSopenharmony_ci Minimum 1805bd8deadSopenharmony_ci GL Type Bit Width Description 1815bd8deadSopenharmony_ci --------- --------- ------------------------------------ 1825bd8deadSopenharmony_ci int64 64 signed 2's complement binary integer 1835bd8deadSopenharmony_ci uint64 64 unsigned binary integer 1845bd8deadSopenharmony_ci 1855bd8deadSopenharmony_ciAdditions to Chapter 3 of the OpenGL 2.0 Specification (Rasterization) 1865bd8deadSopenharmony_ci 1875bd8deadSopenharmony_ci None. 1885bd8deadSopenharmony_ci 1895bd8deadSopenharmony_ciAdditions to Chapter 4 of the OpenGL 2.0 Specification (Per-Fragment 1905bd8deadSopenharmony_ciOperations and the Framebuffer) 1915bd8deadSopenharmony_ci 1925bd8deadSopenharmony_ci (Replace Section 4.1.7, Occlusion Queries, p.204) 1935bd8deadSopenharmony_ci 1945bd8deadSopenharmony_ci Section 4.1.7, Asynchronous Queries 1955bd8deadSopenharmony_ci 1965bd8deadSopenharmony_ci Asynchronous queries provide a mechanism to return information about the 1975bd8deadSopenharmony_ci processing of a sequence of GL commands. There are two query types 1985bd8deadSopenharmony_ci supported by the GL. Occlusion queries (section 4.1.7.1) count the number 1995bd8deadSopenharmony_ci of fragments or samples that pass the depth test. Timer queries (section 2005bd8deadSopenharmony_ci 4.1.12) record the amount of time needed to fully process these commands. 2015bd8deadSopenharmony_ci 2025bd8deadSopenharmony_ci The results of asynchronous queries are not returned by the GL immediately 2035bd8deadSopenharmony_ci after the completion of the last command in the set; subsequent commands 2045bd8deadSopenharmony_ci can be processed while the query results are not complete. When 2055bd8deadSopenharmony_ci available, the query results are stored in an associated query object. 2065bd8deadSopenharmony_ci The commands described in section 6.1.12 provide mechanisms to determine 2075bd8deadSopenharmony_ci when query results are available and return the actual results of the 2085bd8deadSopenharmony_ci query. The name space for query objects is the unsigned integers, with 2095bd8deadSopenharmony_ci zero reserved by the GL. 2105bd8deadSopenharmony_ci 2115bd8deadSopenharmony_ci Each type of query supported by the GL has an active query object name. 2125bd8deadSopenharmony_ci If the active query object name for a query type is non-zero, the GL is 2135bd8deadSopenharmony_ci currently tracking the information corresponding to that query type and 2145bd8deadSopenharmony_ci the query results will be written into the corresponding query object. If 2155bd8deadSopenharmony_ci the active query object for a query type name is zero, no such information 2165bd8deadSopenharmony_ci is being tracked. 2175bd8deadSopenharmony_ci 2185bd8deadSopenharmony_ci A query object is created by calling 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ci void BeginQuery(enum target, uint id); 2215bd8deadSopenharmony_ci 2225bd8deadSopenharmony_ci with an unused name <id>. <target> indicates the type of query to be 2235bd8deadSopenharmony_ci performed; valid values of <target> are defined in subsequent sections. 2245bd8deadSopenharmony_ci When a query object is created, the name <id> is marked as used and 2255bd8deadSopenharmony_ci associated with a new query object. 2265bd8deadSopenharmony_ci 2275bd8deadSopenharmony_ci BeginQuery sets the active query object name for the query type given by 2285bd8deadSopenharmony_ci <target> to <id>. If BeginQuery is called with an <id> of zero, if the 2295bd8deadSopenharmony_ci active query object name for <target> is non-zero, or if <id> is the 2305bd8deadSopenharmony_ci active query object name for any query type, the error INVALID_OPERATION 2315bd8deadSopenharmony_ci is generated. 2325bd8deadSopenharmony_ci 2335bd8deadSopenharmony_ci The command 2345bd8deadSopenharmony_ci 2355bd8deadSopenharmony_ci void EndQuery(enum target); 2365bd8deadSopenharmony_ci 2375bd8deadSopenharmony_ci marks the end of the sequence of commands to be tracked for the query type 2385bd8deadSopenharmony_ci given by <target>. The active query object for <target> is updated to 2395bd8deadSopenharmony_ci indicate that query results are not available, and the active query object 2405bd8deadSopenharmony_ci name for <target> is reset to zero. When the commands issued prior to 2415bd8deadSopenharmony_ci EndQuery have completed and a final query result is available, the query 2425bd8deadSopenharmony_ci object active when EndQuery is called is updated by the GL. The query 2435bd8deadSopenharmony_ci object is updated to indicate that the query results are available and to 2445bd8deadSopenharmony_ci contain the query result. If the active query object name for <target> is 2455bd8deadSopenharmony_ci zero when EndQuery is called, the error INVALID_OPERATION is generated. 2465bd8deadSopenharmony_ci 2475bd8deadSopenharmony_ci The command 2485bd8deadSopenharmony_ci 2495bd8deadSopenharmony_ci void GenQueries(sizei n, uint *ids); 2505bd8deadSopenharmony_ci 2515bd8deadSopenharmony_ci returns <n> previously unused query object names in <ids>. These names are 2525bd8deadSopenharmony_ci marked as used, but no object is associated with them until the first time 2535bd8deadSopenharmony_ci they are used by BeginQuery. 2545bd8deadSopenharmony_ci 2555bd8deadSopenharmony_ci Query objects are deleted by calling 2565bd8deadSopenharmony_ci 2575bd8deadSopenharmony_ci void DeleteQueries(sizei n, const uint *ids); 2585bd8deadSopenharmony_ci 2595bd8deadSopenharmony_ci <ids> contains <n> names of query objects to be deleted. After a query 2605bd8deadSopenharmony_ci object is deleted, its name is again unused. Unused names in <ids> are 2615bd8deadSopenharmony_ci silently ignored. 2625bd8deadSopenharmony_ci 2635bd8deadSopenharmony_ci Calling either GenQueries or DeleteQueries while any query of any target 2645bd8deadSopenharmony_ci is active causes an INVALID_OPERATION error to be generated. 2655bd8deadSopenharmony_ci 2665bd8deadSopenharmony_ci Query objects contain two pieces of state: a single bit indicating 2675bd8deadSopenharmony_ci whether a query result is available, and an integer containing the query 2685bd8deadSopenharmony_ci result value. The number of bits used to represent the query result is 2695bd8deadSopenharmony_ci implementation-dependent. In the initial state of a query object, the 2705bd8deadSopenharmony_ci result is available and its value is zero. 2715bd8deadSopenharmony_ci 2725bd8deadSopenharmony_ci The necessary state for each query type is an unsigned integer holding the 2735bd8deadSopenharmony_ci active query object name (zero if no query object is active), and any 2745bd8deadSopenharmony_ci state necessary to keep the current results of an asynchronous query in 2755bd8deadSopenharmony_ci progress. 2765bd8deadSopenharmony_ci 2775bd8deadSopenharmony_ci Section 4.1.7.1, Occlusion Queries 2785bd8deadSopenharmony_ci 2795bd8deadSopenharmony_ci Occlusion queries use query objects to track the number of fragments or 2805bd8deadSopenharmony_ci samples that pass the depth test. An occlusion query can be started and 2815bd8deadSopenharmony_ci finished by calling BeginQuery and EndQuery, respectively, with a <target> 2825bd8deadSopenharmony_ci of SAMPLES_PASSED. 2835bd8deadSopenharmony_ci 2845bd8deadSopenharmony_ci When an occlusion query starts, the samples-passed count maintained by the 2855bd8deadSopenharmony_ci GL is set to zero. When an occlusion query is active, the samples-passed 2865bd8deadSopenharmony_ci count is incremented for each fragment that passes the depth test. If the 2875bd8deadSopenharmony_ci value of SAMPLE BUFFERS is 0, then the samples-passed count is incremented 2885bd8deadSopenharmony_ci by 1 for each fragment. If the value of SAMPLE BUFFERS is 1, then the 2895bd8deadSopenharmony_ci samples-passed count is incremented by the number of samples whose 2905bd8deadSopenharmony_ci coverage bit is set. However, implementations, at their discretion, may 2915bd8deadSopenharmony_ci instead increase the samples-passed count by the value of SAMPLES if any 2925bd8deadSopenharmony_ci sample in the fragment is covered. When an occlusion query finishes and 2935bd8deadSopenharmony_ci all fragments generated by the commands issued prior to EndQuery have been 2945bd8deadSopenharmony_ci generated, the samples-passed count is written to the corresponding query 2955bd8deadSopenharmony_ci object as the query result value, and the query result for that object is 2965bd8deadSopenharmony_ci marked as available. 2975bd8deadSopenharmony_ci 2985bd8deadSopenharmony_ci If the samples-passed count overflows, (i.e., exceeds the value 2^n - 1, 2995bd8deadSopenharmony_ci where n is the number of bits in the samples-passed count), its value 3005bd8deadSopenharmony_ci becomes undefined. It is recommended, but not required, that 3015bd8deadSopenharmony_ci implementations handle this overflow case by saturating at 2^n - 1 and 3025bd8deadSopenharmony_ci incrementing no further. 3035bd8deadSopenharmony_ci 3045bd8deadSopenharmony_ci (Add new Section 4.1.12, Timer Queries, p.212) 3055bd8deadSopenharmony_ci 3065bd8deadSopenharmony_ci Timer queries use query objects (section 4.1.7) to track the amount of 3075bd8deadSopenharmony_ci time needed to fully complete a set of GL commands. A timer query can be 3085bd8deadSopenharmony_ci started and finished by calling BeginQuery and EndQuery, respectively, 3095bd8deadSopenharmony_ci with a <target> of TIME_ELAPSED_EXT. 3105bd8deadSopenharmony_ci 3115bd8deadSopenharmony_ci When BeginQuery and EndQuery are called with a <target> of 3125bd8deadSopenharmony_ci TIME_ELAPSED_EXT, the GL prepares to start and stop the timer used for 3135bd8deadSopenharmony_ci timer queries. The timer is started or stopped when the effects from all 3145bd8deadSopenharmony_ci previous commands on the GL client and server state and the framebuffer 3155bd8deadSopenharmony_ci have been fully realized. The BeginQuery and EndQuery commands may return 3165bd8deadSopenharmony_ci before the timer is actually started or stopped. When the timer query 3175bd8deadSopenharmony_ci timer is finally stopped, the elapsed time (in nanoseconds) is written to 3185bd8deadSopenharmony_ci the corresponding query object as the query result value, and the query 3195bd8deadSopenharmony_ci result for that object is marked as available. 3205bd8deadSopenharmony_ci 3215bd8deadSopenharmony_ci If the elapsed time overflows the number of bits, <n>, available to hold 3225bd8deadSopenharmony_ci elapsed time, its value becomes undefined. It is recommended, but not 3235bd8deadSopenharmony_ci required, that implementations handle this overflow case by saturating at 3245bd8deadSopenharmony_ci 2^n - 1. 3255bd8deadSopenharmony_ci 3265bd8deadSopenharmony_ciAdditions to Chapter 5 of the OpenGL 2.0 Specification (Special Functions) 3275bd8deadSopenharmony_ci 3285bd8deadSopenharmony_ci None. 3295bd8deadSopenharmony_ci 3305bd8deadSopenharmony_ciAdditions to Chapter 6 of the OpenGL 2.0 Specification (State and State 3315bd8deadSopenharmony_ciRequests) 3325bd8deadSopenharmony_ci 3335bd8deadSopenharmony_ci (Replace Section 6.1.12, Occlusion Queries, p. 254) 3345bd8deadSopenharmony_ci 3355bd8deadSopenharmony_ci Section 6.1.12, Asynchronous Queries 3365bd8deadSopenharmony_ci 3375bd8deadSopenharmony_ci The command 3385bd8deadSopenharmony_ci 3395bd8deadSopenharmony_ci boolean IsQuery(uint id); 3405bd8deadSopenharmony_ci 3415bd8deadSopenharmony_ci returns TRUE if <id> is the name of a query object. If <id> is zero, or if 3425bd8deadSopenharmony_ci <id> is a non-zero value that is not the name of a query object, IsQuery 3435bd8deadSopenharmony_ci returns FALSE. 3445bd8deadSopenharmony_ci 3455bd8deadSopenharmony_ci Information about a query target can be queried with the command 3465bd8deadSopenharmony_ci 3475bd8deadSopenharmony_ci void GetQueryiv(enum target, enum pname, int *params); 3485bd8deadSopenharmony_ci 3495bd8deadSopenharmony_ci <target> identifies the query target and can be SAMPLES_PASSED for 3505bd8deadSopenharmony_ci occlusion queries or TIME_ELAPSED_EXT for timer queries. 3515bd8deadSopenharmony_ci 3525bd8deadSopenharmony_ci If <pname> is CURRENT_QUERY, the name of the currently active query for 3535bd8deadSopenharmony_ci <target>, or zero if no query is active, will be placed in <params>. 3545bd8deadSopenharmony_ci 3555bd8deadSopenharmony_ci If <pname> is QUERY_COUNTER_BITS, the implementation-dependent number of 3565bd8deadSopenharmony_ci bits used to hold the query result for <target> will be placed in params. 3575bd8deadSopenharmony_ci The number of query counter bits may be zero, in which case the counter 3585bd8deadSopenharmony_ci contains no useful information. 3595bd8deadSopenharmony_ci 3605bd8deadSopenharmony_ci For occlusion queries (SAMPLES_PASSED), if the number of bits is non-zero, 3615bd8deadSopenharmony_ci the minimum number of bits allowed is a function of the implementation's 3625bd8deadSopenharmony_ci maximum viewport dimensions (MAX_VIEWPORT_DIMS). The counter must be able 3635bd8deadSopenharmony_ci to represent at least two overdraws for every pixel in the viewport. The 3645bd8deadSopenharmony_ci formula to compute the allowable minimum value (where n is the minimum 3655bd8deadSopenharmony_ci number of bits) is: 3665bd8deadSopenharmony_ci 3675bd8deadSopenharmony_ci n = min(32, ceil(log_2(maxViewportWidth * maxViewportHeight * 2))). 3685bd8deadSopenharmony_ci 3695bd8deadSopenharmony_ci For timer queries (TIME_ELAPSED_EXT), if the minimum number if bits is 3705bd8deadSopenharmony_ci non-zero, it must be at least 30. 3715bd8deadSopenharmony_ci 3725bd8deadSopenharmony_ci The state of a query object can be queried with the commands 3735bd8deadSopenharmony_ci 3745bd8deadSopenharmony_ci void GetQueryObjectiv(uint id, enum pname, int *params); 3755bd8deadSopenharmony_ci void GetQueryObjectuiv(uint id, enum pname, uint *params); 3765bd8deadSopenharmony_ci void GetQueryObjecti64vEXT(uint id, enum pname, int64 *params); 3775bd8deadSopenharmony_ci void GetQueryObjectui64vEXT(uint id, enum pname, uint64 *params); 3785bd8deadSopenharmony_ci If <id> is not the name of a query object, or if the query object named by 3795bd8deadSopenharmony_ci <id> is currently active, then an INVALID_OPERATION error is generated. 3805bd8deadSopenharmony_ci 3815bd8deadSopenharmony_ci If <pname> is QUERY_RESULT, then the query object's result value is 3825bd8deadSopenharmony_ci returned as a single integer in <params>. If the value is so large in 3835bd8deadSopenharmony_ci magnitude that it cannot be represented with the requested type, then the 3845bd8deadSopenharmony_ci nearest value representable using the requested type is returned. If the 3855bd8deadSopenharmony_ci number of query counter bits for any <target> is zero, then the result is 3865bd8deadSopenharmony_ci returned as a single integer with a value of 0. 3875bd8deadSopenharmony_ci 3885bd8deadSopenharmony_ci There may be an indeterminate delay before the above query returns. If 3895bd8deadSopenharmony_ci <pname> is QUERY_RESULT_AVAILABLE, FALSE is returned if such a delay would 3905bd8deadSopenharmony_ci be required, TRUE is returned otherwise. It must always be true that if 3915bd8deadSopenharmony_ci any query object returns a result available of TRUE, all queries of the 3925bd8deadSopenharmony_ci same type issued prior to that query must also return TRUE. 3935bd8deadSopenharmony_ci 3945bd8deadSopenharmony_ci Querying the state for any given query object forces the corresponding 3955bd8deadSopenharmony_ci query to complete within a finite amount of time. 3965bd8deadSopenharmony_ci 3975bd8deadSopenharmony_ci If multiple queries are issued using the same object name prior to calling 3985bd8deadSopenharmony_ci GetQueryObject[u]iv, the result and availability information returned will 3995bd8deadSopenharmony_ci always be from the last query issued. The results from any queries before 4005bd8deadSopenharmony_ci the last one will be lost if they are not retrieved before starting a new 4015bd8deadSopenharmony_ci query on the same <target> and <id>. 4025bd8deadSopenharmony_ci 4035bd8deadSopenharmony_ciGLX Protocol (Modification to the GLX 1.3 Protocol Encoding Specification) 4045bd8deadSopenharmony_ci 4055bd8deadSopenharmony_ci Add to Section 1.4 (p.2), Common Types 4065bd8deadSopenharmony_ci 4075bd8deadSopenharmony_ci INT64 A 64-bit signed integer value. 4085bd8deadSopenharmony_ci 4095bd8deadSopenharmony_ci CARD64 A 64-bit unsigned integer value. 4105bd8deadSopenharmony_ci 4115bd8deadSopenharmony_ci Two new non-rendering GL commands are added. These commands are sent 4125bd8deadSopenharmony_ci seperately (i.e., not as part of a glXRender or glXRenderLarge request), 4135bd8deadSopenharmony_ci using the glXVendorPrivateWithReply request: 4145bd8deadSopenharmony_ci 4155bd8deadSopenharmony_ci GetQueryObjecti64vEXT 4165bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 4175bd8deadSopenharmony_ci 1 1328 GLX opcode (glXVendorPrivateWithReply) 4185bd8deadSopenharmony_ci 2 4 request length 4195bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 4205bd8deadSopenharmony_ci 4 CARD32 id 4215bd8deadSopenharmony_ci 4 ENUM pname 4225bd8deadSopenharmony_ci => 4235bd8deadSopenharmony_ci 1 1 reply 4245bd8deadSopenharmony_ci 1 unused 4255bd8deadSopenharmony_ci 2 CARD16 sequence number 4265bd8deadSopenharmony_ci 4 m reply length, m=(n==1?0:n) 4275bd8deadSopenharmony_ci 4 unused 4285bd8deadSopenharmony_ci 4 CARD32 n 4295bd8deadSopenharmony_ci 4305bd8deadSopenharmony_ci if (n=1) this follows: 4315bd8deadSopenharmony_ci 4325bd8deadSopenharmony_ci 8 INT64 params 4335bd8deadSopenharmony_ci 8 unused 4345bd8deadSopenharmony_ci 4355bd8deadSopenharmony_ci otherwise this follows: 4365bd8deadSopenharmony_ci 4375bd8deadSopenharmony_ci 16 unused 4385bd8deadSopenharmony_ci n*8 LISTofINT64 params 4395bd8deadSopenharmony_ci 4405bd8deadSopenharmony_ci GetQueryObjectui64vEXT 4415bd8deadSopenharmony_ci 1 CARD8 opcode (X assigned) 4425bd8deadSopenharmony_ci 1 1329 GLX opcode (glXVendorPrivateWithReply) 4435bd8deadSopenharmony_ci 2 4 request length 4445bd8deadSopenharmony_ci 4 GLX_CONTEXT_TAG context tag 4455bd8deadSopenharmony_ci 4 CARD32 id 4465bd8deadSopenharmony_ci 4 ENUM pname 4475bd8deadSopenharmony_ci => 4485bd8deadSopenharmony_ci 1 1 reply 4495bd8deadSopenharmony_ci 1 unused 4505bd8deadSopenharmony_ci 2 CARD16 sequence number 4515bd8deadSopenharmony_ci 4 m reply length, m=(n==1?0:n) 4525bd8deadSopenharmony_ci 4 unused 4535bd8deadSopenharmony_ci 4 CARD32 n 4545bd8deadSopenharmony_ci 4555bd8deadSopenharmony_ci if (n=1) this follows: 4565bd8deadSopenharmony_ci 4575bd8deadSopenharmony_ci 8 CARD64 params 4585bd8deadSopenharmony_ci 8 unused 4595bd8deadSopenharmony_ci 4605bd8deadSopenharmony_ci otherwise this follows: 4615bd8deadSopenharmony_ci 4625bd8deadSopenharmony_ci 16 unused 4635bd8deadSopenharmony_ci n*8 CARD64 params 4645bd8deadSopenharmony_ci 4655bd8deadSopenharmony_ciErrors 4665bd8deadSopenharmony_ci 4675bd8deadSopenharmony_ci All existing errors for query objects apply unchanged from the 4685bd8deadSopenharmony_ci ARB_occlusion_query spec, except the modification below: 4695bd8deadSopenharmony_ci 4705bd8deadSopenharmony_ci The error INVALID_ENUM is generated if BeginQueryARB, EndQueryARB, or 4715bd8deadSopenharmony_ci GetQueryivARB is called where <target> is not SAMPLES_PASSED or 4725bd8deadSopenharmony_ci TIME_ELAPSED_EXT. 4735bd8deadSopenharmony_ci 4745bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if GetQueryObjecti64vEXT or 4755bd8deadSopenharmony_ci GetQueryObjectui64vEXT is called where <id> is not the name of a query 4765bd8deadSopenharmony_ci object. 4775bd8deadSopenharmony_ci 4785bd8deadSopenharmony_ci The error INVALID_OPERATION is generated if GetQueryObjecti64vEXT or 4795bd8deadSopenharmony_ci GetQueryObjectui64vEXT is called where <id> is the name of a currently 4805bd8deadSopenharmony_ci active query object. 4815bd8deadSopenharmony_ci 4825bd8deadSopenharmony_ci The error INVALID_ENUM is generated if GetQueryObjecti64vEXT or 4835bd8deadSopenharmony_ci GetQueryObjectui64vEXT is called where <pname> is not QUERY_RESULT or 4845bd8deadSopenharmony_ci QUERY_RESULT_AVAILABLE. 4855bd8deadSopenharmony_ci 4865bd8deadSopenharmony_ciNew State 4875bd8deadSopenharmony_ci 4885bd8deadSopenharmony_ci (table 6.37, p 298) Update the occlusion query / query object state to 4895bd8deadSopenharmony_ci cover timer queries: 4905bd8deadSopenharmony_ci 4915bd8deadSopenharmony_ci Get Value Type Get Command Init. Value Description Sec Attribute 4925bd8deadSopenharmony_ci ---------------------- ---- ---------------- ----------- ------------------------- ----- --------- 4935bd8deadSopenharmony_ci CURRENT_QUERY 2xZ+ GetQueryiv 0 Active query object name 4.1.7 - 4945bd8deadSopenharmony_ci (occlusion and timer) 4955bd8deadSopenharmony_ci QUERY_RESULT 2xZ+ GetQueryObjectiv 0 Query object result 4.1.7 - 4965bd8deadSopenharmony_ci (samples passed or 4975bd8deadSopenharmony_ci time elapsed) 4985bd8deadSopenharmony_ci QUERY_RESULT_AVAILABLE 2xB GetQueryObjectiv TRUE Query object result 4.1.7 - 4995bd8deadSopenharmony_ci available? 5005bd8deadSopenharmony_ci 5015bd8deadSopenharmony_ciNew Implementation Dependent State 5025bd8deadSopenharmony_ci 5035bd8deadSopenharmony_ci (table 6.34, p. 295) Update the occlusion query / query object state to 5045bd8deadSopenharmony_ci cover timer queries: 5055bd8deadSopenharmony_ci 5065bd8deadSopenharmony_ci Get Value Type Get Command Minimum Value Description Sec Attribute 5075bd8deadSopenharmony_ci -------------------- ---- ----------- ------------- -------------------------- ------ --------- 5085bd8deadSopenharmony_ci QUERY_COUNTER_BITS 2xZ+ GetQueryiv see 6.1.12 Asynchronous query counter 6.1.12 - 5095bd8deadSopenharmony_ci bits (occlusion and timer 5105bd8deadSopenharmony_ci queries) 5115bd8deadSopenharmony_ci 5125bd8deadSopenharmony_ciDependencies on ARB_occlusion_query and NV_occlusion_query 5135bd8deadSopenharmony_ci 5145bd8deadSopenharmony_ci If ARB_occlusion_query or NV_occlusion_query is supported, the previous 5155bd8deadSopenharmony_ci spec edits are considered to apply to the nearly identical language in 5165bd8deadSopenharmony_ci these extension specifications. Note that the functionality provided by 5175bd8deadSopenharmony_ci these extensions is included in OpenGL versions 1.5 and greater. 5185bd8deadSopenharmony_ci 5195bd8deadSopenharmony_ciUsage Examples 5205bd8deadSopenharmony_ci 5215bd8deadSopenharmony_ci Here is some rough sample code that demonstrates the intended usage 5225bd8deadSopenharmony_ci of this extension. 5235bd8deadSopenharmony_ci 5245bd8deadSopenharmony_ci GLint queries[N]; 5255bd8deadSopenharmony_ci GLint available = 0; 5265bd8deadSopenharmony_ci // timer queries can contain more than 32 bits of data, so always 5275bd8deadSopenharmony_ci // query them using the 64 bit types to avoid overflow 5285bd8deadSopenharmony_ci GLuint64 timeElapsed = 0; 5295bd8deadSopenharmony_ci 5305bd8deadSopenharmony_ci // Create a query object. 5315bd8deadSopenharmony_ci glGenQueries(N, queries); 5325bd8deadSopenharmony_ci 5335bd8deadSopenharmony_ci // Start query 1 5345bd8deadSopenharmony_ci glBeginQuery(GL_TIME_ELAPSED_EXT, queries[0]); 5355bd8deadSopenharmony_ci 5365bd8deadSopenharmony_ci // Draw object 1 5375bd8deadSopenharmony_ci .... 5385bd8deadSopenharmony_ci 5395bd8deadSopenharmony_ci // End query 1 5405bd8deadSopenharmony_ci glEndQuery(GL_TIME_ELAPSED_EXT); 5415bd8deadSopenharmony_ci 5425bd8deadSopenharmony_ci ... 5435bd8deadSopenharmony_ci 5445bd8deadSopenharmony_ci // Start query N 5455bd8deadSopenharmony_ci glBeginQuery(GL_TIME_ELAPSED_EXT, queries[N-1]); 5465bd8deadSopenharmony_ci 5475bd8deadSopenharmony_ci // Draw object N 5485bd8deadSopenharmony_ci .... 5495bd8deadSopenharmony_ci 5505bd8deadSopenharmony_ci // End query N 5515bd8deadSopenharmony_ci glEndQuery(GL_TIME_ELAPSED_EXT); 5525bd8deadSopenharmony_ci 5535bd8deadSopenharmony_ci // Wait for all results to become available 5545bd8deadSopenharmony_ci while (!available) { 5555bd8deadSopenharmony_ci glGetQueryObjectiv(queries[N-1], GL_QUERY_RESULT_AVAILABLE, &available); 5565bd8deadSopenharmony_ci } 5575bd8deadSopenharmony_ci 5585bd8deadSopenharmony_ci for (i = 0; i < N; i++) { 5595bd8deadSopenharmony_ci // See how much time the rendering of object i took in nanoseconds. 5605bd8deadSopenharmony_ci glGetQueryObjectui64vEXT(queries[i], GL_QUERY_RESULT, &timeElapsed); 5615bd8deadSopenharmony_ci 5625bd8deadSopenharmony_ci // Do something useful with the time. Note that care should be 5635bd8deadSopenharmony_ci // taken to use all significant bits of the result, not just the 5645bd8deadSopenharmony_ci // least significant 32 bits. 5655bd8deadSopenharmony_ci AdjustObjectLODBasedOnDrawTime(i, timeElapsed); 5665bd8deadSopenharmony_ci } 5675bd8deadSopenharmony_ci 5685bd8deadSopenharmony_ci This example is sub-optimal in that it stalls at the end of every 5695bd8deadSopenharmony_ci frame to wait for query results. Ideally, the collection of results 5705bd8deadSopenharmony_ci would be delayed one frame to minimize the amount of time spent 5715bd8deadSopenharmony_ci waiting for the GPU to finish rendering. 5725bd8deadSopenharmony_ci 5735bd8deadSopenharmony_ciRevision History 5745bd8deadSopenharmony_ci 5755bd8deadSopenharmony_ci Version 3, June 25, 2013 (Jon Leech) - replace int64EXT / uint64EXT with 5765bd8deadSopenharmony_ci core int64/uint64 types, for compatibility with EXT_disjoint_timer_query 5775bd8deadSopenharmony_ci (Bug 10449). 578