Exemple #1
0
        // Token: 0x06001BE4 RID: 7140 RVA: 0x0009198C File Offset: 0x0008FB8C
        public static float GetGPUTimeLastFrame()
        {
            float result;

            if (XRStats.TryGetGPUTimeLastFrame(out result))
            {
                return(result);
            }
            return(0f);
        }
    private float GetGpuTimeLastFrame()
    {
        float gpuTimeLastFrame;
        float renderTime = 0;

        if (XRStats.TryGetGPUTimeLastFrame(out gpuTimeLastFrame))
        {
            renderTime = gpuTimeLastFrame;
        }
        return(renderTime);
    }
    // Update is called once per frame
    void Update()
    {
        if (m_Text != null)
        {
            float gpuLastFrameTime  = 0f;
            int   droppedFrameCount = 0;
            int   framePresentCount = 0;

            m_DeltaTime += (Time.unscaledDeltaTime);
            m_FrameCount++;

            string output = "";
#if UNITY_2017_2_OR_NEWER
            if (XRStats.TryGetGPUTimeLastFrame(out gpuLastFrameTime))
            {
                m_TotalGPUFrameTime += gpuLastFrameTime;
            }
            XRStats.TryGetDroppedFrameCount(out droppedFrameCount);
            XRStats.TryGetFramePresentCount(out framePresentCount);
#else
            using UnityEngine.VR;
#endif

            if (m_DeltaTime > m_RefreshFrequency)
            {
                float fps = (float)m_FrameCount / m_DeltaTime;
                m_TotalGPUFrameTime /= (float)m_FrameCount;

                m_DeltaTime -= m_RefreshFrequency;
                output      += "fps: " + fps.ToString("F1");
                output      += "\ngpuTimeLastFrame: " + m_TotalGPUFrameTime.ToString("F1");
                output      += "\ndroppedFrameCount: " + droppedFrameCount.ToString();
                output      += "\nframePresentCount: " + framePresentCount.ToString();

                m_Text.text = output;

                m_DeltaTime        -= m_RefreshFrequency;
                m_TotalGPUFrameTime = 0.0f;
                m_FrameCount        = 0;
            }
        }
    }
Exemple #4
0
    private IEnumerator FPS()
    {
        for (; ;)
        {
            // Capture frame-per-second
            int   lastFrameCount = Time.frameCount;
            float lastTime       = Time.realtimeSinceStartup;
            yield return(new WaitForSeconds(frequency));

            float timeSpan   = Time.realtimeSinceStartup - lastTime;
            int   frameCount = Time.frameCount - lastFrameCount;

            // Display it
            fps = Mathf.RoundToInt(frameCount / timeSpan);

            if (PlayerPrefs.GetInt("dynamic_resolution", 0) == 1)
            {
                float framtime;

                XRStats.TryGetGPUTimeLastFrame(out framtime);

                //Debug.Log(framtime + " - " + (1f / SteamVR.instance.hmd_DisplayFrequency) * 1000f + " at " + fps);

                if (fps < SteamVR.instance.hmd_DisplayFrequency * 0.9f && framtime > (1f / SteamVR.instance.hmd_DisplayFrequency) * 1000f)
                {
                    SteamVR_Camera.sceneResolutionScale *= 0.95f;
                    //Debug.Log("Lowering render res! Min: " + MinRenderScale + " Max: " + MaxRenderScale);
                }
                else if (framtime < (1f / SteamVR.instance.hmd_DisplayFrequency) * 1000f)
                {
                    SteamVR_Camera.sceneResolutionScale *= 1.05f;
                    //Debug.Log("Raising render res! Min: " + MinRenderScale + " Max: " + MaxRenderScale);
                }

                SteamVR_Camera.sceneResolutionScale = Mathf.Clamp(SteamVR_Camera.sceneResolutionScale, MinRenderScale, MaxRenderScale);
            }
            else if (SteamVR_Camera.sceneResolutionScale != MaxRenderScale)
            {
                SteamVR_Camera.sceneResolutionScale = MaxRenderScale;
            }
        }
    }
    private void Update()
    {
        if (XRDevice.isPresent)
        {
            int droppedFrameCount;
            if (XRStats.TryGetDroppedFrameCount(out droppedFrameCount))
            {
                UnityUserReporting.CurrentClient.SampleMetric("XR.DroppedFrameCount", droppedFrameCount);
            }

            int framePresentCount;
            if (XRStats.TryGetFramePresentCount(out framePresentCount))
            {
                UnityUserReporting.CurrentClient.SampleMetric("XR.FramePresentCount", framePresentCount);
            }

            float gpuTimeLastFrame;
            if (XRStats.TryGetGPUTimeLastFrame(out gpuTimeLastFrame))
            {
                UnityUserReporting.CurrentClient.SampleMetric("XR.GPUTimeLastFrame", gpuTimeLastFrame);
            }
        }
    }