using System.Diagnostics; using System.Linq; using System.Runtime.Versioning; using ComputeSharp; [assembly: SupportedOSPlatform("windows6.2")] float[] array = [.. Enumerable.Range(1, 100)]; // Create the graphics buffer using ReadWriteBuffer gpuBuffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(array); // Run the shader GraphicsDevice.GetDefault().For(100, new MultiplyByTwo(gpuBuffer)); // Get the data back float[] result = gpuBuffer.ToArray(); // Validate results for (int i = 0; i < array.Length; i++) { Trace.Assert(result[i] == array[i] * 2); } /// /// A sample kernel that is precompiled. /// [ThreadGroupSize(DefaultThreadGroupSizes.X)] [GeneratedComputeShaderDescriptor] internal readonly partial struct MultiplyByTwo(ReadWriteBuffer buffer) : IComputeShader { /// public void Execute() { buffer[ThreadIds.X] *= 2; } }