public void GetData(RenderContext context) { if (this.hasrun == false) { return; } DeviceContext ctx = context.Context; for (int i = 0; i < WAIT_MAX; i++) { if (context.Context.IsDataAvailable(this.tstart) && context.Context.IsDataAvailable(this.tend) && context.Context.IsDataAvailable(this.tsdis)) { Int64 startTime = ctx.GetData <Int64>(this.tstart); Int64 endTime = ctx.GetData <Int64>(this.tend); QueryDataTimestampDisjoint data = ctx.GetData <QueryDataTimestampDisjoint>(this.tsdis); float time = 0.0f; if (data.Disjoint == false) { Int64 delta = endTime - startTime; float frequency = (float)data.Frequency; time = ((float)delta / frequency) * 1000.0f; this.Elapsed = time; } return; } } }
static void GatherFrame(MyFrameProfiling frame) { QueryDataTimestampDisjoint disjoint = MyImmediateRC.RC.GetData <QueryDataTimestampDisjoint>(frame.m_disjoint.m_query, AsynchronousFlags.DoNotFlush); #if UNSHARPER if (!disjoint.Disjoint.value) #else if (!disjoint.Disjoint) #endif { var freq = disjoint.Frequency; double invFreq = 1.0 / (double)freq; m_timestampStack.Clear(); int stackDepth = 0; while (frame.m_issued.Count > 0) { var q = frame.m_issued.Dequeue(); ulong timestamp; MyImmediateRC.RC.GetData <ulong>(q.m_query, AsynchronousFlags.DoNotFlush, out timestamp); if (q.m_info == MyIssuedQueryEnum.BlockStart) { stackDepth++; MyRender11.GetRenderProfiler().GPU_StartProfilingBlock(q.m_tag); MySimpleProfiler.BeginGPUBlock(q.m_tag); m_timestampStack.Push(timestamp); } else if (q.m_info == MyIssuedQueryEnum.BlockEnd) { stackDepth--; var start = m_timestampStack.Pop(); var time = (timestamp - start) * invFreq; // tick is 100 nanoseconds = 10^-7 second MyRender11.GetRenderProfiler().GPU_EndProfilingBlock(0, MyTimeSpan.FromSeconds(time)); MySimpleProfiler.EndGPUBlock(MyTimeSpan.FromSeconds(time)); } Debug.Assert(stackDepth >= 0); MyQueryFactory.RelaseTimestampQuery(q.m_query); } Debug.Assert(stackDepth == 0); } frame.Clear(); }