1848b8605SmrgName
2848b8605Smrg
3848b8605Smrg    MESA_swap_frame_usage
4848b8605Smrg
5848b8605SmrgName Strings
6848b8605Smrg
7848b8605Smrg    GLX_MESA_swap_frame_usage
8848b8605Smrg
9848b8605SmrgContact
10848b8605Smrg
11848b8605Smrg    Ian Romanick, IBM, idr at us.ibm.com
12848b8605Smrg
13848b8605SmrgStatus
14848b8605Smrg
15848b8605Smrg    Deployed in DRI drivers post-XFree86 4.3.
16848b8605Smrg
17848b8605SmrgVersion
18848b8605Smrg
19848b8605Smrg    Date: 5/1/2003   Revision: 1.1
20848b8605Smrg
21848b8605SmrgNumber
22848b8605Smrg
23848b8605Smrg    ???
24848b8605Smrg
25848b8605SmrgDependencies
26848b8605Smrg
27848b8605Smrg    GLX_SGI_swap_control affects the definition of this extension.
28848b8605Smrg    GLX_MESA_swap_control affects the definition of this extension.
29848b8605Smrg    GLX_OML_sync_control affects the definition of this extension.
30848b8605Smrg
31848b8605Smrg    Based on WGL_I3D_swap_frame_usage version 1.3.
32848b8605Smrg
33848b8605SmrgOverview
34848b8605Smrg
35848b8605Smrg    This extension allows an application to determine what portion of the
36848b8605Smrg    swap period has elapsed since the last swap operation completed.  The
37848b8605Smrg    "usage" value is a floating point value on the range [0,max] which is
38848b8605Smrg    calculated as follows:
39848b8605Smrg
40848b8605Smrg                              td
41848b8605Smrg                   percent = ----
42848b8605Smrg                              tf
43848b8605Smrg
44848b8605Smrg    where td is the time measured from the last completed buffer swap (or
45848b8605Smrg    call to enable the statistic) to when the next buffer swap completes, tf
46848b8605Smrg    is the entire time for a frame which may be multiple screen refreshes
47848b8605Smrg    depending on the swap interval as set by the GLX_SGI_swap_control or
48848b8605Smrg    GLX_OML_sync_control extensions. 
49848b8605Smrg
50848b8605Smrg    The value, percent, indicates the amount of time spent between the
51848b8605Smrg    completion of the two swaps.  If the value is in the range [0,1], the
52848b8605Smrg    buffer swap occurred within the time period required to maintain a
53848b8605Smrg    constant frame rate.  If the value is in the range (1,max], a constant
54848b8605Smrg    frame rate was not achieved.  The value indicates the number of frames
55848b8605Smrg    required to draw.
56848b8605Smrg
57848b8605Smrg    This definition of "percent" differs slightly from
58848b8605Smrg    WGL_I3D_swap_frame_usage.  In WGL_I3D_swap_frame_usage, the measurement
59848b8605Smrg    is taken from the completion of one swap to the issuance of the next.
60848b8605Smrg    This representation may not be as useful as measuring between
61848b8605Smrg    completions, as a significant amount of time may pass between the
62848b8605Smrg    issuance of a swap and the swap actually occurring.
63848b8605Smrg
64848b8605Smrg    There is also a mechanism to determine whether a frame swap was
65848b8605Smrg    missed.
66848b8605Smrg
67848b8605SmrgNew Procedures and Functions
68848b8605Smrg
69848b8605Smrg    int glXGetFrameUsageMESA(Display *dpy,
70848b8605Smrg                             GLXDrawable drawable,
71848b8605Smrg    	                     float *usage)
72848b8605Smrg
73848b8605Smrg    int glXBeginFrameTrackingMESA(Display *dpy,
74848b8605Smrg                                  GLXDrawable drawable)
75848b8605Smrg
76848b8605Smrg    int glXEndFrameTrackingMESA(Display *dpy,
77848b8605Smrg                                GLXDrawable drawable)
78848b8605Smrg
79848b8605Smrg    int glXQueryFrameTrackingMESA(Display *dpy,
80848b8605Smrg                                  GLXDrawable drawable,
81848b8605Smrg				  int64_t *swapCount,
82848b8605Smrg                                  int64_t *missedFrames,
83848b8605Smrg                                  float *lastMissedUsage)
84848b8605Smrg
85848b8605SmrgNew Tokens
86848b8605Smrg
87848b8605Smrg    None
88848b8605Smrg
89848b8605SmrgAdditions to Chapter 2 of the 1.4 GL Specification (OpenGL Operation)
90848b8605Smrg
91848b8605Smrg    None
92848b8605Smrg
93848b8605SmrgAdditions to Chapter 3 of the 1.4 GL Specification (Rasterization)
94848b8605Smrg
95848b8605Smrg    None
96848b8605Smrg
97848b8605SmrgAdditions to Chapter 4 of the 1.4 GL Specification (Per-Fragment Operations
98848b8605Smrgand the Framebuffer)
99848b8605Smrg
100848b8605Smrg    None
101848b8605Smrg
102848b8605SmrgAdditions to Chapter 5 of the 1.4 GL Specification (Special Functions)
103848b8605Smrg
104848b8605Smrg    None
105848b8605Smrg
106848b8605SmrgAdditions to Chapter 6 of the 1.4 GL Specification (State and State Requests)
107848b8605Smrg
108848b8605Smrg    None
109848b8605Smrg
110848b8605SmrgAdditions to the GLX 1.3 Specification
111848b8605Smrg
112848b8605Smrg    The frame usage is measured as the percentage of the swap period elapsed
113848b8605Smrg    between two buffer-swap operations being committed.  In unextended GLX the
114848b8605Smrg    swap period is the vertical refresh time.  If SGI_swap_control or
115848b8605Smrg    MESA_swap_control are supported, the swap period is the vertical refresh
116848b8605Smrg    time multiplied by the swap interval (or one if the swap interval is set
117848b8605Smrg    to zero).
118848b8605Smrg    
119848b8605Smrg    If OML_sync_control is supported, the swap period is the vertical
120848b8605Smrg    refresh time multiplied by the divisor parameter to
121848b8605Smrg    glXSwapBuffersMscOML.  The frame usage in this case is less than 1.0 if
122848b8605Smrg    the swap is committed before target_msc, and is greater than or equal to
123848b8605Smrg    1.0 otherwise.  The actual usage value is based on the divisor and is
124848b8605Smrg    never less than 0.0.
125848b8605Smrg
126848b8605Smrg       int glXBeginFrameTrackingMESA(Display *dpy,
127848b8605Smrg                                     GLXDrawable drawable,
128848b8605Smrg				     float *usage)
129848b8605Smrg
130848b8605Smrg    glXGetFrameUsageMESA returns a floating-point value in <usage>
131848b8605Smrg    that represents the current swap usage, as defined above.
132848b8605Smrg
133848b8605Smrg    Missed frame swaps can be tracked by calling the following function:
134848b8605Smrg
135848b8605Smrg       int glXBeginFrameTrackingMESA(Display *dpy,
136848b8605Smrg                                     GLXDrawable drawable)
137848b8605Smrg
138848b8605Smrg    glXBeginFrameTrackingMESA resets a "missed frame" count and
139848b8605Smrg    synchronizes with the next frame vertical sync before it returns.
140848b8605Smrg    If a swap is missed based in the rate control specified by the
141848b8605Smrg    <interval> set by glXSwapIntervalSGI or the default swap of once
142848b8605Smrg    per frame, the missed frame count is incremented.
143848b8605Smrg
144848b8605Smrg    The current missed frame count and total number of swaps since
145848b8605Smrg    the last call to glXBeginFrameTrackingMESA can be obtained by
146848b8605Smrg    calling the following function:
147848b8605Smrg
148848b8605Smrg       int glXQueryFrameTrackingMESA(Display *dpy,
149848b8605Smrg                                     GLXDrawable drawable,
150848b8605Smrg				     int64_t *swapCount,
151848b8605Smrg                                     int64_t *missedFrames,
152848b8605Smrg                                     float *lastMissedUsage)
153848b8605Smrg
154848b8605Smrg    The location pointed to by <swapCount> will be updated with the
155848b8605Smrg    number of swaps that have been committed.  This value may not match the
156848b8605Smrg    number of swaps that have been requested since swaps may be
157848b8605Smrg    queued by the implementation.  This function can be called at any
158848b8605Smrg    time and does not synchronize to vertical blank.
159848b8605Smrg
160848b8605Smrg    The location pointed to by <missedFrames> will contain the number
161848b8605Smrg    swaps that missed the specified frame.  The frame usage for the
162848b8605Smrg    last missed frame is returned in the location pointed to by
163848b8605Smrg    <lastMissedUsage>.
164848b8605Smrg
165848b8605Smrg    Frame tracking is disabled by calling the function
166848b8605Smrg
167848b8605Smrg       int glXEndFrameTrackingMESA(Display *dpy,
168848b8605Smrg                                   GLXDrawable drawable)
169848b8605Smrg
170848b8605Smrg    This function will not return until all swaps have occurred.  The
171848b8605Smrg    application can call glXQueryFrameTrackingMESA for a final swap and
172848b8605Smrg    missed frame count.
173848b8605Smrg
174848b8605Smrg    If these functions are successful, zero is returned.  If the context
175848b8605Smrg    associated with dpy and drawable is not a direct context,
176848b8605Smrg    GLX_BAD_CONTEXT is returned.
177848b8605Smrg
178848b8605SmrgErrors
179848b8605Smrg
180848b8605Smrg    If the function succeeds, zero is returned.  If the function
181848b8605Smrg    fails, one of the following error codes is returned:
182848b8605Smrg
183848b8605Smrg       GLX_BAD_CONTEXT         The current rendering context is not a direct
184848b8605Smrg       			       context.
185848b8605Smrg
186848b8605SmrgGLX Protocol
187848b8605Smrg
188848b8605Smrg    None.  This extension only extends to direct rendering contexts.
189848b8605Smrg
190848b8605SmrgNew State
191848b8605Smrg
192848b8605Smrg    None
193848b8605Smrg
194848b8605SmrgNew Implementation Dependent State
195848b8605Smrg
196848b8605Smrg    None
197848b8605Smrg
198848b8605SmrgRevision History
199848b8605Smrg
200848b8605Smrg    1.1,  5/1/03   Added contact information.
201848b8605Smrg    1.0,  3/17/03  Initial version based on WGL_I3D_swap_frame_usage.
202