sokol icon indicating copy to clipboard operation
sokol copied to clipboard

sapp_frame_duration() returns ~16ms but frame cb called much more frequently than that on d3d11 backend

Open mlabbe opened this issue 2 years ago • 2 comments

Using sokol_gfx & sokol_app as of 1cc5e7f6562e4faa7e1252d5d68f70cb1eaba516, NVidia Drivers 512.95 on an RTX 3080 Laptop GPU on Windows 10.

Using the d3d11 backend with .swap_interval set to either 0 or 1 in sapp_desc, sapp_frame_duration() is returning intervals of around 16ms, but a trivial frame callback is being called much more frequently than that. This only occurs when both of the following are true:

  1. In the NVidia control panel, Manage 3D Settings, "Vertical Sync" is set to "Off" or "Fast" instead of "Use the Application 3D Setting"
  2. The _sapp.d3d11.use_dxgi_frame_stats == true code path is taken in _sapp_win32_timing_measure().

This is measured by test code that is calling QueryPerformanceCounter at the top of the frame callback function, and reporting it against the delta of the previous function.

nvidia

mlabbe avatar May 31 '22 19:05 mlabbe

Hmm ok, looks like an unintended side effect of using the DXGI SyncQPCTime value for the frame time computation. I guess DXGI only updates this timestamp when the framebuffer can actually be (visibily) presented (so at minimum the display refresh rate), not when frames are discarded because vsync has been disabled.

Not sure how to best solve this without going back to the traditional time measurement.

I'm without Windows PC access for the rest of the week, so I can't currently tinker with this.

floooh avatar Jun 01 '22 06:06 floooh

I had the opportunity to briefly consult with a D3D engineer, and they confirmed that SyncQPCTime indicates the most recent VSync that had a new frame. So it makes sense that I am getting 16ms deltas. Frame statistics indicate the last frame that was displayed.

mlabbe avatar Jun 01 '22 16:06 mlabbe