Пример #1
0
        public static void EndFrame()
        {
            if (!Enabled)
            {
                return;
            }

            IsWithinFrame = false;

            var context        = D3DDevice.Device.ImmediateContext;
            var measureElement = _measureElements[_currentQueryFrame];

            measureElement.QueryTimeStampFrameEnd.End(context);
            measureElement.QueryTimeStampDisjoint.End(context);
            measureElement.QueryPipelineStats.End(context);
            measureElement.QueryOcclusion.End(context);

            int oldestQueryFrame = (_currentQueryFrame + 1) % _maxQueryFrames;

            ++_currentQueryFrame;
            if (_currentQueryFrame == _maxQueryFrames)
            {
                _allQueriesValid = true;
            }

            _currentQueryFrame %= _maxQueryFrames;

            if (_allQueriesValid)
            {
                var measureElementToFetch = _measureElements[oldestQueryFrame];
                QueryDataTimestampDisjoint disjointData;
                long timeStampframeBegin;
                long timeStampframeEnd;
                QueryDataPipelineStatistics pipelineStatsData;
                UInt64 occlusionCount;
                bool   dataFetched = true;
                dataFetched &= measureElementToFetch.QueryTimeStampDisjoint.GetData(context, AsynchronousFlags.None, out disjointData);
                dataFetched &= measureElementToFetch.QueryTimeStampFrameBegin.GetData(context, AsynchronousFlags.None, out timeStampframeBegin);
                dataFetched &= measureElementToFetch.QueryTimeStampFrameEnd.GetData(context, AsynchronousFlags.None, out timeStampframeEnd);
                dataFetched &= measureElementToFetch.QueryPipelineStats.GetData(context, AsynchronousFlags.None, out pipelineStatsData);
                dataFetched &= measureElementToFetch.QueryOcclusion.GetData(context, AsynchronousFlags.None, out occlusionCount);

                if (dataFetched && !disjointData.Disjoint)
                {
                    DataEntry entry = new DataEntry()
                    {
                        ID              = _lock.GetHashCode().ToString(),
                        Name            = "TotalFrameTime",
                        Color           = System.Drawing.Color.FromArgb(100, 255, 255, 255),
                        Duration        = (double)(timeStampframeEnd - timeStampframeBegin) / disjointData.Frequency,
                        FrameTimeOffset = 0
                    };

                    float fps        = (float)(1.0 / entry.Duration);
                    Int64 privateMem = 0;
                    lock (_lock)
                    {
                        FrameData frame;
                        if (_logData.TryGetValue(measureElementToFetch.FrameID, out frame))
                        {
                            frame.TimeBlocks.Add(entry);
                            frame.RenderedPrimitives         = pipelineStatsData.CPrimitiveCount;
                            frame.PrimitivesSentToRasterizer = pipelineStatsData.CInvocationCount;
                            frame.OcclusionCount             = occlusionCount;
                            privateMem = frame.PrivateMemory;
                            _logData[measureElementToFetch.FrameID] = frame;
                        }
                    }

                    if (fps < (float)FPSHistogram.Count)
                    {
                        FPSHistogram[(int)fps]++;
                    }
                    else
                    {
                        FPSOverflows++;
                    }

                    if (_logNextEndFrameEnabled)
                    {
                        Logger.Debug("fps: {0:0000.00}, mem: {1:0000}kb", fps, privateMem / 1024);
                        _logNextEndFrameEnabled = false;
                    }
                }
            }

            FrameID++;
            if (ChangedEvent != null)
            {
                ChangedEvent(null, new EventArgs());
            }
        }