r/GraphicsProgramming • • Aug 22 '20

Why directxtk11 sample runs faster than imgui dx11 sample on empty scene?

I removed all the rendering and only called the ClearRenderTargetView. I even tried checking it in renderdoc but even though directxtk renders those models, it is still faster than imgui dx11 sample. I tried both imgui's sdl and win32 samples both slower than directxtk.

I've been figuring this for over 2 days now but I can't figure out what's happening.

Directxtk11: https://github.com/walbourn/directxtk-samples/blob/master/SimpleSampleWin32/Game.cppImgui + Win32: https://github.com/ocornut/imgui/blob/master/examples/example_win32_directx11/main.cpp

Imgui + SDL2: https://github.com/ocornut/imgui/blob/master/examples/example_sdl_directx11/main.cpp

I also tried bgfx example0 in dx11 build and it runs constantly at 60fps.

Btw, I ran all of these in my windows 10 vmware.

EDIT: I looked at bgfx renderer_d3d11.h ( https://github.com/bkaradzic/bgfx/blob/master/src/renderer_d3d11.h ) and it seems like directxtk11 and bgfx uses directx 11.1? and on the imgui sample is only directx11. Is that reason why? I guess I have to try out and see. lol

EDIT2: I converted my project to use <d3d11_1.h> and <d3d11_6.h> headers and it's running like in dxtk11 samples now inside my windows vm (60fps). Amazing. My opengl 3.3 project as expected runs really slow at 20-25fps. Sad drivers. :(

4 Upvotes

4 comments sorted by

2

u/Gamertron Aug 22 '20

I haven't looked at the code (it may also depend on swap creation parameters), but based on these incomplete snippets, DXTK11 is discarding the existing view, then creating a new view (which doesn't have any outstanding work), which means the Clear* calls are asynchronous against views which have no outstanding work waiting to complete.

vs the Imgui sample which is Clearing an existing view, and this has to wait for any existing work to complete

2

u/[deleted] Aug 22 '20

I tried to copy dxtk11 swap chain setup but there are some methods that are not available in plain d3d11 like the DiscardView which is only available in direct3d 11_1 ( https://docs.microsoft.com/en-us/windows/win32/api/d3d11_1/nf-d3d11_1-id3d11devicecontext1-discardview ).

I guess I just have to try the new api and see if my issue would still exist. I'm still quite new with direct3d. I've been always on the other side (opengl, vulkan)

Thanks!

1

u/DilatedMurder Aug 25 '20

Do you care about less than windows 10? If you don't then you can just skip right to 11_3. If your final target is VR then you can skip right to 11_4 (because of update 1903 and WMR [specifically the hotfixes after 1903 fucked everything]).

You can use 11_1 on Windows 7 if the platform update is installed. There are some failure cases but almost all functions you're likely to use will fall back to emulation if unsupported.

1

u/ocornut Aug 25 '20

The value if `SwapEffect` in the SwapChain creation also may have a large effect on performance on Windows 10. On Windows 10 you are supposed to use e.g. DXGI_SWAP_EFFECT_FLIP_DISCARD instead of DXGI_SWAP_EFFECT_DISCARD, but it needs a Windows 10 SDK to compile and some mumbo-jumbo Windows version testing to selectively use the other one on Windows 7/8.