public void Reset() { _subSetPool.Return(_subSet); _subSet = null; }
private IEnumerator SampleFpsData(int posX, int posZ, SampleData[] dts, int dir) { foreach (var dt in sortedDts) { _dataPool.Return(dt); } sortedDts.Clear(); // 采样指定帧数去除多个最大最小值后取平均值 for (int c = 0; c < sampleCount; c++) { float fps = 1 / Time.deltaTime; SampleData dt = _dataPool.Get(); #if HAVE_FAST_GPU_PROFILER && ENABLE_PROFILER SampleDataSubset subset = dt.SubSet; _samples.Clear(); Profiler.GetFastGpuProfilerSamples(_samples); foreach (var sample in _samples) { subset.Add(sample.StatName, sample.ElapsedTime); } #endif dt.SetData(posX, posZ, fps, RuntimeStats.batches, RuntimeStats.setPassCalls, RuntimeStats.triangles, RuntimeStats.vertices, Camera.main.transform.forward, Camera.main.transform.up, Camera.main.transform.position, Camera.main.fieldOfView, Camera.main.nearClipPlane, Camera.main.farClipPlane, Camera.main.useOcclusionCulling ? 1 : 0, Camera.main.allowHDR ? 1 : 0, Camera.main.allowMSAA ? 1 : 0, RuntimeStats.shadowCasters, RuntimeStats.frameTime, RuntimeStats.renderTime); sortedDts.Add(dt); yield return(null); } sortedDts.Sort(CompareSampleData); float frame = 0f; int batches = 0, setPassCalls = 0, triangles = 0, vertices = 0; Vector3 forward = Vector3.zero, up = Vector3.zero, position = Vector3.zero; float fov = 0f, near = 0f, far = 0f; int useOc = 0, useHDR = 0, useMSAA = 0, shadowCaster = 0; float frameTime = 0f, renderTime = 0f; int dropFrames = 5; var dirDt = _dataPool.Get(); #if HAVE_FAST_GPU_PROFILER && ENABLE_PROFILER SampleDataSubset avrSubset = dirDt.SubSet; #endif for (int i = dropFrames; i < sampleCount - dropFrames; i++) { SampleData sd = sortedDts[i]; frame += sd.FrameRate; batches += sd.Batches; setPassCalls += sd.SetPassCalls; triangles += sd.Triangles; vertices += sd.Vertices; forward += new Vector3(sd.CamDirX, sd.CamDirY, sd.CamDirZ); up += new Vector3(sd.CamUpX, sd.CamUpY, sd.CamUpZ); position += new Vector3(sd.CamPosX, sd.CamPosY, sd.CamPosZ); fov += sd.CamFOV; near += sd.CamNear; far += sd.CamFar; useOc += sd.camOC; useHDR += sd.camHDR; useMSAA += sd.camMSAA; shadowCaster += sd.shadowCaster; frameTime += sd.frameTime; renderTime += sd.renderTime; #if HAVE_FAST_GPU_PROFILER && ENABLE_PROFILER avrSubset.Add(sd.SubSet); #endif } int count = sampleCount - 2 * dropFrames; frame /= count; batches /= count; setPassCalls /= count; triangles /= count; vertices /= count; forward /= count; up /= count; position /= count; fov /= count; near /= count; far /= count; useOc /= count; useHDR /= count; useMSAA /= count; shadowCaster /= count; frameTime /= count; renderTime /= count; #if HAVE_FAST_GPU_PROFILER && ENABLE_PROFILER avrSubset.Divide(count); #endif dirDt.SetData(posX, posZ, frame, batches, setPassCalls, triangles, vertices, forward, up, position, fov, near, far, useOc, useHDR, useMSAA, shadowCaster, frameTime, renderTime); dts[dir] = dirDt; }