Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Gfx.WaitForPresent

Discussion in 'Editor & General Support' started by jordi_boni, Nov 15, 2013.

  1. ghostnova

    ghostnova

    Joined:
    Nov 27, 2013
    Posts:
    5
    I'm on Windows 7 Pro and I have the WaitForPresent issue. The spikes are visible on the device too though. I'm going to try Cryztalfox advice. I hope it affects the builds as well.
     
  2. Connorconno2

    Connorconno2

    Joined:
    Jan 23, 2013
    Posts:
    8
    Has anybody found an answer yet?!
     
  3. SeanM3D

    SeanM3D

    Joined:
    Jul 24, 2013
    Posts:
    192
    Cryztalfox's solution did NOT entirely get rid of the viewport stuttering. Even if it did, I need some DX features for my project so switching to OpenGL is not an option for me.

    This is really a nasty bug that needs to be fixed urgently!
     
  4. Vunpac

    Vunpac

    Joined:
    Mar 13, 2012
    Posts:
    32
    As LaneFox pointed out, it is not an innocent value. It is using 89% of my CPU and my fps is down to 33fps, I only have 3000 objects, basic shaders (all are being batch drawn) I have shadows disabled. There is no reason to be hitting that low of an fps just loading and moving a few thousand cubes.

    I really don't like having to use a work around. Feels like I will run into issues on other systems. I hope they fix this soon.

    Edit: I was just testing something. Seems I only get it when the camera is in Orthographic. The second I switch to perspective, my fps flys up to normal. I am curious as to how many other people are using ortho, or if they are getting this with persp cameras as well?
     
    Last edited: Mar 18, 2014
  5. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    717
    $7Gdkc.png

    IN OpenGL i look win 50ms only ! but gfx stay here
     
  6. Xander779

    Xander779

    Joined:
    Feb 19, 2014
    Posts:
    1
    I've found a solution to the problem that doesn't require any sacrifices to your project.
    The problem appears to be centered around Unity 4.3 compatibility with Windows 8.

    I switched Unity to run in compatibility mode with Windows XP and it completely eliminated the GFX.WaitForPreset call without any negative impacts on the project.
     
  7. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    717
    thank's i just try and i stay here with overhead !
     
  8. d1-favero

    d1-favero

    Joined:
    Oct 14, 2011
    Posts:
    4
    Just make a quick test here. With shadows enabled, Gfx.WaitForPreset goes to 60%, 70%.
    With no shadows , 0%.
     
  9. oneslyfox

    oneslyfox

    Joined:
    Sep 4, 2012
    Posts:
    71
    That worked for me!
     
  10. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    I am also experiencing this problem after updating my Unity to the latest version.

    There were no changes made to my project between updating Unity, yet when I run my game it is unplayable due to the same reasons these dozens of people have pointed out.
     
    Last edited: Apr 19, 2014
  11. zelmund

    zelmund

    Joined:
    Mar 2, 2012
    Posts:
    315
    confirm. if i start unity3d in winXp mode, the problem is gone forever!
     
  12. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,082
    I'm not totally convinced this is a bug as I too am (or was) having this problem on a 8.1 / ARM device (mobile) and yet could not figure out why I would get between 30-15fps for basically nothing in my unity project (running remote debug with an actual device).

    but what I CAN say for sure, is that 8.1 seems to be v-sync locked on this particular device, so setting vsync does absolutely nothing in the game.. you just can't change it on the device (at all).

    the other deal is just poorly optimized shaders for DirectX 11 and/or super crappy drivers for ARM and w8... to much stuff happening in the fragment portion of it... seems like anything above 21 ALU "kills" the GPU on these win 8/8.1 mobile devices. so you really have to be conservative with the shaders... combine as much as possible into single textures, single meshes.. no post effects, no or at MOST one light source, no shadows (or extremely limited one hard shadow), limit your physics, limit your particles. post effects absolutely destroys frame rate.


    now with all that said, since we can actually debug remote graphics now for ARM/Win 8.1.... and capture vert/frag operations, as well as mega details for reach draw call and a timeline... :

    (the following is a timeline capture of the drawcall(s) sequence for one frame, 8 draw calls, ~60fps)


    Code (csharp):
    1.  
    2. 1 ID3D11DeviceContext::OMSetRenderTargets(1,{obj:10},obj:12)
    3. 2 IDXGIFactory1::IsCurrent()
    4. 3 IDXGIOutput::WaitForVBlank()
    5. 4 ID3D11DeviceContext::RSSetViewports(1,{{D3D11_VIEWPORT: TopLeftX=0, TopLeftY=0, Width=1366, Height=768, MinDepth=0, MaxDepth=1}})
    6. 5 ID3D11DeviceContext::RSSetScissorRects(1,{{D3D11_RECT: left=0, top=0, right=1366, bottom=768}})
    7. 6 ID3D11DeviceContext::ClearRenderTargetView(obj:10,{0.192157,0.301961,0.47451,0.0196078})
    8. 7 ID3D11DeviceContext::ClearDepthStencilView(obj:12,D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL,1,0)
    9. 8 ID3D11DeviceContext::PSSetShaderResources(0,1,{Texture2D-SRV-13-4x4})
    10. 9 IDXGIFactory1::IsCurrent()
    11. 10 IDXGIOutput::WaitForVBlank()
    12. 11 ID3D11DeviceContext::PSSetSamplers(0,1,{SamplerState-1-0})
    13. 12 ID3D11DeviceContext::PSSetShaderResources(1,1,{Texture2D-SRV-41-1024x1024})
    14. 13 IDXGIFactory1::IsCurrent()
    15. 14 IDXGIOutput::WaitForVBlank()
    16. 15 IDXGIFactory1::IsCurrent()
    17. 16 IDXGIOutput::WaitForVBlank()
    18. 17 IDXGIFactory1::IsCurrent()
    19. 18 IDXGIOutput::WaitForVBlank()
    20. 19 ID3D11DeviceContext::PSSetSamplers(1,1,{SamplerState-1-1})
    21. 20 ID3D11DeviceContext::OMSetBlendState(BlendState-2-1,nullptr,0xffffffff)
    22. 21 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    23. 22 ID3D11DeviceContext::OMSetDepthStencilState(DepthStencilState-1-4,0)
    24. 23 ID3D11DeviceContext::RSSetState(RasterizerState-0-3(1))
    25. 24 ID3D11DeviceContext::VSSetShader(VS-2048,nullptr,0)
    26. 25 ID3D11DeviceContext::PSSetShader(PS-1658,nullptr,0)
    27. 26 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-36-336,0,nullptr,addr,336,336)
    28. 27 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-41-96,0,nullptr,addr,96,96)
    29. 28 ID3D11DeviceContext::VSSetConstantBuffers(0,1,{ConstantBuffer-41-96})
    30. 29 ID3D11DeviceContext::PSSetConstantBuffers(0,1,{ConstantBuffer-41-96})
    31. 30 ID3D11DeviceContext::IASetInputLayout(InputLayout-6(1))
    32. 31 ID3D11DeviceContext::IASetIndexBuffer(IndexBuffer-26880,DXGI_FORMAT_R16_UINT,0)
    33. 32 IDXGIFactory1::IsCurrent()
    34. 33 IDXGIOutput::WaitForVBlank()
    35. 34 IDXGIFactory1::IsCurrent()
    36. 35 IDXGIOutput::WaitForVBlank()
    37. 36 IDXGIFactory1::IsCurrent()
    38. 37 IDXGIOutput::WaitForVBlank()
    39. 38 IDXGIFactory1::IsCurrent()
    40. 39 IDXGIOutput::WaitForVBlank()
    41. 40 IDXGIFactory1::IsCurrent()
    42. 41 IDXGIOutput::WaitForVBlank()
    43. 42 IDXGIFactory1::IsCurrent()
    44. 43 IDXGIOutput::WaitForVBlank()
    45. 44 IDXGIFactory1::IsCurrent()
    46. 45 IDXGIOutput::WaitForVBlank()
    47. 46 IDXGIFactory1::IsCurrent()
    48. 47 IDXGIOutput::WaitForVBlank()
    49. 48 IDXGIFactory1::IsCurrent()
    50. 49 IDXGIOutput::WaitForVBlank()
    51. 50 IDXGIFactory1::IsCurrent()
    52. 51 IDXGIOutput::WaitForVBlank()
    53. 52 IDXGIFactory1::IsCurrent()
    54. 53 IDXGIOutput::WaitForVBlank()
    55. 54 IDXGIFactory1::IsCurrent()
    56. 55 IDXGIOutput::WaitForVBlank()
    57. 56 IDXGIFactory1::IsCurrent()
    58. 57 IDXGIOutput::WaitForVBlank()
    59. 58 IDXGIFactory1::IsCurrent()
    60. 59 IDXGIOutput::WaitForVBlank()
    61. 60 IDXGIFactory1::IsCurrent()
    62. 61 IDXGIOutput::WaitForVBlank()
    63. 62 IDXGIFactory1::IsCurrent()
    64. 63 IDXGIOutput::WaitForVBlank()
    65. 64 IDXGIFactory1::IsCurrent()
    66. 65 IDXGIOutput::WaitForVBlank()
    67. 66 IDXGIFactory1::IsCurrent()
    68. 67 IDXGIOutput::WaitForVBlank()
    69. 68 IDXGIFactory1::IsCurrent()
    70. 69 IDXGIOutput::WaitForVBlank()
    71. 70 ID3D11DeviceContext::DrawIndexed(1980,11460,0)
    72. 71 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    73. 72 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-41-96,0,nullptr,addr,96,96)
    74. 73 ID3D11DeviceContext::IASetIndexBuffer(IndexBuffer-26880,DXGI_FORMAT_R16_UINT,0)
    75. 74 IDXGIFactory1::IsCurrent()
    76. 75 IDXGIOutput::WaitForVBlank()
    77. 76 IDXGIFactory1::IsCurrent()
    78. 77 IDXGIOutput::WaitForVBlank()
    79. 78 ID3D11DeviceContext::DrawIndexed(360,8940,0)
    80. 79 ID3D11DeviceContext::Map(IndexBufferCustomDynamic-32768,0,D3D11_MAP_WRITE_DISCARD,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFFC, RowPitch=0, DepthPitch=0})
    81. 80 ID3D11DeviceContext::Unmap(IndexBufferCustomDynamic-32768,0)
    82. 81 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    83. 82 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-41-96,0,nullptr,addr,96,96)
    84. 83 ID3D11DeviceContext::IASetIndexBuffer(IndexBufferCustomDynamic-32768,DXGI_FORMAT_R16_UINT,0)
    85. 84 IDXGIFactory1::IsCurrent()
    86. 85 IDXGIOutput::WaitForVBlank()
    87. 86 ID3D11DeviceContext::DrawIndexed(8460,0,0)
    88. 87 ID3D11DeviceContext::Map(IndexBufferCustomDynamic-32768,0,D3D11_MAP_WRITE_NO_OVERWRITE,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFFA, RowPitch=0, DepthPitch=0})
    89. 88 ID3D11DeviceContext::Unmap(IndexBufferCustomDynamic-32768,0)
    90. 89 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    91. 90 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-41-96,0,nullptr,addr,96,96)
    92. 91 ID3D11DeviceContext::IASetIndexBuffer(IndexBufferCustomDynamic-32768,DXGI_FORMAT_R16_UINT,0)
    93. 92 IDXGIFactory1::IsCurrent()
    94. 93 IDXGIOutput::WaitForVBlank()
    95. 94 IDXGIFactory1::IsCurrent()
    96. 95 IDXGIOutput::WaitForVBlank()
    97. 96 ID3D11DeviceContext::DrawIndexed(1800,8460,0)
    98. 97 ID3D11DeviceContext::PSSetShaderResources(0,1,{Texture2D-SRV-39-2048x2048})
    99. 98 IDXGIFactory1::IsCurrent()
    100. 99 IDXGIOutput::WaitForVBlank()
    101. 100 IDXGIFactory1::IsCurrent()
    102. 101 IDXGIOutput::WaitForVBlank()
    103. 102 IDXGIFactory1::IsCurrent()
    104. 103 IDXGIOutput::WaitForVBlank()
    105. 104 IDXGIFactory1::IsCurrent()
    106. 105 IDXGIOutput::WaitForVBlank()
    107. 106 IDXGIFactory1::IsCurrent()
    108. 107 IDXGIOutput::WaitForVBlank()
    109. 108 IDXGIFactory1::IsCurrent()
    110. 109 IDXGIOutput::WaitForVBlank()
    111. 110 IDXGIFactory1::IsCurrent()
    112. 111 IDXGIOutput::WaitForVBlank()
    113. 112 ID3D11DeviceContext::PSSetShaderResources(1,1,{Texture2D-SRV-41-1024x1024})
    114. 113 ID3D11DeviceContext::PSSetSamplers(0,1,{SamplerState-1-1})
    115. 114 ID3D11DeviceContext::PSSetShaderResources(2,1,{Texture2D-SRV-37-2048x2048})
    116. 115 ID3D11DeviceContext::PSSetSamplers(1,1,{SamplerState-2-1})
    117. 116 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    118. 117 ID3D11DeviceContext::VSSetShader(VS-1796,nullptr,0)
    119. 118 ID3D11DeviceContext::PSSetShader(PS-3803,nullptr,0)
    120. 119 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-41-96,0,nullptr,addr,96,96)
    121. 120 IDXGIFactory1::IsCurrent()
    122. 121 ID3D11DeviceContext::IASetInputLayout(InputLayout-6(2))
    123. 122 IDXGIOutput::WaitForVBlank()
    124. 123 ID3D11DeviceContext::IASetIndexBuffer(IndexBuffer-26880,DXGI_FORMAT_R16_UINT,0)
    125. 124 IDXGIFactory1::IsCurrent()
    126. 125 IDXGIOutput::WaitForVBlank()
    127. 126 ID3D11DeviceContext::DrawIndexed(480,0,0)
    128. 127 ID3D11DeviceContext::PSSetShaderResources(0,1,{Texture2D-SRV-41-1024x1024})
    129. 128 ID3D11DeviceContext::OMSetBlendState(BlendState-10-2,nullptr,0xffffffff)
    130. 129 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBuffer-489840},{60},{0})
    131. 130 ID3D11DeviceContext::OMSetDepthStencilState(DepthStencilState-0-4,0)
    132. 131 ID3D11DeviceContext::RSSetState(RasterizerState-0-3(2))
    133. 132 ID3D11DeviceContext::VSSetShader(VS-3502,nullptr,0)
    134. 133 ID3D11DeviceContext::PSSetShader(PS-2032,nullptr,0)
    135. 134 ID3D11DeviceContext::VSSetConstantBuffers(1,1,{ConstantBuffer-42-128})
    136. 135 IDXGIFactory1::IsCurrent()
    137. 136 IDXGIOutput::WaitForVBlank()
    138. 137 ID3D11DeviceContext::VSSetConstantBuffers(0,1,{ConstantBuffer-41-128})
    139. 138 ID3D11DeviceContext::PSSetConstantBuffers(0,1,{ConstantBuffer-41-128})
    140. 139 ID3D11DeviceContext::IASetInputLayout(InputLayout-6(3))
    141. 140 ID3D11DeviceContext::IASetIndexBuffer(IndexBuffer-26880,DXGI_FORMAT_R16_UINT,0)
    142. 141 IDXGIFactory1::IsCurrent()
    143. 142 IDXGIOutput::WaitForVBlank()
    144. 143 IDXGIFactory1::IsCurrent()
    145. 144 IDXGIOutput::WaitForVBlank()
    146. 145 ID3D11DeviceContext::DrawIndexed(360,11100,0)
    147. 146 ID3D11DeviceContext::RSSetViewports(1,{{D3D11_VIEWPORT: TopLeftX=0, TopLeftY=0, Width=1366, Height=768, MinDepth=0, MaxDepth=1}})
    148. 147 ID3D11DeviceContext::PSSetShaderResources(0,1,{Texture2D-SRV-35-256x256})
    149. 148 IDXGIFactory1::IsCurrent()
    150. 149 IDXGIOutput::WaitForVBlank()
    151. 150 ID3D11DeviceContext::PSSetSamplers(0,1,{SamplerState-1-0})
    152. 151 ID3D11DeviceContext::PSSetShaderResources(1,1,{Texture2D-SRV-97-16x16})
    153. 152 ID3D11DeviceContext::PSSetSamplers(1,1,{SamplerState-0-1})
    154. 153 ID3D11DeviceContext::OMSetBlendState(BlendState-5-6,nullptr,0xffffffff)
    155. 154 ID3D11DeviceContext::Map(VertexBufferDynamic-1048576,0,D3D11_MAP_WRITE_NO_OVERWRITE,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFF7, RowPitch=0, DepthPitch=0})
    156. 155 IDXGIFactory1::IsCurrent()
    157. 156 IDXGIOutput::WaitForVBlank()
    158. 157 ID3D11DeviceContext::Map(IndexBufferDynamic-65536,0,D3D11_MAP_WRITE_NO_OVERWRITE,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFF6, RowPitch=0, DepthPitch=0})
    159. 158 ID3D11DeviceContext::Unmap(VertexBufferDynamic-1048576,0)
    160. 159 ID3D11DeviceContext::Unmap(IndexBufferDynamic-65536,0)
    161. 160 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBufferDynamic-1048576},{24},{0})
    162. 161 ID3D11DeviceContext::OMSetDepthStencilState(DepthStencilState-0-8,0)
    163. 162 ID3D11DeviceContext::VSSetShader(VS-2844,nullptr,0)
    164. 163 ID3D11DeviceContext::PSSetShader(PS-1495,nullptr,0)
    165. 164 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-36-336,0,nullptr,addr,336,336)
    166. 165 ID3D11DeviceContext::VSSetConstantBuffers(1,1,{ConstantBuffer-36-336})
    167. 166 ID3D11DeviceContext::VSSetConstantBuffers(0,1,{ConstantBuffer-41-112})
    168. 167 ID3D11DeviceContext::IASetInputLayout(InputLayout-6(4))
    169. 168 ID3D11DeviceContext::IASetIndexBuffer(IndexBufferDynamic-65536,DXGI_FORMAT_R16_UINT,0)
    170. 169 IDXGIFactory1::IsCurrent()
    171. 170 IDXGIOutput::WaitForVBlank()
    172. 171 IDXGIFactory1::IsCurrent()
    173. 172 IDXGIOutput::WaitForVBlank()
    174. 173 ID3D11DeviceContext::DrawIndexed(48,19116,15576)
    175. 174 ID3D11DeviceContext::RSSetViewports(1,{{D3D11_VIEWPORT: TopLeftX=0, TopLeftY=0, Width=1366, Height=768, MinDepth=0, MaxDepth=1}})
    176. 175 ID3D11DeviceContext::RSSetViewports(1,{{D3D11_VIEWPORT: TopLeftX=0, TopLeftY=0, Width=1366, Height=768, MinDepth=0, MaxDepth=1}})
    177. 176 ID3D11DeviceContext::Map(VertexBufferDynamic-1048576,0,D3D11_MAP_WRITE_NO_OVERWRITE,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFF4, RowPitch=0, DepthPitch=0})
    178. 177 IDXGIFactory1::IsCurrent()
    179. 178 IDXGIOutput::WaitForVBlank()
    180. 179 ID3D11DeviceContext::Map(IndexBufferDynamic-65536,0,D3D11_MAP_WRITE_NO_OVERWRITE,0,{D3D11_MAPPED_SUBRESOURCE: pData=0xFFFFFFF3, RowPitch=0, DepthPitch=0})
    181. 180 ID3D11DeviceContext::Unmap(VertexBufferDynamic-1048576,0)
    182. 181 ID3D11DeviceContext::Unmap(IndexBufferDynamic-65536,0)
    183. 182 ID3D11DeviceContext::PSSetShaderResources(0,1,{Texture2D-SRV-99-115x17})
    184. 183 ID3D11DeviceContext::PSSetSamplers(0,1,{SamplerState-1-1})
    185. 184 ID3D11DeviceContext::IASetVertexBuffers(0,1,{VertexBufferDynamic-1048576},{24},{0})
    186. 185 ID3D11DeviceContext::VSSetShader(VS-1812,nullptr,0)
    187. 186 ID3D11DeviceContext::PSSetShader(PS-1138,nullptr,0)
    188. 187 ID3D11DeviceContext::UpdateSubresource(ConstantBuffer-36-336,0,nullptr,addr,336,336)
    189. 188 ID3D11DeviceContext::VSSetConstantBuffers(0,1,{ConstantBuffer-41-32})
    190. 189 ID3D11DeviceContext::IASetIndexBuffer(IndexBufferDynamic-65536,DXGI_FORMAT_R16_UINT,0)
    191. 190 IDXGIFactory1::IsCurrent()
    192. 191 IDXGIOutput::WaitForVBlank()
    193. 192 IDXGIFactory1::IsCurrent()
    194. 193 IDXGIOutput::WaitForVBlank()
    195. 194 ID3D11DeviceContext::DrawIndexed(6,19164,15616)
    196. 195 IDXGIFactory1::IsCurrent()
    197. 196 IDXGIOutput::WaitForVBlank()
    198.  

    as you can see... quite a few cycles just "waiting" for vblank... nothing we can do about it apparently.


    there is really not a lot of difference in that drawcall timeline between a scene optimized for 60fps and one that runs at 30 or 15fps with poorly optimized shaders, are just too much crap going on.
     
  13. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    717
    so if i understand you it's comming from shader maybie
     
  14. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,082
    more than likely yes... doesn't mean it was poorly written, it could just be trying to do too much or use operations that are notoriously slow for mobile GPUs.
     
  15. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    717
    yes i use skyshop rendering and get gfxaitForPresent only after install Windows 8
     
  16. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    I have this bug on windows 7. Vsync is off on the project. It happens both in-editor and in-standalone
     
  17. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    After trying the "Windows XP compatibility mode", i was about to type "yess, it works!". But no. It doesn't.
    The profiler is fine, no gfx.waitforpresent peaks, but the framerate is dropped. So, the xp compatibility mode, only hide the gfx.waitforpresent messages on profiler (really don't know why).

    Closing and reopening Unity does not solve.

    Rebooting windows do solve.

    My project is running at 7/800 fps but when the gfx.waitforpresent thing comes on (randomly) i got 130 fps.
     
    Last edited: Apr 21, 2014
  18. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    Can a Unity developer please tell us what Gfx.WaitForPresent is and why it is hogging so much resources now compared to 4.2?
     
  19. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,082
    it most likely reflects a GPU bound problem... as the CPU is literally "waiting" for something.. either vsync, or the GPU to process something. It could be many different things... each of those things I listed in the third paragraph of my earlier post could be the issue, or a combination there-of.
     
  20. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    Hi,

    Here i have attached the image. In this image my scripting and other stuff taking the small amount of memory but this Gfx.WaitforPresent taking the 85% of the space because of this only my frame rate getting low.

    I have checked the scripting,Rendering, Garbage collector, vsync everything coming fine. But this gfx only giving the problem.
    $profiler.JPG

    Have any idea about this?..
     
  21. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    47
    Last edited: May 29, 2014
  22. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    Even i have disable the vsync and i changed my camera to vertexlit from forward rendering. even though i am getting this problem.
     
  23. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    47
    Are you developing for mobile?

    Did you try to disable script debugging in the build settings?
     
  24. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    yes, i am developing for a android mobile platform.

    I have unchecked the script debugging, even-though it is coming.

    Have you got any idea about why it is coming?
     
  25. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    47
    Please try to complie a complete empty scene....with only:

    - One Camera (Clear Flags: Solid Color)
    - Disabled Gui-Layer
    - Disabled Flare-Layer

    - NO Scripts in the Scene
    - NO other Objects in the scene

    Try and run this on your android device and then lets see what the profiler is teeling you. Moreover try to disable these in the Build Settings:

    - Multithreaded Rendering
    - Enable Internal Profiler
    - Use 24-bit Depth Buffer

    EDIT: If you now get some acceptable FPS then you need to:
    -> load your game scene, disable every gameObject except your camera
    -> Test the FPS
    -> If everything is okay....enable one gameObject
    -> Test again
    -> If evrything is still okay....enable another gameObject
    -> And so on..

    If you enable one GO and immediately get FPS drops while testing then you know this object is causing the FPS-Drop.
    This is the way I try to find the "bad guys"...its rather time-consuming but it works most of the time.
     
    Last edited: May 30, 2014
  26. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    thanks for your idea. let me try this
     
  27. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    i have tried to compile the empty scene with camera and fps count script. i compile it to my unity editor, i played the scene and i saw the profiler the gfx.waitforpresent took the 5.6ms. It was the empty scene eventhough it is taking the more than 90%.

    I uncheck the camera flare and in build setting i uncheck the optimizemesh data, static batching, dynamic batching, enable internal profiler.

    tell me why its taking the so much timing for this?
     
  28. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    196
    i don't know why none of unity developers found this a real issue..

    testing a sample project on my old Galaxy Nexus, GFX.WaitForPresent took 50+% of resources...
    made the game from being 50-55 fps to around 15fps !! turned the game to unplayable literally!

    i dunno what GFX.WaitForPresent role is, but whatever it is, am sure its Not more important than making the game playable!?..
     
  29. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    then what the reason for getting down the performance in the scene?
     
  30. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    196
    sorry i didn't get your question.. what i was saying that gfx.etc was consuming resources thus dropping fps around 15 fps...
     
  31. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    358
    i have a scene when i run it on the editor it showing the above 50 fps count. But when i exported as a apk and run it on my device the fps rate is getting damage it showing only upto 10fps and lot of lag.

    What is the reason for getting fps down in the device?
     
  32. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    196
    try connecting your phone to pc then connecting profiler to see what's happening in your device while running the game... no one can answer you without showing an image of profiling your game in mobile..
     
  33. Dex7er

    Dex7er

    Joined:
    Jun 5, 2014
    Posts:
    7
    Having this issue too, even though I just updated to Unity 4.5. I am using Windows 7 and not developing for Mobile.
    Running this on an Intel Xeon E5-2609 Quadcore CPU with 12GB RAM and a 760 GTX installed.

    To start with, opening the Profiler window to try and optimize Performance drops the FPS I am getting in the Editor considerably and checking to see what might be the cause I also get the dreaded "Gfx.WaitForPresent" in the Overview:
    [​IMG]

    Tried turning off VSync and that didn't help. Even Running it at "Fastest" Quality Setting with Shadows disabled and Low Resolution with AA/AF disabled and Half Res Textures seems to still produce this to a lesser extent.
     
  34. ev3d

    ev3d

    Joined:
    Apr 19, 2013
    Posts:
    306
    I also am having this issue... Nothing seems to fix it..
     
  35. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    228
    Anyone got any info on that?
     
  36. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,018
    I encountered this issue on Mac OSX 10.9.3, though its behavior seems to depend on which monitor the game is running on.
    Screen Shot 2014-07-03 at 2.29.45 PM.png

    In this image, the left half is running on an Acer AL2216W, and the right half is running on an AOC 2269W. Both are connected via DVI to the same 780ti and both are running at 60 Hz. I don't have to restart the game for this to happen - simply running it in windowed mode and dragging from one monitor to the other will change the behavior.

    Not only does this seem to be limiting the frame rate of the game, but it also makes it really difficult to profile the other items as their sections of the graph get shrunk down so much.
     
  37. Ben Massey

    Ben Massey

    Joined:
    Jun 13, 2011
    Posts:
    581
    Interesting find, this issue has prevented us from upgrading for the time being.

    To my knowledge, you can uncheck the coloured box next to the usage group to stop it displaying in the profiler.
     
  38. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,018
    Wow... not sure how I never bothered to try that before. Thanks =-)
     
  39. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    Not sure if this is at all related, but every time I have a Gfx.WaitForPresent event in my profiler, my Memory graph shows my mesh count jumping from 50 to 130 (nothing going on in the scene), and my active rigidbodies in Physics going from 2 to 0 (they go to sleep)...

    These events happen at exact regular intervals, in my case spread out approximately 20 something frames.

    These events look very precisely controlled in the graphs for Physics and Memory, but the number of ms that Gfx.WaitForPresent takes in my CPU varies greatly. Sometimes it's an unnoticable spike (4%), sometimes its 98%.

    I never noticed this before upgrading to the Pro Trial, but I am currently using unity 4.3 on Windows 7... and this is all coming from running the profiler in the editor with the game running in the editor.
     
  40. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,474
    It would be nice to get some input from Unity.

    However I've noticed in many of the profiler screenshots shown on this page that the GPU usage is pretty high. For example 'schetty' has 21 ms on the GPU alone, that is at best that is 47 frames per second, add on the 5ms or so I can see in the cpu (ignoring waitForPresent) and that takes it down to 38 fps. Now if vsync is active or if the device is snc'd to the fresh rate the gfx.waitForpresent is most likely to be showing the time that frame had to wait for the next sync.

    Many people have mentioned Android, as far as i'm aware those devices are locked to 60 fps, meaning enabling/disabling v-sync will have no effect, thus if you project can't reliably hit 60 fps or more on those devices then you will get waits for the next v-blank.

    Its difficult to be sure since many people posting here have very different projects and may be encountering a number of different issues, but for my money this is definitely something to do with the cpu simply waiting for the gpu to become free or for the v-blank.

    No, not related. In the editor you'll get these regular jumps every time the editor updates. I can't remember off-hand if its something specific, like having the stats window open, or even if its something in the profiler itself. Should be easy to confirm just profile from a standalone build.
     
  41. XeviaN360

    XeviaN360

    Joined:
    Jun 3, 2010
    Posts:
    181
    Just updated to 4.5.2f1. Same problem. Randomly happens. I cannot optimize a !$£/%%£!=)( anything because i got 43 fps once, and 470 after a few Unity restart. F**K.
     
  42. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    I haven't tested this yet as I have never profiled a standalone build and will look into that, but just to throw this out there, I diminished its impact by 99% by tunneling all of my OnGUI calls into one main OnGUI, which decreased the amount of garbage collecting my GUI calls were making, which ultimately means less strain on both the CPU and GPU... so you're probably onto something, but I have to say that these spikes occured when my machine was capable of running 140FPS, with a WaitForFPS script locking it to 60... so it's not definitive of "your graphics card can't handle it" and may still infact be a bug... because my graphics card was far from maxed out, with the closest spike not relating to gfx.waitforpresent(which was spiking to 98ms) coming in at a whopping 6ms total. (on the GPU)
     
  43. Oswaldo-Filho

    Oswaldo-Filho

    Joined:
    Jul 18, 2014
    Posts:
    1
    Hello guys,

    same problem here, in my case it's happened in random situations (particles, GUI panels, etc...) but I think I found a solution.

    I used the old technique of erasing everything on the project except the Assets folder. Analyzing the problem more closely (kicks) I fixed the project without having to remove the following files:

    ProjectSettings / EditorBuildSettings.asset
    ProjectSettings / EditorSettings.asset
    ProjectSettings / TagManager.asset <--- I really need this in my project.

    The Unity asked me if I wanted to upgrade the project ... yes.

    It worked for me.

    I BELIEVE the problem is in ProjectSettings / ProjectSettings.asset file, not sure.

    *MAKE A BACKUP BEFORE TRY THIS!
     
    Last edited: Jul 18, 2014
  44. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,474
    Its not a question of your graphics card being maxed out, though that is a good way to get this issue, its about the gpu being busy and the cpu having to wait before it can continue to the next frame.

    For example a project I currently have open the profiler tells me that the cpu is taking 1.39ms, but the GPU is taking 1.59 ms. Clearly the cpu is finishing before the gpu can be ready for the next frame and thus gfx.waitForPresent appears. At least that's my understanding of it and makes sense in terms of the profiler term being used 'waitForPresent'.

    Of course I could be completely wrong, just like everyone else in this thread. Such a shame that we can't get a Unity dev in here to give us a definitive answer.

    I'm also sceptical of many of the 'solutions' posted here, because none provide any reasoning or information as to 'why' their fix works. That leads me to believe that they are simply fixing an unrelated issue that itself impacted on the cpu/gpu timing. Other solutions suggest that there may be some specific hardware issues, but generally I think people are misinterpreting the data they are seeing. Its not that gfx,waitForPresent is adding time, its just the time it has to wait before it can start sending data to the gpu again, which can happen for a variety of reasons, v-sync, maxed out gpu, gpu taking more time than cpu per frame etc.
     
  45. iamsteele

    iamsteele

    Joined:
    Mar 25, 2014
    Posts:
    29
    Ah, that all sounds very reasonable... doesn't explain why my GPU time was 6ms and waitforpresent was 98ms though.. and the disparity seems apparent in other cases in this thread as well where the math doesn't add up
     
  46. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,474
    Hmm, not seen something that extreme, especially if the gpu isn't taking much time itself. Guess there must be more to gfx.waitforpresent than I figured. I've brought this thread to the attention of Brett (bibbinator) hopefully he will be able to get some official posts on the matter in her soon.
     
  47. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    190
    I don't know why you are seeing the performance spikes and I am not a graphics programmer, but here is an explanation about what Gfx.WaitForPresent is, as offered by one of our developers a while ago:

    "A better name would be something like "waiting for renderer to catch up."

    It means that the main thread is waiting for the last frame to finish rendering, either on the render thread and GPU. Typically the GPU is the bottleneck, either because of Vsync or drawing too much stuff. It could also be submitting the frame to D3D/OpenGL that's taking long.

    The actual dependency is that the main thread waits for the render thread's last frame, which waits for the GPU's last frame. It could be either of those blocking the main thread. You have to find out what the cause is experimentally by disabling Vsync, rendering to a low resolution using simple shaders etc."

    Maybe this helps some of you.
     
    laurelhach likes this.
  48. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    360
    Hi im having exactly the same issue on 4.5.4 f1 and Vsync is off ofc.
    Im on win 7 on win 8.1 everything is fine.
    Its been couple of months any news on fixes?

    This destroys my work.. is this a joke? Why its not fixed yet?
     
  49. Biggsism

    Biggsism

    Joined:
    Jul 8, 2013
    Posts:
    5
    I've had this happen off and on but I still can't figure out exactly what triggers it. Tonight I had it crop up again, spent a good chunk of time trying to find the culprit, and literally closing an editor window made it go away. It never ever seems to be the same thing that fixes it but I'll still assume user error until I can't get out of the problem using testing and backups.

    Make sure all your windows (especially scene or any custom stuff like playmaker ect) are closed before profiling the issue. If no dice, try to start Unity in a fresh project and check your scene(s) in pieces.

    If this doesn't help, a fresh project with selective importing to nail down the issue then figure out the route from there. Best of luck.
     
    pointcache likes this.
  50. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    360
    exactly. Its just random bug i guess. Buying new pc solved it.
    Just kidding i restarted and it fixed itself, it's just that you get so sure you can debug stuff that when you actually cant
    you start panicking.