public static void EndFrame() { IsWithinFrame = false; var context = D3DDevice.Device.ImmediateContext; context.End(_queryTimeStampFrameEnd); context.End(_queryTimeStampDisjoint); context.End(_queryPipelineStats); context.End(_queryOcclusion); QueryDataTimestampDisjoint disjointData; long timeStampframeBegin; long timeStampframeEnd; QueryDataPipelineStatistics pipelineStatsData; UInt64 occlusionCount; while (!context.GetData(_queryTimeStampFrameBegin, AsynchronousFlags.None, out timeStampframeBegin)) { ; } while (!context.GetData(_queryTimeStampFrameEnd, AsynchronousFlags.None, out timeStampframeEnd)) { ; } while (!context.GetData(_queryTimeStampDisjoint, AsynchronousFlags.None, out disjointData)) { ; } while (!context.GetData(_queryPipelineStats, AsynchronousFlags.None, out pipelineStatsData)) { ; } while (!context.GetData(_queryOcclusion, AsynchronousFlags.None, out occlusionCount)) { ; } if (LogData.Count == 0 || disjointData.Disjoint) { return; } DataEntry entry = new DataEntry() { ID = _queryTimeStampDisjoint.GetHashCode().ToString(), Name = "TotalFrameTime", Color = System.Drawing.Color.FromArgb(100, 255, 255, 255), Duration = (double)(timeStampframeEnd - timeStampframeBegin) / disjointData.Frequency, FrameTimeOffset = 0 }; FrameData frame = LogData[LogData.Count - 1]; frame.TimeBlocks.Add(entry); frame.RenderedPrimitives = pipelineStatsData.CPrimitiveCount; frame.PrimitivesSentToRasterizer = pipelineStatsData.CInvocationCount; frame.OcclusionCount = occlusionCount; LogData[LogData.Count - 1] = frame; float fps = (float)(1.0 / entry.Duration); if (fps < (float)FPSHistogram.Count) { FPSHistogram[(int)fps]++; } else { FPSOverflows++; } if (_logNextEndFrameEnabled) { Logger.Debug("fps: {0:0000.00}, mem: {1:0000}kb", fps, frame.PrivateMemory / 1024); _logNextEndFrameEnabled = false; } if (ChangedEvent != null) { ChangedEvent(null, EventArgs.Empty); } }