using System; using System.Linq; using ComputeSharp; using ComputeSharp.Sample; float[] array = Enumerable.Range(1, 100).Select(static i => (float)i).ToArray(); // Create the graphics buffer using ReadWriteBuffer gpuBuffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(array); // Run the shader GraphicsDevice.GetDefault().For(100, new MultiplyByTwo(gpuBuffer)); // Print the initial matrix Formatting.PrintMatrix(array, 10, 10, "BEFORE"); // Get the data back gpuBuffer.CopyTo(array); // Print the updated matrix Formatting.PrintMatrix(array, 10, 10, "AFTER"); /// /// The sample kernel that multiples all items by two. /// [AutoConstructor] internal readonly partial struct MultiplyByTwo : IComputeShader { public readonly ReadWriteBuffer buffer; /// public void Execute() { buffer[ThreadIds.X] *= 2; } }