0
\$\begingroup\$

I am writing my own c++/DirectX engine. I've made the basic framework and here comes the time for optimizations.

I don't want to focus on optimizing the resources themselves right now (meshes, textures) or on instancing. I've also commented out shadows and normal mapping for that test. So it's just a "flat" problem of "how to speed up rendering that vertices?".

The meshes are fully static, loaded from files (no terrain generation involved).

I just have about 120.000 triangles with textures on scene (one shader, few models). And on my laptop I get about 20-40fps. I was able to increase fps with vsync and back-face a bit (note that camera is rotating and fps falls when all 120.000 triangles are within its range): enter image description here

Still, other engines (Unity, Unreal) can render the same meshes faster on the same hardware (and Unreal does it even faster then Unity which still is better then my DirecX11/c++ implementation). How they do that? I know there are many "pro programmers" behind that engines, but they are no magicians. And some solutions should be possible to apply in my engine too (vsync was easy to apply yet it gave me a nice speed boost).

I use DirectX 11, c++. I use Visual Studio if it's important. There is very little logic involved in application, no physics, no searches etc. that could slow down the render loop.

So far I made just few optimizations:

  1. Dynamic/static vertex buffers where they are needed. Index buffer.
  2. Back-face culling.
  3. V-SYNC (more about removing bugs but also helped with fps a bit).
  4. Near/far clipping.
  5. Compressing textures into single texture atlas (I've not done it yet, but I am aware of that technique).
  6. Lowering the AA (e.g. MSAA) and resolution (but it has an big impact on render quality).

I know my hardware is capable of rendering such amount of triangles. But how to help it? My problem is that I don't know all the tricks & methods that can be used here.

If any part of the source code would be useful, just comment me (I'm not sure which parts should I post and I don't want to paste meaningless code listings). I will post the results of fps increase/decrease as I manage to incorporate new optimizations.

\$\endgroup\$
  • 1
    \$\begingroup\$ I can't tell much about direct3d since i'm using opengl but you'll need to find out where exactly the bottleneck is. As far as i know, Visual Studio has its own graphics debugger and profiler, i've seen podcasts from microsoft where they use this profiler and get a nice timeline which shows, what happens when and how long it takes. \$\endgroup\$ – tkausl Jul 28 '15 at 1:12
  • \$\begingroup\$ Have you played with frustum culling? Cull out shapes that aren't in the view. DirectX automatically culls, but it is per triangle. It's a lot more efficient to cull out entire batches. It's even more efficient if you work on a scene graph. hierarchically culling them. I do not believe this is your bottleneck though. \$\endgroup\$ – Andrew Wilson Jul 28 '15 at 1:14
  • \$\begingroup\$ For Direct3D on Windows, the key performance question is how many individual Draw batches you are submitting? This directly drives a lot of the CPU and kernel overhead. Good tools to try: VS 2013/2015 Graphics Diagnostics, GPUView, Intel GPA, NVIDIA nSight, and/or AMD GPU PerfStudio. \$\endgroup\$ – Chuck Walbourn Jul 28 '15 at 2:13
  • \$\begingroup\$ Thank you all for the comments :) I will definitely use frustum culling and look into draw batches (the less the better? or above some batch size, it's better to split it?). I have one concern - when I profile the program, won't I end up in local minimum (the optimization for my specific hardware which may not work on other PC with e.g. different GPU/CPU "performance proportion")? \$\endgroup\$ – PolGraphic Jul 29 '15 at 7:03
  • \$\begingroup\$ nvidia.com/docs/IO/8228/BatchBatchBatch.pdf Read up on what exactly a batch is. I imagine you are using batches already. I suggest downloading Nvidia Nsight (a graphics debugger) and poking around with it for a bit. Very nice tool. \$\endgroup\$ – Andrew Wilson Jul 29 '15 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.