Пример #1
0
        public void ShaderWithCapturedDelegates()
        {
            Func <float, float> f = x => x * x;

            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Shader2 shader1 = new Shader2 {
                A = 1, B = buffer, F = f
            };

            int
                hash1 = ShaderHashCodeProvider.GetHashCode(shader1),
                hash2 = ShaderHashCodeProvider.GetHashCode(shader1);

            Assert.IsTrue(hash1 == hash2);

            f = x => x + 1;

            Shader2 shader2 = new Shader2 {
                A = 1, B = buffer, F = f
            };

            int hash3 = ShaderHashCodeProvider.GetHashCode(shader2);

            Assert.IsFalse(hash1 == hash3);
        }
        public void ShaderWithCapturedDelegates()
        {
            Func <float, float> f = x => x * x;

            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Action <ThreadIds> action = id => buffer[0] = f(2);

            int
                hash1 = ShaderHashCodeProvider.GetHashCode(action),
                hash2 = ShaderHashCodeProvider.GetHashCode(action);

            Assert.IsTrue(hash1 == hash2);

            f = x => x + 1;

            int hash3 = ShaderHashCodeProvider.GetHashCode(action);

            Assert.IsFalse(hash1 == hash3);
        }
        public void ShaderWithNoCapturedDelegates()
        {
            float value = 10;

            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Action <ThreadIds> action1 = id => buffer[0] = value;

            int
                hash1 = ShaderHashCodeProvider.GetHashCode(action1),
                hash2 = ShaderHashCodeProvider.GetHashCode(action1);

            Assert.IsTrue(hash1 == hash2);

            Action <ThreadIds> action2 = id => buffer[0] = value;

            int hash3 = ShaderHashCodeProvider.GetHashCode(action2);

            Assert.IsFalse(hash1 == hash3);
        }
Пример #4
0
        public void ShaderWithNoCapturedDelegates()
        {
            float value = 10;

            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Shader1 shader1 = new() { A = value, B = buffer };

            int
                hash1 = ShaderHashCodeProvider.GetHashCode(shader1),
                hash2 = ShaderHashCodeProvider.GetHashCode(shader1);

            Assert.IsTrue(hash1 == hash2);

            Shader1 shader2 = new() { A = value, B = buffer };

            int hash3 = ShaderHashCodeProvider.GetHashCode(shader2);

            Assert.IsTrue(hash1 == hash3);
        }

        public struct Shader2 : IComputeShader