1Name 2 3 NV_delay_before_swap 4 5Name Strings 6 7 GLX_NV_delay_before_swap 8 9Contributors 10 11 Miguel Angel Vico, NVIDIA 12 Jeannot Breton, NVIDIA 13 Eric Werness, NVIDIA 14 Andy Ritger, NVIDIA 15 James Jones, NVIDIA 16 Cass Everitt, NVIDIA 17 John Carmack, id Software 18 19Contact 20 21 Miguel Angel Vico, NVIDIA Corporation (mvicomoya 'at' nvidia.com) 22 23Status 24 25 Complete. 26 27Version 28 29 Last Modified Date: 11/08/2013 30 Revision: 1 31 32Number 33 34 OpenGL Extension #445 35 36Dependencies 37 38 Requires GLX 1.1 39 40 Requires EXT_swap_control 41 42 Interacts with EXT_swap_control_tear 43 44 This specification is written against the wording of the GLX 1.4 and 45 is based on the WGL_NV_delay_before_swap specifications 46 47Overview 48 49 For most interactive applications, the standard rendering loop responding 50 to input events on a frame granularity is sufficient. Some more demanding 51 applications may want to exchange performance for the ability to sample 52 input closer to the final frame swap and adjust rendering accordingly. 53 This extension adds functionality to allow the application to wait until a 54 specified time before a swapbuffers command would be able to execute. 55 56 57New Procedures and Functions 58 59 Bool glXDelayBeforeSwapNV(Display *dpy, GLXDrawable drawable, GLfloat seconds) 60 61 62New Tokens 63 64 None 65 66Additions to the GLX 1.4 Specification 67 68 [Add the following to Section 3.3.10 of the GLX specification 69 (Double Buffering)] 70 71 glXDelayBeforeSwapNV blocks the CPU until <seconds> seconds before a 72 synchronized swap would occur on a particular GLX window drawable. It 73 also returns a boolean value equal to True when the implementation had 74 to wait for the synchronized swap and False otherwise. 75 76 The parameter <seconds> accepts positive floating point values not larger 77 than the length in seconds of the swap period on the associated drawable. 78 When buffer swaps are synchronized, the swap period is composed of one or 79 multiple video frame periods. A video frame period is the time required by 80 the monitor to display a full frame of video data. A swap interval set to 81 a value of 2 means that the color buffers will be swapped at most every 82 other video frame. If <seconds> is smaller than 0, glXDelayBeforeSwapNV 83 will return False and will not wait for the end of the swap period. If 84 <seconds> is greater than a swap period, glXDelayBeforeSwapNV will return 85 immediately without generating any error and the return value will be False. 86 87 The application should use a <seconds> delay large enough to have time to 88 complete its work before the end of the swap period. If <seconds> is close 89 to 0.0, the application may miss the end of the swap period and it will 90 have to wait an additional swap period before it can swap. 91 92 If glXDelayBeforeSwapNV detects that there is less than <seconds> seconds 93 before the end of the swap period, it will return immediately and the 94 return value will be False. The implementation will not wait an additional 95 video frame period to have an exact delay of <seconds> seconds. 96 97 If buffer swaps are unsynchronized, glXDelayBeforeSwapNV will return 98 immediately and the return value will be False. It could happen for 99 multiple reasons, for example if the swap interval is equal to 0, if the 100 window is in a mode switch or if no monitors are active. 101 102GLX Protocol 103 104 One new GLX protocol command is added. 105 106 DelayBeforeSwapNV 107 1 CARD8 opcode (X assigned) 108 1 17 GLX opcode (glXVendorPrivateWithReply) 109 2 4 request length 110 4 1341 vendor specific opcode 111 4 GLX_DRAWABLE drawable 112 4 FLOAT32 seconds 113 => 114 1 CARD8 reply 115 1 unused 116 2 CARD16 sequence number 117 4 0 reply length 118 1 BOOL waited 119 23 unused 120 121Errors 122 123 glXDelayBeforeSwapNV generates BadValue if parameter <seconds> is 124 less than zero. 125 126 glXDelayBeforeSwapNV generates GLXBadWindow if parameter <drawable> is 127 not a GLXWindow or Window XID. 128 129Usage Examples 130 131 Here is a simple example that shows how an application can use 132 GLX_NV_delay_before_swap to lower input latency when rendering its frames. 133 134 void DrawFrame(Display *dpy, GLXDrawable drawable) 135 { 136 // Render the slowest part of the frame 137 DrawScene(); 138 // Make sure there's no remaining work on the GPU 139 glFinish(); 140 // Wait for the end of the swap period 141 glXDelayBeforeSwapNV(dpy, drawable, 0.0015); 142 143 // Sample inputs and adjust the image before the SwapBuffer 144 145 glXSwapBuffers(dpy, drawable); 146 } 147 148Issues 149 150 (1) What happens if glXDelayBeforeSwapNV is called and the <seconds> delay 151 is larger than the time left until the end of the swap period? 152 153 RESOLVED. The function returns immediately. We also added a return 154 value to glXDelayBeforeSwapNV to help the application detects this 155 situation. When glXDelayBeforeSwapNV returns False, but didn't 156 generate any error, it means that it didn't have to wait because it got 157 called less than <seconds> seconds before the end of the swap period. 158 159 (2) Should we add a function that return the amount of time until the end 160 of the swap period? 161 162 RESOLVED. It would be nice to know exactly when the current swap 163 period is going to end, but in some configurations it's not possible 164 to return a value that we can guarantee will always be accurate. 165 166 (3) How does glXDelayBeforeSwapNV interact with GLX_EXT_swap_control_tear? 167 168 RESOLVED. glXDelayBeforeSwapNV always attempts to stall until the 169 specified time before the SwapBuffers command could complete. With 170 swap_control_tear, the swap will wait until a fixed swap period if 171 possible, but perform an unsynchronized swap otherwise. If the 172 swapbuffers would wait, then glXDelayBeforeSwapNV will wait similarly if 173 required, but if the swap period is already past and the swapbuffers 174 would execute unsynchronized, then glXDelayBeforeSwapNV would return 175 immediately. 176 177 (4) Why does this extension delay before execution of SwapBuffers rather 178 than on a potential swap period? 179 180 RESOLVED. Given that the expected use case is to wait until before the 181 SwapBuffers would execute to sample input, having any cases where the 182 behavior of the delay mismatches the behavior of the swap (such as 183 swap_control_tear or swap_interval!=1) can cause significant issues in 184 when the input is sampled. 185 186Revision History 187 188 Rev. Date Author Changes 189 ---- -------- -------- ----------------------------------------- 190 1 10/22/13 mvicomoya Internal revisions. 191