I've been developing a small indie game in my spare time and have run across an inexplicable issue开发者_高级运维. Some builds of the game will randomly run several hundred frames per second slower than other builds. For example, when rendering some text and no 3D scene, I can achieve 1800FPS on my own hardware. Add one 3D sphere (10k verts, pixel shaded), achieve 1700 FPS. Add two more spheres, achieve 800 FPS. Remove all spheres, achieve 1100FPS- even though the code now renders the same scene as I previously achieved at 1800FPS, which is just the FPS counter being rendered. I've tried rebuilding and cleaning the project and rebooting the compiler. This is in Release mode and I turned on all the optimizations I could find. Any suggestions as to the cause?
I ran a quick profile, and Visual Studio seems to think that over 90% of my time was spent in D3D9_43.dll, suggesting that it's not a bug in my app, which doesn't explain why it manifests in only some builds.
I rebooted my machine and it's back up to 1800FPS. I think it's a bug in the DirectX SDK tools (amongst many others). Going to delete this question.
I don't know if MSVC does this, but GCC does:
When GCC cannot determine the most likely branch it throws the dice.
If MSVC does that, it may be that in each build an important branch point is being predicted one way or the other and it makes a difference.
You can fix that by doing a PGO build: profile guided optimization. That will examine the code at run time and it will make all the branches correctly predicted. At least, it will be correct if your test run is a good sample.
That said, the results are not usually so dramatic. If you had more objects on the scene and more code involved the changes would even out more.
Another possibility: CPU speed scaling.
If your program spends most of its time executing on the GPU, CPU usage may not rise high enough to push the CPU into full speed.
Try adjusting Windows power management to full speed instead of balanced, see if it changes anything.
精彩评论