109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulName
209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    MESA_swap_frame_usage
409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulName Strings
609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_MESA_swap_frame_usage
809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulContact
1009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
11c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul    Ian Romanick, IBM, idr at us.ibm.com
1209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
1309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulStatus
1409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
1509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    Deployed in DRI drivers post-XFree86 4.3.
1609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
1709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulVersion
1809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
19c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul    Date: 5/1/2003   Revision: 1.1
2009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
2109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulNumber
2209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
2309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    ???
2409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
2509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulDependencies
2609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
2709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_SGI_swap_control affects the definition of this extension.
2809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_MESA_swap_control affects the definition of this extension.
2909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_OML_sync_control affects the definition of this extension.
3009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
3109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    Based on WGL_I3D_swap_frame_usage version 1.3.
3209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
3309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulOverview
3409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
356e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    This extension allows an application to determine what portion of the
3609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    swap period has elapsed since the last swap operation completed.  The
3709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    "usage" value is a floating point value on the range [0,max] which is
3809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    calculated as follows:
3909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
4009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                              td
4109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                   percent = ----
4209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                              tf
4309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
4409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    where td is the time measured from the last completed buffer swap (or
4509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    call to enable the statistic) to when the next buffer swap completes, tf
4609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    is the entire time for a frame which may be multiple screen refreshes
4709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    depending on the swap interval as set by the GLX_SGI_swap_control or
4809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_OML_sync_control extensions. 
4909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
5009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    The value, percent, indicates the amount of time spent between the
5109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    completion of the two swaps.  If the value is in the range [0,1], the
5209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    buffer swap occurred within the time period required to maintain a
5309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    constant frame rate.  If the value is in the range (1,max], a constant
5409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    frame rate was not achieved.  The value indicates the number of frames
5509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    required to draw.
5609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
5709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    This definition of "percent" differs slightly from
5809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    WGL_I3D_swap_frame_usage.  In WGL_I3D_swap_frame_usage, the measurement
5909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    is taken from the completion of one swap to the issuance of the next.
6009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    This representation may not be as useful as measuring between
6109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    completions, as a significant amount of time may pass between the
626e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    issuance of a swap and the swap actually occurring.
6309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
6409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    There is also a mechanism to determine whether a frame swap was
6509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    missed.
6609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
6709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulNew Procedures and Functions
6809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
6909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    int glXGetFrameUsageMESA(Display *dpy,
7009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                             GLXDrawable drawable,
7109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    	                     float *usage)
7209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
7309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    int glXBeginFrameTrackingMESA(Display *dpy,
7409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                  GLXDrawable drawable)
7509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
7609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    int glXEndFrameTrackingMESA(Display *dpy,
7709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                GLXDrawable drawable)
7809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
7909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    int glXQueryFrameTrackingMESA(Display *dpy,
8009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                  GLXDrawable drawable,
8109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul				  int64_t *swapCount,
8209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                  int64_t *missedFrames,
8309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                  float *lastMissedUsage)
8409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
8509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulNew Tokens
8609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
8709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
8809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
8909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to Chapter 2 of the 1.4 GL Specification (OpenGL Operation)
9009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
9109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
9209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
9309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to Chapter 3 of the 1.4 GL Specification (Rasterization)
9409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
9509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
9609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
9709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to Chapter 4 of the 1.4 GL Specification (Per-Fragment Operations
9809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Pauland the Framebuffer)
9909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
10009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
10109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
10209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to Chapter 5 of the 1.4 GL Specification (Special Functions)
10309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
10409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
10509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
10609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to Chapter 6 of the 1.4 GL Specification (State and State Requests)
10709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
10809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
10909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
11009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulAdditions to the GLX 1.3 Specification
11109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
11209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    The frame usage is measured as the percentage of the swap period elapsed
1136e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    between two buffer-swap operations being committed.  In unextended GLX the
11409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    swap period is the vertical refresh time.  If SGI_swap_control or
11509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    MESA_swap_control are supported, the swap period is the vertical refresh
11609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    time multiplied by the swap interval (or one if the swap interval is set
11709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    to zero).
11809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    
11909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    If OML_sync_control is supported, the swap period is the vertical
12009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    refresh time multiplied by the divisor parameter to
12109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    glXSwapBuffersMscOML.  The frame usage in this case is less than 1.0 if
1226e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    the swap is committed before target_msc, and is greater than or equal to
12309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    1.0 otherwise.  The actual usage value is based on the divisor and is
12409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    never less than 0.0.
12509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
12609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       int glXBeginFrameTrackingMESA(Display *dpy,
12709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                     GLXDrawable drawable,
12809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul				     float *usage)
12909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
13009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    glXGetFrameUsageMESA returns a floating-point value in <usage>
13109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    that represents the current swap usage, as defined above.
13209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
13309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    Missed frame swaps can be tracked by calling the following function:
13409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
13509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       int glXBeginFrameTrackingMESA(Display *dpy,
13609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                     GLXDrawable drawable)
13709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
13809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    glXBeginFrameTrackingMESA resets a "missed frame" count and
13909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    synchronizes with the next frame vertical sync before it returns.
14009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    If a swap is missed based in the rate control specified by the
14109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    <interval> set by glXSwapIntervalSGI or the default swap of once
14209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    per frame, the missed frame count is incremented.
14309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
14409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    The current missed frame count and total number of swaps since
14509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    the last call to glXBeginFrameTrackingMESA can be obtained by
1466e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    calling the following function:
14709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
14809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       int glXQueryFrameTrackingMESA(Display *dpy,
14909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                     GLXDrawable drawable,
15009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul				     int64_t *swapCount,
15109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                     int64_t *missedFrames,
15209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                     float *lastMissedUsage)
15309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
15409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    The location pointed to by <swapCount> will be updated with the
1556e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    number of swaps that have been committed.  This value may not match the
15609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    number of swaps that have been requested since swaps may be
15709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    queued by the implementation.  This function can be called at any
15809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    time and does not synchronize to vertical blank.
15909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
16009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    The location pointed to by <missedFrames> will contain the number
16109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    swaps that missed the specified frame.  The frame usage for the
16209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    last missed frame is returned in the location pointed to by
16309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    <lastMissedUsage>.
16409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
16509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    Frame tracking is disabled by calling the function
16609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
16709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       int glXEndFrameTrackingMESA(Display *dpy,
16809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul                                   GLXDrawable drawable)
16909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
17009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    This function will not return until all swaps have occurred.  The
17109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    application can call glXQueryFrameTrackingMESA for a final swap and
17209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    missed frame count.
17309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
1746e2ab82f5c2bc41c1dcb146c0fe9606f3bfe4eb1Ian Romanick    If these functions are successful, zero is returned.  If the context
17509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    associated with dpy and drawable is not a direct context,
17609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    GLX_BAD_CONTEXT is returned.
17709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
17809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulErrors
17909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
18009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    If the function succeeds, zero is returned.  If the function
18109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    fails, one of the following error codes is returned:
18209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
18309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       GLX_BAD_CONTEXT         The current rendering context is not a direct
18409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul       			       context.
18509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
18609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulGLX Protocol
18709b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
18809b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None.  This extension only extends to direct rendering contexts.
18909b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
19009b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulNew State
19109b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
19209b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
19309b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
19409b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian PaulNew Implementation Dependent State
19509b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul
19609b00c5ded8e6211c9c79be600bb8c8ecad0d8fcBrian Paul    None
197c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul
198c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian PaulRevision History
199c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul
200c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul    1.1,  5/1/03   Added contact information.
201c784d87b0f07590a2bb87307ca6a264b2ec99b31Brian Paul    1.0,  3/17/03  Initial version based on WGL_I3D_swap_frame_usage.
202