Пример #1
0
    public void DoubleConstantsInShaderConstantFields(Device device)
    {
        if (!device.Get().IsDoublePrecisionSupportAvailable())
        {
            Assert.Inconclusive();
        }

        using ReadWriteBuffer <float> buffer1  = device.Get().AllocateReadWriteBuffer <float>(8);
        using ReadWriteBuffer <double> buffer2 = device.Get().AllocateReadWriteBuffer <double>(8);

        device.Get().For(1, new DoubleConstantsInShaderConstantFieldsShader(buffer1, buffer2));

        float[] results1 = buffer1.ToArray();

        Assert.AreEqual(results1[0], DoubleConstantsInShaderConstantFieldsShader.DoubleToFloatConstant, 0.0001f);
        Assert.AreEqual(results1[1], DoubleConstantsInShaderConstantFieldsShader.DoubleToFloatField, 0.0001f);
        Assert.AreEqual(results1[2], DoubleConstants.PI, 0.0001f);
        Assert.AreEqual(results1[3], (float)(1 / 255.0), 0.0001f);
        Assert.AreEqual(results1[4], DoubleConstantsInShaderConstantFieldsShader.floatExponentLowercase, 0.0001f);
        Assert.AreEqual(results1[5], DoubleConstantsInShaderConstantFieldsShader.floatExponentUppercase, 0.0001f);
        Assert.AreEqual(results1[6], DoubleConstantsInShaderConstantFieldsShader.floatExponentLowercaseField, 0.0001f);
        Assert.AreEqual(results1[7], DoubleConstantsInShaderConstantFieldsShader.floatExponentUppercaseField, 0.0001f);

        double[] results2 = buffer2.ToArray();

        Assert.AreEqual(results2[0], DoubleConstantsInShaderConstantFieldsShader.DoubleConstant, 0.0001f);
        Assert.AreEqual(results2[1], DoubleConstantsInShaderConstantFieldsShader.DoubleField, 0.0001f);
        Assert.AreEqual(results2[2], DoubleConstants.PI2, 0.0001f);
        Assert.AreEqual(results2[3], 1 / 255.0, 0.0001f);
        Assert.AreEqual(results2[4], DoubleConstantsInShaderConstantFieldsShader.exponentLowercase, 0.0001f);
        Assert.AreEqual(results2[5], DoubleConstantsInShaderConstantFieldsShader.exponentUppercase, 0.0001f);
        Assert.AreEqual(results2[6], DoubleConstantsInShaderConstantFieldsShader.exponentLowercaseField, 0.0001f);
        Assert.AreEqual(results2[7], DoubleConstantsInShaderConstantFieldsShader.exponentUppercaseField, 0.0001f);
    }
Пример #2
0
    public void NanAndInfinite(Device device)
    {
        if (!device.Get().IsDoublePrecisionSupportAvailable())
        {
            Assert.Inconclusive();
        }

        using ReadWriteBuffer <float> buffer1  = device.Get().AllocateReadWriteBuffer <float>(16);
        using ReadWriteBuffer <double> buffer2 = device.Get().AllocateReadWriteBuffer <double>(16);

        device.Get().For(1, new NanAndInfiniteShader(buffer1, buffer2));

        float[]  results1 = buffer1.ToArray();
        double[] results2 = buffer2.ToArray();

        Assert.IsTrue(float.IsNaN(results1[0]));
        Assert.IsTrue(float.IsPositiveInfinity(results1[1]));
        Assert.IsTrue(float.IsNegativeInfinity(results1[2]));
        Assert.AreEqual(results1[3], 1);
        Assert.AreEqual(results1[4], 1);
        Assert.AreEqual(results1[5], 1);
        Assert.IsTrue(float.IsNaN(results1[6]));
        Assert.IsTrue(float.IsPositiveInfinity(results1[7]));
        Assert.IsTrue(float.IsNegativeInfinity(results1[8]));
        Assert.AreEqual(results1[9], 1);
        Assert.AreEqual(results1[10], 1);
        Assert.AreEqual(results1[11], 1);

        Assert.IsTrue(double.IsNaN(results2[0]));
        Assert.IsTrue(double.IsPositiveInfinity(results2[1]));
        Assert.IsTrue(double.IsNegativeInfinity(results2[2]));
        Assert.IsTrue(double.IsNaN(results2[3]));
        Assert.IsTrue(double.IsPositiveInfinity(results2[4]));
        Assert.IsTrue(double.IsNegativeInfinity(results2[5]));
    }
Пример #3
0
        public void Verify_GridIds(Device device)
        {
            using ReadWriteBuffer <int> buffer = device.Get().AllocateReadWriteBuffer <int>(256);

            device.Get().For(256, 1, 1, 32, 1, 1, new GridIdsShader(buffer));

            int[] data = buffer.ToArray();

            for (int i = 0; i < data.Length; i++)
            {
                Assert.AreEqual(data[i], i / 32);
            }
        }
Пример #4
0
    public void Verify_GroupShared_WithDynamicSize(Device device)
    {
        using ReadWriteBuffer <int> buffer = device.Get().AllocateReadWriteBuffer <int>(32);

        device.Get().For(64, 1, 1, 32, 1, 1, new DynamicGroupSharedPixelShader(buffer));

        int[] result = buffer.ToArray();

        for (int i = 0; i < 32; i++)
        {
            Assert.AreEqual(result[i], i);
        }
    }
Пример #5
0
    public void Verify_GroupShared_WithFixedSize(Device device)
    {
        using ReadWriteBuffer <int> buffer = device.Get().AllocateReadWriteBuffer <int>(128);

        device.Get().For(256, new FixedGroupSharedPixelShader(buffer));

        int[] result = buffer.ToArray();

        for (int i = 0; i < 128; i++)
        {
            Assert.AreEqual(result[i], i);
        }
    }
Пример #6
0
        public void Verify_GroupSize(Device device)
        {
            using ReadWriteBuffer <int> buffer = device.Get().AllocateReadWriteBuffer <int>(32);

            device.Get().For(1, 1, 1, 4, 15, 7, new GroupSizeShader(buffer));

            int[] data = buffer.ToArray();

            Assert.AreEqual(4, data[0]);
            Assert.AreEqual(15, data[1]);
            Assert.AreEqual(7, data[2]);
            Assert.AreEqual(4 * 15 * 7, data[3]);
            Assert.AreEqual(4 + 15, data[4]);
            Assert.AreEqual(4 + 15 + 7, data[5]);
        }
        public void StaticConstants(Device device)
        {
            using ReadWriteBuffer <float> buffer = device.Get().AllocateReadWriteBuffer <float>(8);

            device.Get().For(1, new StaticConstantsShader(buffer));

            float[] results = buffer.ToArray();

            Assert.AreEqual(3.14f, results[0], 0.00001f);
            Assert.AreEqual(results[1], results[2], 0.00001f);
            Assert.AreEqual(1, results[3], 0.00001f);
            Assert.AreEqual(2, results[4], 0.00001f);
            Assert.AreEqual(3, results[5], 0.00001f);
            Assert.AreEqual(4, results[6], 0.00001f);
            Assert.AreEqual(3.14f, results[7], 0.00001f);
        }
Пример #8
0
        public void Verify_DispatchSize(Device device)
        {
            using ReadWriteBuffer <int> buffer = device.Get().AllocateReadWriteBuffer <int>(6);

            device.Get().For(11, 22, 3, new DispatchSizeShader(buffer));

            ReflectionServices.GetShaderInfo <DispatchSizeShader>(out var info);

            int[] data = buffer.ToArray();

            Assert.AreEqual(data[0], 11 * 22 * 3);
            Assert.AreEqual(data[1], 11);
            Assert.AreEqual(data[2], 22);
            Assert.AreEqual(data[3], 3);
            Assert.AreEqual(data[4], 11 + 22);
            Assert.AreEqual(data[5], 11 + 22 + 3);
        }
Пример #9
0
    public void CustomHlslOperators(Device device)
    {
        float[] data = { 1, 6, 7, 3, 5, 2, 8, 4 };

        using ReadWriteBuffer <float> buffer = device.Get().AllocateReadWriteBuffer(data);

        device.Get().For(1, new ModAndComparisonOperatorsShader(buffer));

        float[] results = buffer.ToArray();

        Assert.AreEqual(results[0], 1);
        Assert.AreEqual(results[1], 0);
        Assert.AreEqual(results[2], 7);
        Assert.AreEqual(results[3], 3);
        Assert.AreEqual(results[4], 0);
        Assert.AreEqual(results[5], 1);
        Assert.AreEqual(results[6], 0);
        Assert.AreEqual(results[7], 0);
    }
Пример #10
0
    public void ConstantsInShaderConstantFields(Device device)
    {
        using ReadWriteBuffer <float> buffer = device.Get().AllocateReadWriteBuffer <float>(16);

        device.Get().For(1, new ConstantsInShaderConstantFieldsShader(buffer));

        float[] results = buffer.ToArray();

        Assert.AreEqual(results[0], ConstantsInShaderConstantFieldsShader.rot_angle, 0.0001f);
        Assert.AreEqual(results[1], ConstantsInShaderConstantFieldsShader.rot_angle2, 0.0001f);
        Assert.AreEqual(results[2], (float)Math.Cos(ConstantsInShaderConstantFieldsShader.rot_angle), 0.0001f);
        Assert.AreEqual(results[3], -(float)Math.Sin((float)(137.2 / 180.0 * Constants.PI2)), 0.0001f);
        Assert.AreEqual(results[4], (float)Math.Cos(Math.Sin(ConstantsInShaderConstantFieldsShader.sin)), 0.0001f);
        Assert.AreEqual(results[5], (float)(Math.Sin(ConstantsInShaderConstantFieldsShader.sin) + Math.Cos(Math.Sin(ConstantsInShaderConstantFieldsShader.sin))), 0.0001f);
        Assert.AreEqual(results[6], ConstantsInShaderConstantFieldsShader.exponentLowercase, 0.0001f);
        Assert.AreEqual(results[7], ConstantsInShaderConstantFieldsShader.exponentUppercase, 0.0001f);
        Assert.AreEqual(results[8], ConstantsInShaderConstantFieldsShader.exponentLowercaseField, 0.0001f);
        Assert.AreEqual(results[9], ConstantsInShaderConstantFieldsShader.exponentUppercaseField, 0.0001f);
    }
Пример #11
0
 private BigInteger(ReadWriteBuffer <bool> bits, bool isNegative) : this(bits.ToArray(), isNegative) => bits.Dispose();