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