周期性FPS下降的可能原因? [英] Possible causes of cyclic FPS drops?

查看:47
本文介绍了周期性FPS下降的可能原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在opengl中编写了一个新的代码库,很早就遇到了一个奇怪的错误.重复率和可预测性是帧速率的明显波动.

I was writing a new code base in opengl and have encountered a weird bug very early on. It is a distinct fluctuation in framerate that is repetitive and predictable.

我知道它绝对与渲染的对象成比例.它也与屏幕大小成比例(不是视口大小,不是窗口大小,仅是物理设备大小)大约是0.2:1(低:高)帧的比例

I know that it is definitely proportional to objects rendered. It is also proportional to screen size (not viewport size, not window size, just physical device size) It is roughly a ratio of 0.2:1 (low:high) frames

我很好奇并绘制了图形,请记住,窗口/上下文没有被垂直同步或封闭.

I got curious and graphed it, bear in mind that the window/context isn't vsynced or capped.

视图是完全静止的,所有对象都是静止的.每个帧都是完全相同的.任何时候都没有输入.没有基于时间的.没有垃圾收集发生.

The view is completely stationary and all objects are stationary. Each frame is exactly the same. No input was given at any time. There is nothing time-based. No garbage collection happens.

我不明白,如果基本上是一帧一遍又一遍的渲染,是什么会引起如此大的变化?

I don't get it, if it is basically one frame being rendered over and over what could cause such a great change?

这是程序流程的伪代码

create window
load shaders
grab uniform locations
create camera
create 3 meshes // They just hold the buffers and data for a model
create x objects and pass a pointer to a random mesh // Objects hold position, rotation etc + link to mesh
while game is running
    poll window for events
    capture mouse and recalculate VP matrix if required
    for each object
        recalc MVP
        bind mesh's buffers and draw elements
    draw window //SFML handles this, just swaps front/back buffers and draws
clean up data

如果这没有任何见识,那么我将VS2012项目上传到了github: https://github.com/Twistedsnail/Untitled_for_SO (它可能不会在本地运行,因为它在指定位置需要SFML2,而在VS的文件中需要GLM)

If this gives no insights then I uploaded the VS2012 project to github: https://github.com/Twistedsnail/Untitled_for_SO(it probably won't run locally because it requires SFML2 in a specified location and GLM in VS's files)

推荐答案

当我们在上一份工作中构建游戏引擎时,有时也会遇到类似的奇怪问题.

When we were building a game engine at my last job we also had curious problems like that from time to time.

原因我记得:

  • Lua垃圾回收.在哪里使用Lua作为引擎的脚本语言,而GC会使它看起来好像渲染存在问题!虽然不是很明显.检查是否有其他线程甚至进程在您的应用程序/计算机中变得贪婪.

  • Lua garbage collection. Where were using Lua as scripting language for the engine and the GC would make it appear as if there was problem with the rendering! Though it was not obviously. Check for any other threads or even processes that might become greedy in your application/machine.

OpenGL驱动程序问题:有时在NVIDIA驱动程序中禁用或启用线程优化"会对性能产生有趣的影响.ATI驱动程序通常只是存在需要升级的错误.

OpenGL driver issues: disabling or enabling "Threaded Optimization" in the NVIDIA driver had funny effects on performance like this sometimes. ATI drivers more often simply had bugs which required an upgrade.

Windows事件循环出现问题.就像使用GetMessage而不是PeekMessage.

Problems with the Windows event loop. Like using GetMessage instead of PeekMessage.

另一件事:如果您实际上没有渲染太多,却拥有数千个FPS:即使渲染时间稍有增加,也会对您的FPS产生巨大的"影响.因此,您所看到的可能是非常正常的操作系统/驱动程序任务,这些任务在使用正常"游戏FPS(例如60到120)时无关紧要,并且以后不会引起太大关注.

Another thing: If you are really not rendering much and have several thousand FPS: even the slightest increase in rendering time will have "huge" effects on your FPS. So what you are seeing might be very normal operating system/driver tasks that are irrelevant when working with "normal" game FPS like 60 to 120 and not much noticeable later.

这篇关于周期性FPS下降的可能原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆