VR开发中性能问题—OculusWaitForGPU

来源:互联网 发布:arima模型Python代码 编辑:程序博客网 时间:2024/05/02 01:44

VR开发中性能问题—OculusWaitForGPU


本文章由cartzhang编写,转载请注明出处。 所有权利保留。
文章链接:http://blog.csdn.net/cartzhang/article/details/50788894
作者:cartzhang

**

一、OculusWaitForGPU


在unity 5.3.0f4中测试,使用Unity提供的VR解决方案,直接在Build setting的Playersetting中,勾选使用Virtual Reality Supported,如下图所示:

setting

在运行程序的Profile时,你会发现OculusWaitForGPU 的占用时间特别高。
如下图:

这里写图片描述

二、原因

先说配置:
Unity 版本:Unity 5.3.0f4
OC版本:0.8.0 beta的.
是什么造成这个问题的呢?

网上搜索各种原因,如下:
1. 有的说是因为,CPU在等待OC的GPU渲染数据返回。
2. OC内部API强制垂直同步,罪魁祸首是Unity内部集成的当前OC驱动。
3. Unity个版本问题,不仅仅各个大版本,还有各个小版本之间,有个的f,有的是P。

三、大致的解决方案

为啥说大致的解决方案呢?因为招了半天,没有具体的,也没有谁说有个自己好用,别人也好用的方法。更重要的是OC官方说的方法,也是针对某个版本的暂时之用。

故此,我总结的方法如下:
1.使用64位模式。
2.在GUp和shader的渲染处理优化。
3. 换OC版本试试,使用0.6.0.1,0.7版本的可能效率低。
4. 5.3.0f4对VR来说不太好,可选择5.2.3p3来解决多线程问题,也就是说你的换换其他版本来测试,安装OC官方推荐版本来试试(下面会给出官方推荐版本连接)。
5. 对于使用Untiy插件的观众:你的选择有多了一个!!代码来解决,自己修改 TimeWarp,但是OCulus官方说这个是暂时的,以后版本就不能这样用 的。
关于修改TimeWarp的代码如下:

using UnityEngine;using System.Runtime.InteropServices;/// <summary>/// Helper class to modify the internal Oculus TimeWarp values./// </summary>public class OVRTimeWarp : MonoBehaviour{    public enum VsyncMode    {        VSYNC_60FPS = 1,        VSYNC_30FPS = 2,        VSYNC_20FPS = 3    }#pragma warning disable 414    [SerializeField]    VsyncMode targetFrameRate = VsyncMode.VSYNC_30FPS;#pragma warning restore#if (UNITY_ANDROID && !UNITY_EDITOR)   [DllImport("OVRPlugin")]   // Support to fix 60/30/20 FPS frame rate for consistency or power savings   private static extern void OVR_TW_SetMinimumVsyncs( VsyncMode mode );#endif    /// <summary>    /// Start modifying the TimeWarp    /// </summary>    void Start()    {        if (!OVRManager.isHmdPresent)        {            enabled = false;            return;        }#if (UNITY_ANDROID && !UNITY_EDITOR)      Debug.LogWarning( "Setting TimeWarp Rate to: " + targetFrameRate );      OVR_TW_SetMinimumVsyncs( targetFrameRate );#endif    }}


看清楚了,这个是需要OC对Unity的插件的,因为看到里面的

OVRManager


看到这个东西了吧,这个就是需要OVRManager.cs,也就是OC插件里带的相机管理脚本。
里面还有个宏定义,也就是说在安卓下使用。

#if (UNITY_ANDROID && !UNITY_EDITOR)   [DllImport("OVRPlugin")]   // Support to fix 60/30/20 FPS frame rate for consistency or power savings   private static extern void OVR_TW_SetMinimumVsyncs( VsyncMode mode );#endif#if (UNITY_ANDROID && !UNITY_EDITOR)      Debug.LogWarning( "Setting TimeWarp Rate to: " + targetFrameRate );      OVR_TW_SetMinimumVsyncs( targetFrameRate );#endif


什么是TimeWarp呢?这个问题,很好。简单说就是:处理VR,提高帧率的一种手段。但是不是万能的。
具体参考如下:

http://xinreality.com/wiki/Timewarp
http://www.myexception.cn/other/1883027.html

里面讲了TimeWarp的基本原理,时间扭曲和位置抖动等,可以参考一下!!
就这样了。


最后,就是关于Unity版本推荐的OC官方网:

https://forums.oculus.com/viewtopic.php?t=25882

四、参考链接

https://www.reddit.com/r/oculus/comments/3of567/huge_fps_hit_in_unity_with_vr_enabled/
https://forums.oculus.com/viewtopic.php?f=37&t=27963&p=310144&hilit=OculusWaitforGPU#p310144
http://forum.unity3d.com/threads/major-vr-performance-issue-oculuswaitforgpu-running-on-cpu.328442/

http://xinreality.com/wiki/Timewarp
http://www.myexception.cn/other/1883027.html


重要更新:2016-07-28
我们的解决方案:
目前我们测试的低OculusWaitForGPU的版本为:5.3.2f1版本。当然也不是说其他版本不行。
只是我们没有测试过。

还有就是:目前对OCulus0.80.支持的最后版本为:
Unity 5.3.4p4 and 5.4.0b15 were the last versions that supported PC SDK 0.8.!!!


就是这样了。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



若有问题,请随时联系!!!
非常感谢!!!

————————–THE———–END————————————

你可知道这默默忍耐的力量

这里写图片惊蛰

0 0
原创粉丝点击