Beispiel #1
0
        public void FloatToFloatFunc()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            var shader = new FloatToFloatFunc_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
        }
Beispiel #2
0
        public void InternalFloatToFloatFunc()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Func <float, float> square = StaticMethodsContainer.InternalSquare;

            var shader = new FloatToFloatFunc_Shader
            {
                F = square,
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
        }
Beispiel #3
0
        public void InlineStatelessDelegate()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Func <float, float> f = x => x * x;

            var shader = new FloatToFloatFunc_Shader
            {
                F = f,
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
        }
Beispiel #4
0
        public void ChangingFuncsFromSameMethod()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            var shader = new FloatToFloatFunc_Shader
            {
                F = StaticMethodsContainer.Square,
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);

            shader.F = StaticMethodsContainer.Negate;

            Gpu.Default.For(1, shader);

            result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] + 3) < 0.0001f);
        }