Esempio n. 1
0
        // Alea Parallel.For!
        internal static Image Render1(int width, int height)
        {
            var resultLength = ColorComponents * width * height;
            var resultMemory = Gpu.Default.AllocateDevice <byte>(resultLength);
            var resultDevPtr = new deviceptr <byte>(resultMemory.Handle);

            Gpu.Default.For(0, width * height, i =>
            {
                ComputeRippleAtOffset(resultDevPtr, i, width, height);
            });

            return(BitmapUtility.FromByteArray(Gpu.CopyToHost(resultMemory), width, height));
        }
Esempio n. 2
0
        // Custom!
        internal static Image Render2(int width, int height)
        {
            var resultLength = ColorComponents * width * height;
            var resultMemory = Gpu.Default.AllocateDevice <byte>(resultLength);
            var resultDevPtr = new deviceptr <byte>(resultMemory.Handle);

            var lp = ComputeLaunchParameters(width, height);

            Gpu.Default.Launch(() =>
            {
                var i = blockDim.x * blockIdx.x + threadIdx.x;
                ComputeRippleAtOffset(resultDevPtr, i, width, height);
            }, lp);

            return(BitmapUtility.FromByteArray(Gpu.CopyToHost(resultMemory), width, height));
        }
Esempio n. 3
0
        // Byte Array!
        internal static Image Render2(int width, int height)
        {
            var result = new byte[ColorComponents * width * height];

            Parallel.For(0, height, y =>
            {
                for (var x = 0; x < width; ++x)
                {
                    ComputeRippleAtOffset(x, y, width, height, v =>
                    {
                        var offset = ColorComponents * (y * width + x);

                        result[offset + 0] = v;
                        result[offset + 1] = v;
                        result[offset + 2] = v;
                    });
                }
            });

            return(BitmapUtility.FromByteArray(result, width, height));
        }