public HeatmapImageGenerationShader(
     ReadWriteBuffer <int> density,
     ReadWriteBuffer <int> image,
     int width,
     float maxDensity
     )
 {
     this.density    = density;
     this.image      = image;
     this.width      = width;
     this.maxDensity = maxDensity;
 }
示例#2
0
        public void Setup()
        {
            X = CreateRandomArray(C * N * M);
            W = CreateRandomArray(M * P);
            B = CreateRandomArray(P);
            Y = CreateRandomArray(C * N * P);

            BufferX = Gpu.Default.AllocateReadOnlyBuffer(X);
            BufferW = Gpu.Default.AllocateReadOnlyBuffer(W);
            BufferB = Gpu.Default.AllocateReadOnlyBuffer(B);
            BufferY = Gpu.Default.AllocateReadWriteBuffer(Y);
        }
示例#3
0
        public void StaticScalarFieldRepeatedAssignToBuffer()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Action <ThreadIds> action = id => buffer[0] = StaticFieldsContainer.StaticFloat + StaticFieldsContainer.StaticFloat;

            Gpu.Default.For(1, action);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - StaticFieldsContainer.StaticFloat * 2) < 0.0001f);
        }
示例#4
0
        public void StaticReadonlyScalarPropertyAssignToBuffer()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            Action <ThreadIds> action = id => buffer[0] = StaticPropertiesContainer.ReadonlyFloat;

            Gpu.Default.For(1, action);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - StaticPropertiesContainer.ReadonlyFloat) < 0.0001f);
        }
    public unsafe void LoadScalarVectorAndMatrixTypes()
    {
        using ReadWriteBuffer <float> buffer = GraphicsDevice.Default.AllocateReadWriteBuffer <float>(16);

        DebugDispatchDataLoader          dataLoader = DebugDispatchDataLoader.Create();
        ScalarVectorAndMatrixTypesShader shader     = new(
            buffer,
            f2x3 : new(55, 44, 888, 111, 222, 333),
            a : 22,
            i1x3 : new(1, 2, 3),
            d2 : new(3.14, 6.28),
            c : 42,
            i1x2 : new(111, 222),
            i2x2 : new(11, 22, 33, 44),
            d : 9999);

        ((IShader)shader).LoadDispatchData(ref dataLoader, GraphicsDevice.Default, 111, 222, 333);

        Assert.AreEqual(31, dataLoader.Values.Length);
        Assert.AreEqual(1, dataLoader.Resources.Length);

        Assert.AreEqual(111, (int)dataLoader.Values[0]);
        Assert.AreEqual(222, (int)dataLoader.Values[1]);
        Assert.AreEqual(333, (int)dataLoader.Values[2]);

        Assert.AreEqual(buffer.D3D12GpuDescriptorHandle.ptr, dataLoader.Resources[0]);

        fixed(void *p0 = &dataLoader.Values[0])
        {
            byte *p1 = (byte *)p0;

            Assert.AreEqual(55, *(float *)&p1[16]);
            Assert.AreEqual(44, *(float *)&p1[20]);
            Assert.AreEqual(888, *(float *)&p1[24]);
            Assert.AreEqual(111, *(float *)&p1[32]);
            Assert.AreEqual(222, *(float *)&p1[36]);
            Assert.AreEqual(333, *(float *)&p1[40]);
            Assert.AreEqual(22, *(int *)&p1[44]);
            Assert.AreEqual(1, *(int *)&p1[48]);
            Assert.AreEqual(2, *(int *)&p1[52]);
            Assert.AreEqual(3, *(int *)&p1[56]);
            Assert.AreEqual(3.14, *(double *)&p1[64]);
            Assert.AreEqual(6.28, *(double *)&p1[72]);
            Assert.AreEqual(42, *(int *)&p1[80]);
            Assert.AreEqual(111, *(int *)&p1[84]);
            Assert.AreEqual(222, *(int *)&p1[88]);
            Assert.AreEqual(11, *(int *)&p1[96]);
            Assert.AreEqual(22, *(int *)&p1[100]);
            Assert.AreEqual(33, *(int *)&p1[112]);
            Assert.AreEqual(44, *(int *)&p1[116]);
            Assert.AreEqual(9999, *(int *)&p1[120]);
        }
    }
示例#6
0
        public void StaticLocalScalarFieldAssignToBuffer()
        {
            using ReadWriteBuffer <int> buffer = Gpu.Default.AllocateReadWriteBuffer <int>(1);

            Action <ThreadIds> action = id => buffer[0] = SomeNumber;

            Gpu.Default.For(1, action);

            int[] result = buffer.GetData();

            Assert.IsTrue(result[0] == SomeNumber);
        }
        public void StatelessLocalFunction()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            float f(float x) => x * x;

            Gpu.Default.For(1, id => buffer[0] = f(3));

            float[] result = buffer.GetData();

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

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

            Gpu.Default.For(1, id => buffer[0] = square(3));

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
        }
示例#9
0
        public void SequentialCompilation()
        {
            Float2 f2 = new Float2(1, 2);

            using ReadWriteBuffer <Float2> buffer = Gpu.Default.AllocateReadWriteBuffer <Float2>(2);

            Action <ThreadIds> action1 = id => buffer[0] = f2.YX;

            Action <ThreadIds> action2 = id => buffer[1] = f2.YX;

            Gpu.Default.For(1, action1);
            Gpu.Default.For(1, action2);
        }
        public void FloatToFloat4Func()
        {
            using ReadWriteBuffer <Float4> buffer = Gpu.Default.AllocateReadWriteBuffer <Float4>(1);

            Gpu.Default.For(1, id => buffer[0] = StaticMethodsContainer.Range(3));

            Float4[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0].X - 3) < 0.0001f);
            Assert.IsTrue(MathF.Abs(result[0].Y - 4) < 0.0001f);
            Assert.IsTrue(MathF.Abs(result[0].Z - 5) < 0.0001f);
            Assert.IsTrue(MathF.Abs(result[0].W - 6) < 0.0001f);
        }
示例#11
0
        public void ReadOnlyBufferGetSetDataFromReadWriteBuffer()
        {
            float[] array = Enumerable.Range(0, 4096).Select(i => (float)i).ToArray();

            using ReadWriteBuffer <float> sourceBuffer     = Gpu.Default.AllocateReadWriteBuffer(array);
            using ConstantBuffer <float> destinationBuffer = Gpu.Default.AllocateConstantBuffer(sourceBuffer);

            float[] sourceResult      = sourceBuffer.GetData();
            float[] destinationResult = destinationBuffer.GetData();

            Assert.IsTrue(array.AsSpan().ContentEquals(sourceResult));
            Assert.IsTrue(array.AsSpan().ContentEquals(destinationResult));
        }
示例#12
0
        public void ReadWriteBufferSetRangeData()
        {
            float[] array = Enumerable.Range(0, 256).Select(i => (float)i).ToArray();

            using ReadWriteBuffer <float> sourceBuffer = Gpu.Default.AllocateReadWriteBuffer(array);

            array.AsSpan(56, 100).Clear();
            sourceBuffer.SetData(new float[100], 56, 100);

            float[] sourceResult = sourceBuffer.GetData();

            Assert.IsTrue(array.AsSpan().ContentEquals(sourceResult));
        }
示例#13
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);
        }
    }
示例#14
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);
        }
    }
        public void WriteToReadWriteBufferManualDispatch3D()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1000);

            Action <ThreadIds> action = id => buffer[id.X + id.Y * 10 + id.Z * 100] = id.X + id.Y * 10 + id.Z * 100;

            Gpu.Default.For(10, 10, 10, 4, 4, 4, action);

            float[] array    = buffer.GetData();
            float[] expected = Enumerable.Range(0, 1000).Select(i => (float)i).ToArray();

            Assert.IsTrue(array.AsSpan().ContentEquals(expected));
        }
示例#16
0
 public ExecuteShader(
     ReadOnlyBuffer <float> directionsX,
     ReadOnlyBuffer <float> directionsY,
     ReadWriteBuffer <float> positionsX,
     ReadWriteBuffer <float> positionsY,
     ReadOnlyBuffer <float> speeds)
 {
     this.directionsX = directionsX;
     this.directionsY = directionsY;
     this.positionsX  = positionsX;
     this.positionsY  = positionsY;
     this.speeds      = speeds;
 }
示例#17
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);
            }
        }
示例#18
0
        public unsafe void CapturedResource()
        {
            ulong *p0 = stackalloc ulong[128];
            byte * p1 = stackalloc byte[256];

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

            int size = DispatchDataLoader.LoadDispatchData(Gpu.Default, new CapturedResourceShader(buffer), ref *p0, ref *p1);

            Assert.AreEqual(12, size);

            Assert.AreEqual(p0[0], buffer.D3D12GpuDescriptorHandle.ptr);
        }
        public void LocalScalarAssignToBufferWithinLocalMethod()
        {
            float value = 10;

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

            void Foo(ThreadIds id) => buffer[0] = value;

            Gpu.Default.For(1, Foo);

            float[] result = buffer.GetData();

            Assert.IsTrue((int)result[0] == (int)value);
        }
示例#20
0
        public void StaticScalarFieldAssignToBuffer()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            var shader = new StaticScalarFieldAssignToBuffer_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - StaticFieldsContainer.StaticFloat) < 0.0001f);
        }
示例#21
0
        public void IntrinsicWithInlineOutParamater()
        {
            float angle = 80;

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

            Action <ThreadIds> action = id =>
            {
                buffer[0] = Hlsl.Sin(angle);
                buffer[1] = Hlsl.Cos(angle);
                Hlsl.SinCos(angle, out float sine, out float cosine);
                buffer[2] = sine;
                buffer[3] = cosine;
            };
示例#22
0
        public void ExternalStaticFunctionWithAttributesDirect()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            var shader = new ExternalStaticFunctionWithAttributesDirect_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 16) < 0.0001f);
        }
示例#23
0
        public void Int2Properties()
        {
            using ReadWriteBuffer <Int2> buffer = Gpu.Default.AllocateReadWriteBuffer <Int2>(1);

            var shader = new Int2Properties_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            Int2[] result = buffer.GetData();

            Assert.IsTrue(result[0].X == 1);
        }
示例#24
0
        public void IntToOutIntFunc()
        {
            using ReadWriteBuffer <int> buffer = Gpu.Default.AllocateReadWriteBuffer <int>(1);

            var shader = new IntToOutIntFunc_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            int[] result = buffer.GetData();

            Assert.IsTrue(result[0] == 7);
        }
示例#25
0
        public void InternalFloatToFloatFunc()
        {
            using ReadWriteBuffer <float> buffer = Gpu.Default.AllocateReadWriteBuffer <float>(1);

            var shader = new InternalFloatToFloatFunc_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
        }
示例#26
0
        public BigInteger(long value)
        {
            if (IsNegative = value < 0)
            {
                value = ~value + 1;
            }
            List <bool> bits = new();

            do
            {
                bits.Add((value & 1) == 1);
            } while ((value >>= 1) > 0);
            Bits = Gpu.Default.AllocateReadWriteBuffer(bits.ToArray());
        }
        public void LocalScalarAssignToBuffer()
        {
            float value = 10;

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

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

            Gpu.Default.For(1, action);

            float[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0] - value) < 0.0001f);
        }
示例#28
0
        public void StaticLocalScalarFieldAssignToBuffer()
        {
            using ReadWriteBuffer <int> buffer = Gpu.Default.AllocateReadWriteBuffer <int>(1);

            var shader = new StaticLocalScalarFieldAssignToBuffer_Shader {
                B = buffer
            };

            Gpu.Default.For(1, shader);

            int[] result = buffer.GetData();

            Assert.IsTrue(result[0] == SomeNumber);
        }
示例#29
0
        public void LocalBoolAssignToBool2Buffer()
        {
            Bool2 b2 = Bool2.TrueY;

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

            Action <ThreadIds> action = id => buffer[0] = b2;

            Gpu.Default.For(1, action);

            Bool2[] result = buffer.GetData();

            Assert.IsTrue(result[0].X == b2.X);
            Assert.IsTrue(result[0].Y == b2.Y);
        }
示例#30
0
        public void LocalFloatAssignToFloat2Buffer()
        {
            Float2 f2 = new Float2(1, 2);

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

            Action <ThreadIds> action = id => buffer[0] = f2.YX;

            Gpu.Default.For(1, action);

            Float2[] result = buffer.GetData();

            Assert.IsTrue(MathF.Abs(result[0].X - f2.Y) < 0.0001f);
            Assert.IsTrue(MathF.Abs(result[0].Y - f2.X) < 0.0001f);
        }