华为P9在URP中,使用后处理帧数极低,暂时放弃

2021-04-14  本文已影响0人  rekcah1986

手里有一台华为P9测试机,在开启后处理时fps会降到10+,同期的红米note4和其他低端机都没有这个问题,猜测是麒麟的GPU性能太差了,在此机器上需要关闭后处理效果,写了个跑分代码来检测。

using System.Collections;
using UnityEngine;

/// <summary>
/// 华为P9开启后处理卡的要死,需要判断一下
/// 原理,持续一段时间做多次render,然后计算fps
/// </summary>
public class FixFPSChecker : MonoBehaviour
{
    private bool check = false;
    private int frames = 0;
    private int testRenderCount = 5;
    private float testDuration = 1;
    private void Update()
    {
        if (!check)
        {
            return;
        }
        for (int i = 0; i < testRenderCount; i++)
        {
            Camera.main.Render();
        }
        ++frames;
    }

    public delegate void CheckFPSCallback(float fPS);
    private CheckFPSCallback callback;
    public void CheckFPS(int renderCount, float duration, CheckFPSCallback callback)
    {
        testRenderCount = renderCount;
        testDuration = duration;
        this.callback = callback; 
        StartCoroutine(_Check());
    }

    private IEnumerator _Check()
    {
        yield return new WaitForSeconds(0.4f);
        frames = 0;
        check = true;
        yield return new WaitForSeconds(testDuration);
        check = false;
        var fps = frames / testDuration;
        Debug.Log("FPS测试结果:" + fps);
        this.callback?.Invoke(fps);
    }
}

调用方法:

        var checker = this.AddComponent<FixFPSChecker>();
        checker.CheckFPS(10, 1, (fps =>
        {
            if (fps < 10) {
                Debug.Log("渣机,fps: " + fps);
            }
            // ...
        }));

后续:打包ARM64就解决了……

上一篇下一篇

猜你喜欢

热点阅读