コード例 #1
0
        /// <summary>
        /// Read out some values from a DeviceBuffer and print them to the console. Just for debugging.
        /// </summary>
        /// <param name="buf">GPU DeviceBuffer to read</param>
        /// <param name="message">Caption for the printout</param>
        /// <param name="printCount">Max values to print</param>
        private void DebugPrintOutputFloatBuffer(DeviceBuffer buf, string message, int printCount)
        {
            DeviceBuffer destinationReadback = VeldridGraphBuffers.GetReadback(_gd !, buf);
            MappedResourceView <float> destinationReadView = _gd !.Map <float>(destinationReadback, MapMode.Read);

            float[] outputArray = new float[destinationReadView.Count];
            for (int index = 0; index < destinationReadView.Count; index++)
            {
                if (index >= destinationReadView.Count)
                {
                    break;
                }

                outputArray[index] = destinationReadView[index];
            }
            _gd.Unmap(destinationReadback);
            PrintFloatBufferArray(outputArray, message, printCount);
            VeldridGraphBuffers.VRAMDispose(destinationReadback);
        }
コード例 #2
0
        /// <summary>
        /// Must have read lock to call
        /// Find the node with the highest x/y/z dimension. Ignores w.
        /// </summary>
        /// <param name="buf">Device buffer containing values (can be speeds or positions)</param>
        /// <param name="nodeCount">Number of nodes to iterate over</param>
        /// <param name="highIndex">set to the index of the highest node</param>
        /// <returns></returns>
        private float FindHighXYZ(DeviceBuffer buf, int nodeCount, out int highIndex)
        {
            if (GlobalConfig.Settings.Logs.BulkLogging)
            {
                Logging.RecordLogEvent($"FindHighXYZ  {this.EngineID}", Logging.LogFilterType.BulkDebugLogFile);
            }
            DeviceBuffer destinationReadback = VeldridGraphBuffers.GetReadback(_gd !, buf);
            MappedResourceView <float> destinationReadView = _gd !.Map <float>(destinationReadback, MapMode.Read);
            float highest = 0f;

            highIndex = 0;
            for (int testNodeIndex = 0; testNodeIndex < nodeCount; testNodeIndex += 1)
            {
                int bufIndex = testNodeIndex * 4;
                Debug.Assert(bufIndex + 3 < destinationReadView.Count);

                if (Math.Abs(destinationReadView[bufIndex]) > highest)
                {
                    highest   = Math.Abs(destinationReadView[bufIndex]);
                    highIndex = bufIndex;
                }
                if (Math.Abs(destinationReadView[bufIndex + 1]) > highest)
                {
                    highest   = Math.Abs(destinationReadView[bufIndex + 1]);
                    highIndex = bufIndex + 1;
                }
                if (Math.Abs(destinationReadView[bufIndex + 2]) > highest)
                {
                    highest   = Math.Abs(destinationReadView[bufIndex + 2]);
                    highIndex = bufIndex + 2;
                }
            }
            highIndex = (int)Math.Floor(highIndex / 4f);
            _gd.Unmap(destinationReadback);
            VeldridGraphBuffers.VRAMDispose(destinationReadback);
            return(highest);
        }
コード例 #3
0
        private void DebugPrintOutputIntBuffer(DeviceBuffer buf, string message, int printCount)
        {
            if (buf is null)
            {
                Console.WriteLine("Skipping debug output of null buffer:" + message);
                return;
            }
            DeviceBuffer             destinationReadback = VeldridGraphBuffers.GetReadback(_gd !, buf);
            MappedResourceView <int> destinationReadView = _gd !.Map <int>(destinationReadback, MapMode.Read);

            int[] outputArray = new int[destinationReadView.Count];
            for (int index = 0; index < destinationReadView.Count; index++)
            {
                if (index >= destinationReadView.Count)
                {
                    break;
                }

                outputArray[index] = destinationReadView[index];
            }
            _gd.Unmap(destinationReadback);
            PrintIntBufferArray(outputArray, message, printCount);
            VeldridGraphBuffers.VRAMDispose(destinationReadback);
        }