Esempio n. 1
0
        private void Update(EvaluationContext context)
        {
            var  deviceContext = _d3dDevice.ImmediateContext;
            bool enabled       = Enabled.GetValue(context);
            bool logToConsole  = LogToConsole.GetValue(context);

            if (enabled && _readyToMeasure)
            {
                _queryTimeStampDisjoint.Begin(deviceContext);
                _queryTimeStampFrameBegin.End(deviceContext);
            }

            Command.GetValue(context);

            if (!enabled)
            {
                return;
            }

            if (_readyToMeasure)
            {
                _queryTimeStampFrameEnd.End(deviceContext);
                _queryTimeStampDisjoint.End(deviceContext);
                _readyToMeasure = false;
            }
            else
            {
                // check if last measurement is ready
                bool dataFetched = true;
                dataFetched &= _queryTimeStampDisjoint.GetData(deviceContext, AsynchronousFlags.None, out QueryDataTimestampDisjoint disjointData);
                dataFetched &= _queryTimeStampFrameBegin.GetData(deviceContext, AsynchronousFlags.None, out long timeStampframeBegin);
                dataFetched &= _queryTimeStampFrameEnd.GetData(deviceContext, AsynchronousFlags.None, out long timeStampframeEnd);

                if (dataFetched && !disjointData.Disjoint)
                {
                    float durationInS = (float)(timeStampframeEnd - timeStampframeBegin) / disjointData.Frequency;
                    int   usDuration  = (int)(durationInS * 1000f * 1000f);
                    if (logToConsole)
                    {
                        Log.Debug($"Subtree took: {usDuration}us on GPU.");
                    }
                    LastMeasureInMicroSeconds = usDuration;
                    _readyToMeasure           = true;
                }

                LastMeasureInMs = MathUtils.Lerp(LastMeasureInMs, (float)(LastMeasureInMicroSeconds / 1000.0), 0.03f);
            }
        }