15df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulName
25df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
35df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    MESA_swap_frame_usage
45df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
55df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulName Strings
65df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
75df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_MESA_swap_frame_usage
85df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
95df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulContact
105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Ian Romanick, IBM, idr at us.ibm.com
125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulStatus
145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Deployed in DRI drivers post-XFree86 4.3.
165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulVersion
185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Date: 5/1/2003   Revision: 1.1
205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulNumber
225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    ???
245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulDependencies
265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_SGI_swap_control affects the definition of this extension.
285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_MESA_swap_control affects the definition of this extension.
295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_OML_sync_control affects the definition of this extension.
305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Based on WGL_I3D_swap_frame_usage version 1.3.
325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulOverview
345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
35ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul    This extension allows an application to determine what portion of the
36ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul    swap period has elapsed since the last swap operation completed.  The
37ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul    "usage" value is a floating point value on the range [0,max] which is
38ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul    calculated as follows:
39ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul
40ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul                              td
41ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul                   percent = ----
4247941bfaea6e8a60e2c31f7a2c8c233f2a10ecb1Brian Paul                              tf
43bbf2b5c4ffcb6755d34a5b698445aecf604e45fbPauli Nieminen
44decc6e2a32ef49e673c081f30e19b8970155d887Brian Paul    where td is the time measured from the last completed buffer swap (or
455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    call to enable the statistic) to when the next buffer swap completes, tf
4680c88304fc9d09531b2530b74973821e47b46753Keith Whitwell    is the entire time for a frame which may be multiple screen refreshes
475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    depending on the swap interval as set by the GLX_SGI_swap_control or
485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_OML_sync_control extensions. 
495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
50e167403e5809c447870644bd9ea09fad369706cfAlex Deucher    The value, percent, indicates the amount of time spent between the
515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    completion of the two swaps.  If the value is in the range [0,1], the
525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    buffer swap occurred within the time period required to maintain a
5305304d41f2d9ab7a66a8b976580c156b7b93a9d3Dave Airlie    constant frame rate.  If the value is in the range (1,max], a constant
545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    frame rate was not achieved.  The value indicates the number of frames
555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    required to draw.
565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    This definition of "percent" differs slightly from
585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    WGL_I3D_swap_frame_usage.  In WGL_I3D_swap_frame_usage, the measurement
595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    is taken from the completion of one swap to the issuance of the next.
60f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg    This representation may not be as useful as measuring between
612d61d301171620efe624d83a5457f4094eb49cbaRoland Scheidegger    completions, as a significant amount of time may pass between the
625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    issuance of a swap and the swap actually occurring.
635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    There is also a mechanism to determine whether a frame swap was
655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    missed.
66f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg
675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulNew Procedures and Functions
684637235183b80963536f2364e4d50fcb894886ddDave Airlie
695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    int glXGetFrameUsageMESA(Display *dpy,
705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                             GLXDrawable drawable,
715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    	                     float *usage)
725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    int glXBeginFrameTrackingMESA(Display *dpy,
745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                  GLXDrawable drawable)
755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    int glXEndFrameTrackingMESA(Display *dpy,
775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                GLXDrawable drawable)
785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    int glXQueryFrameTrackingMESA(Display *dpy,
805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                  GLXDrawable drawable,
815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				  int64_t *swapCount,
825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                  int64_t *missedFrames,
835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                  float *lastMissedUsage)
845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulNew Tokens
865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulAdditions to Chapter 2 of the 1.4 GL Specification (OpenGL Operation)
905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulAdditions to Chapter 3 of the 1.4 GL Specification (Rasterization)
945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulAdditions to Chapter 4 of the 1.4 GL Specification (Per-Fragment Operations
985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Pauland the Framebuffer)
995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
1015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulAdditions to Chapter 5 of the 1.4 GL Specification (Special Functions)
1035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
1055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulAdditions to Chapter 6 of the 1.4 GL Specification (State and State Requests)
1075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
109f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg
110c93105eb9e2499efb237fd89dba0cebd48f18375Ian RomanickAdditions to the GLX 1.3 Specification
1115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1124637235183b80963536f2364e4d50fcb894886ddDave Airlie    The frame usage is measured as the percentage of the swap period elapsed
1135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    between two buffer-swap operations being committed.  In unextended GLX the
1145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    swap period is the vertical refresh time.  If SGI_swap_control or
1155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    MESA_swap_control are supported, the swap period is the vertical refresh
116c93105eb9e2499efb237fd89dba0cebd48f18375Ian Romanick    time multiplied by the swap interval (or one if the swap interval is set
117c93105eb9e2499efb237fd89dba0cebd48f18375Ian Romanick    to zero).
118c93105eb9e2499efb237fd89dba0cebd48f18375Ian Romanick    
1195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    If OML_sync_control is supported, the swap period is the vertical
1205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    refresh time multiplied by the divisor parameter to
1215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    glXSwapBuffersMscOML.  The frame usage in this case is less than 1.0 if
1225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    the swap is committed before target_msc, and is greater than or equal to
1235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    1.0 otherwise.  The actual usage value is based on the divisor and is
1245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    never less than 0.0.
1255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       int glXBeginFrameTrackingMESA(Display *dpy,
1275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                     GLXDrawable drawable,
1285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     float *usage)
1295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    glXGetFrameUsageMESA returns a floating-point value in <usage>
1315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    that represents the current swap usage, as defined above.
1325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Missed frame swaps can be tracked by calling the following function:
1345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       int glXBeginFrameTrackingMESA(Display *dpy,
1365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                     GLXDrawable drawable)
1375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    glXBeginFrameTrackingMESA resets a "missed frame" count and
1395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    synchronizes with the next frame vertical sync before it returns.
140888b1a9166abfb1b2873cf7c1eb2daf45a26c84fRoland Scheidegger    If a swap is missed based in the rate control specified by the
14174713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul    <interval> set by glXSwapIntervalSGI or the default swap of once
1425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    per frame, the missed frame count is incremented.
1435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    The current missed frame count and total number of swaps since
1455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    the last call to glXBeginFrameTrackingMESA can be obtained by
1465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    calling the following function:
1475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       int glXQueryFrameTrackingMESA(Display *dpy,
149f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg                                     GLXDrawable drawable,
15020a17e42d7fc9fe65aabe612fe1e513c3103d121Ian Romanick				     int64_t *swapCount,
15120a17e42d7fc9fe65aabe612fe1e513c3103d121Ian Romanick                                     int64_t *missedFrames,
1525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                     float *lastMissedUsage)
1534637235183b80963536f2364e4d50fcb894886ddDave Airlie
1547dd184dc4da37233471875df6f40cce0560cb7bcNicolai Hähnle    The location pointed to by <swapCount> will be updated with the
1555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    number of swaps that have been committed.  This value may not match the
1565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    number of swaps that have been requested since swaps may be
1575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    queued by the implementation.  This function can be called at any
15874713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul    time and does not synchronize to vertical blank.
1595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    The location pointed to by <missedFrames> will contain the number
1615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    swaps that missed the specified frame.  The frame usage for the
1625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    last missed frame is returned in the location pointed to by
1635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    <lastMissedUsage>.
1645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    Frame tracking is disabled by calling the function
1665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       int glXEndFrameTrackingMESA(Display *dpy,
1685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul                                   GLXDrawable drawable)
1695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    This function will not return until all swaps have occurred.  The
1715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    application can call glXQueryFrameTrackingMESA for a final swap and
1725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    missed frame count.
1735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    If these functions are successful, zero is returned.  If the context
1755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    associated with dpy and drawable is not a direct context,
1765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    GLX_BAD_CONTEXT is returned.
1775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulErrors
1795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    If the function succeeds, zero is returned.  If the function
1815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    fails, one of the following error codes is returned:
1825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       GLX_BAD_CONTEXT         The current rendering context is not a direct
1845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       			       context.
1855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulGLX Protocol
1875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None.  This extension only extends to direct rendering contexts.
1895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulNew State
1915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
1935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulNew Implementation Dependent State
1955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    None
1975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian PaulRevision History
1995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    1.1,  5/1/03   Added contact information.
2015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    1.0,  3/17/03  Initial version based on WGL_I3D_swap_frame_usage.
2025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul